edit-address.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var businessT = require('../../../../tool/business-tool.js')
  2. var url = require('../../../../constant/url.js')
  3. import Net from '../../../../tool/net.js'
  4. var net = new Net()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. type: 'add',
  11. data: { u_name: '', phone: '', area: '', address:'' },
  12. area: ''
  13. },
  14. formSubmit: businessT.action(function (sender) {
  15. businessT.debugLog(sender.detail)
  16. var data = sender.detail.value
  17. if (data.u_name == '') {
  18. wx.showToast({
  19. title: '请输入收货人姓名',
  20. icon: 'none'
  21. })
  22. return
  23. } else if (data.phone == '') {
  24. wx.showToast({
  25. title: '请输入正确的手机号',
  26. icon: 'none'
  27. })
  28. return
  29. } else if (data.area == '') {
  30. wx.showToast({
  31. title: '请选择所在地区',
  32. icon: 'none'
  33. })
  34. return
  35. } else if (data.address == '') {
  36. wx.showToast({
  37. title: '请填写详细地址',
  38. icon: 'none'
  39. })
  40. return
  41. } else {
  42. this.uploadData(data)
  43. }
  44. }),
  45. uploadData: function (data) {
  46. wx.showLoading({
  47. title: this.data.type == 'add' ? '正在添加' : '正在修改',
  48. mask: true
  49. })
  50. net.connectNeedLogin({
  51. url: url.app_host + url.addAndUpdateMailingAddress,
  52. data: data,
  53. success: (err, res) => {
  54. var pages = getCurrentPages()
  55. pages[pages.length - 2].reloadData(data)
  56. wx.hideLoading()
  57. wx.navigateBack({
  58. })
  59. },
  60. fail: (err, res) => {
  61. wx.hideLoading()
  62. businessT.showFailTips(err, this.data.type == 'add' ? '添加失败' : '修改失败')
  63. }
  64. })
  65. },
  66. pickerChange: businessT.action(function (sender) {
  67. businessT.debugLog(sender)
  68. var a = sender.detail.value
  69. var area = ''
  70. for (var i in a) {
  71. area = area + a[i]
  72. }
  73. this.data.area = area
  74. this.setData({
  75. area: this.data.area
  76. })
  77. }),
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) {
  82. this.data.type = options.type
  83. if (this.data.type == 'edit') {
  84. wx.setNavigationBarTitle({
  85. title: '更改信息'
  86. })
  87. var pages = getCurrentPages()
  88. this.data.data = pages[pages.length - 2].data.data
  89. this.data.area = this.data.data.area
  90. this.setData({
  91. data: this.data.data,
  92. area: this.data.area
  93. })
  94. } else {
  95. wx.setNavigationBarTitle({
  96. title: '添加信息'
  97. })
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. return {
  135. path: '/page/home/index',
  136. imageUrl: '../../../../icon/public/share_img.png',
  137. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  138. }
  139. }
  140. })