address.js 3.9 KB

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