C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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