address.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/checkAddress/handleAddCheck.js
  2. import { addressList, deleteAddress } from '../../api/address'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. currentPage: 1,
  10. hasNext: false,
  11. allAddressList: [],
  12. addressList: [],
  13. outRangAddresList: [], // 超出预约范围的地址
  14. formPage: '',
  15. formback:0,
  16. addressId: ''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. this.setData({
  23. formPage: options.form,
  24. formback: options.back
  25. })
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow() {
  31. this.getAddressList()
  32. },
  33. // 获取地址列表
  34. getAddressList () {
  35. var data = {
  36. currentPage: this.data.currentPage
  37. }
  38. wx.showLoading({
  39. title: '加载中...',
  40. mask: true
  41. })
  42. var temp = []
  43. var tempR = []
  44. addressList(data).then(res => {
  45. wx.hideLoading()
  46. var response = res.data.vos || []
  47. response.map(item => {
  48. if (item.isEnable) {
  49. temp.push(item)
  50. } else {
  51. tempR.push(item)
  52. }
  53. })
  54. this.setData({
  55. hasNext: res.data.hasNext,
  56. allAddressList: response,
  57. addressList: temp,
  58. outRangAddresList: tempR
  59. })
  60. }).catch(e => {
  61. wx.hideLoading()
  62. wx.showModal({
  63. content: e,
  64. confirmColor: '#333',
  65. showCancel: false
  66. })
  67. })
  68. },
  69. /**
  70. * 页面到底事件
  71. */
  72. onReachBottom() {
  73. if (this.data.hasNext) {
  74. var _currentPage = this.data.currentPage + 1
  75. this.setData({
  76. currentPage: _currentPage
  77. })
  78. this.getAddressList()
  79. }
  80. },
  81. /**
  82. * 编辑地址
  83. */
  84. handleEdit(e) {
  85. console.log(e);
  86. var value = e.currentTarget.dataset.item
  87. var editProvice = value.province
  88. var editCity = value.city
  89. var editCounty = value.county
  90. var editDetailAddress = value.detailAddress
  91. var editContactName = value.contactName
  92. var editContactPhone = value.contactPhone
  93. var editAddressId = value.addressId
  94. wx.navigateTo({
  95. url: '/pages/addressAdd/addressAdd?form=address&type=0&province=' + editProvice + '&city=' + editCity + '&county=' + editCounty + '&detailAddress=' + editDetailAddress + '&contactName=' + editContactName + '&contactPhone=' + editContactPhone + '&addressId=' + editAddressId
  96. })
  97. },
  98. /**
  99. * 点击地址Item 我的地址进入不做处理 预约页面进入返回预约页面
  100. */
  101. handleAddressChose (e) {
  102. if (e.currentTarget.dataset.info.isEnable) {
  103. if (this.data.formback == '1') {
  104. const address = e.currentTarget.dataset.info
  105. app.globalData.navigateBackParams.contactName = address.contactName
  106. app.globalData.navigateBackParams.addressId = address.addressId
  107. app.globalData.navigateBackParams.contactPhone = address.contactPhone
  108. app.globalData.navigateBackParams.province = address.province
  109. app.globalData.navigateBackParams.city = address.city
  110. app.globalData.navigateBackParams.county = address.county
  111. app.globalData.navigateBackParams.address = address.province + address.city + address.county + address.detailAddress
  112. wx.navigateBack()
  113. }
  114. } else {
  115. wx.showToast({
  116. title: '该地区未开通服务!',
  117. icon: "error"
  118. })
  119. }
  120. },
  121. /**
  122. * 用户点击删除地址按钮
  123. */
  124. handleDelAddres(e) {
  125. var delId = e.currentTarget.dataset.addressid
  126. var that = this
  127. this.setData({
  128. addressId: delId
  129. })
  130. wx.showModal({
  131. content: '确定要删除吗?',
  132. cancelColor: '#666',
  133. confirmColor: '#333',
  134. success (res) {
  135. if (res.confirm) {
  136. that.handleConfirm()
  137. }
  138. }
  139. })
  140. },
  141. // 删除地址接口函数
  142. handleConfirm () {
  143. var that = this
  144. var data = {
  145. addressId: that.data.addressId
  146. }
  147. wx.showLoading({
  148. title: '加载中...',
  149. mask: true
  150. })
  151. deleteAddress(data).then(res => {
  152. wx.hideLoading()
  153. that.setData({
  154. currentPage: 1
  155. })
  156. that.getAddressList()
  157. }).catch(e => {
  158. wx.hideLoading()
  159. wx.showModal({
  160. content: e,
  161. confirmColor: '#333',
  162. showCancel: false
  163. })
  164. })
  165. },
  166. /**
  167. * 用户点击 新增地址
  168. */
  169. handleAddressAdd() {
  170. wx.navigateTo({
  171. url: '/pages/addressAdd/addressAdd?form=address&type=1',
  172. })
  173. }
  174. })