C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

254 rader
4.6 KiB

  1. var app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. const Http = require("../../utils/HttpBasics");
  5. const config = require("../../config/config.js");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. userName: "",
  13. userPhone: "",
  14. // region:"",
  15. detail: "",
  16. switch1Checked: false,
  17. region: ['北京市', '北京市', '东城区'],
  18. id: "",
  19. url: "",
  20. typeLsit: {}
  21. },
  22. /**
  23. * 获取全局样式
  24. */
  25. getType() {
  26. Http.get({
  27. url: config.api.setType,
  28. data: {
  29. mouldType: app.globalData.mouldType
  30. }
  31. }).then(res => {
  32. const {
  33. code,
  34. data
  35. } = res
  36. if (code == 200) {
  37. app.globalData.typeLsit = data
  38. this.setData({
  39. typeLsit: data,
  40. })
  41. }
  42. })
  43. },
  44. go(e) {
  45. let url = e.currentTarget.dataset.url
  46. wx.navigateTo({
  47. url: url,
  48. })
  49. },
  50. setUserName(e) {
  51. this.setData({
  52. userName: e.detail.value
  53. })
  54. },
  55. setUserPhone(e) {
  56. this.setData({
  57. userPhone: e.detail.value
  58. })
  59. },
  60. setRegion(e) {
  61. this.setData({
  62. region: e.detail.value
  63. })
  64. },
  65. setDetail(e) {
  66. this.setData({
  67. detail: e.detail.value
  68. })
  69. },
  70. switch1Change(e) {
  71. this.setData({
  72. switch1Checked: e.detail.value
  73. })
  74. },
  75. dleSite() {
  76. Http.get({
  77. url: config.api.siteDel,
  78. data: {
  79. id: this.data.id
  80. }
  81. }).then(res => {
  82. wx.showToast({
  83. title: '删除成功',
  84. icon: 'none',
  85. duration: 2000,
  86. })
  87. wx.navigateBack({
  88. delta: 1
  89. })
  90. }).catch(err => {
  91. wx.showToast({
  92. title: err.message ? err.message : err.data,
  93. icon: 'none',
  94. duration: 2000,
  95. })
  96. })
  97. },
  98. addSite() {
  99. let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  100. if (this.data.userName == "") {
  101. wx.showToast({
  102. title: '请输入收货人',
  103. icon: 'none',
  104. duration: 2000,
  105. })
  106. return
  107. }
  108. if (!myreg.test(this.data.userPhone)) {
  109. // this.redata.Phone = '';
  110. wx.showToast({
  111. title: '请输入正确手机号',
  112. icon: 'none',
  113. duration: 2000,
  114. })
  115. return
  116. }
  117. if (this.data.detail == "") {
  118. wx.showToast({
  119. title: '请输入详细地址',
  120. icon: 'none',
  121. duration: 2000,
  122. })
  123. return
  124. }
  125. let data = {
  126. consignee: this.data.userName,
  127. mobile: this.data.userPhone,
  128. address: this.data.detail,
  129. region: JSON.stringify(this.data.region),
  130. isDefault: this.data.switch1Checked ? 1 : 0,
  131. }
  132. if (this.data.id && this.data.id != "") {
  133. data.id = this.data.id
  134. }
  135. Http.post({
  136. url: config.api.collectSite,
  137. data: data,
  138. }).then(res => {
  139. wx.showToast({
  140. title: '保存成功!',
  141. icon: 'none',
  142. duration: 2000,
  143. })
  144. wx.navigateBack({
  145. delta: 1
  146. })
  147. }).catch(err => {
  148. wx.showToast({
  149. title: err.message ? err.message : err.data,
  150. icon: 'none',
  151. duration: 2000,
  152. })
  153. })
  154. },
  155. bindRegionChange(e) {
  156. this.setData({
  157. region: e.detail.value,
  158. obj: {},
  159. })
  160. },
  161. /**
  162. * 生命周期函数--监听页面加载
  163. */
  164. onLoad: function (options) {
  165. this.getType()
  166. if (options.id) {
  167. this.setData({
  168. id: options.id
  169. })
  170. this.siteCheck(options.id)
  171. }
  172. },
  173. siteCheck(id) {
  174. Http.get({
  175. url: config.api.siteCheck,
  176. data: {
  177. id
  178. }
  179. }).then(res => {
  180. let obj = res.data
  181. this.setData({
  182. userName: obj.consignee,
  183. userPhone: obj.mobile,
  184. detail: obj.address,
  185. region: JSON.parse(obj.region),
  186. switch1Checked: obj.isDefault == 0 ? false : true,
  187. })
  188. }).catch(err => {
  189. wx.showToast({
  190. title: err.message ? err.message : err.data,
  191. icon: 'none',
  192. duration: 2000,
  193. })
  194. })
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom: function () {
  225. },
  226. /**
  227. * 用户点击右上角分享
  228. */
  229. onShareAppMessage: function () {
  230. }
  231. })