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.

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