address.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. formPage: '',
  13. formback:0,
  14. addressId: ''
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. console.log(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. console.log(value);
  84. },
  85. /**
  86. * 点击地址Item 我的地址进入不做处理 预约页面进入返回预约页面
  87. */
  88. handleAddressChose (e) {
  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. handleDelAddres(e) {
  105. var delId = e.currentTarget.dataset.addressid
  106. var that = this
  107. this.setData({
  108. addressId: delId
  109. })
  110. wx.showModal({
  111. content: '确定要删除吗?',
  112. cancelColor: '#666',
  113. confirmColor: '#333',
  114. success (res) {
  115. if (res.confirm) {
  116. that.handleConfirm()
  117. }
  118. }
  119. })
  120. },
  121. // 删除地址接口函数
  122. handleConfirm () {
  123. var that = this
  124. var data = {
  125. addressId: that.data.addressId
  126. }
  127. wx.showLoading({
  128. title: '加载中...',
  129. mask: true
  130. })
  131. deleteAddress(data).then(res => {
  132. wx.hideLoading()
  133. that.setData({
  134. currentPage: 1
  135. })
  136. that.getAddressList()
  137. }).catch(e => {
  138. wx.hideLoading()
  139. wx.showModal({
  140. content: e,
  141. confirmColor: '#333',
  142. showCancel: false
  143. })
  144. })
  145. },
  146. /**
  147. * 用户点击 新增地址
  148. */
  149. handleAddressAdd() {
  150. wx.navigateTo({
  151. url: '/pages/addressAdd/addressAdd?form=address&type=1',
  152. })
  153. }
  154. })