// pages/checkAddress/handleAddCheck.js import { addressList, deleteAddress } from '../../api/address' const app = getApp() Page({ /** * 页面的初始数据 */ data: { currentPage: 1, hasNext: false, allAddressList: [], addressList: [], outRangAddresList: [], // 超出预约范围的地址 formPage: '', formback:0, addressId: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ formPage: options.form, formback: options.back }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getAddressList() }, // 获取地址列表 getAddressList () { var data = { currentPage: this.data.currentPage } wx.showLoading({ title: '加载中...', mask: true }) var temp = [] var tempR = [] addressList(data).then(res => { wx.hideLoading() var response = res.data.vos || [] response.map(item => { if (item.isEnable) { temp.push(item) } else { tempR.push(item) } }) this.setData({ hasNext: res.data.hasNext, allAddressList: response, addressList: temp, outRangAddresList: tempR }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 页面到底事件 */ onReachBottom() { if (this.data.hasNext) { var _currentPage = this.data.currentPage + 1 this.setData({ currentPage: _currentPage }) this.getAddressList() } }, /** * 编辑地址 */ handleEdit(e) { console.log(e); var value = e.currentTarget.dataset.item var editProvice = value.province var editCity = value.city var editCounty = value.county var editDetailAddress = value.detailAddress var editContactName = value.contactName var editContactPhone = value.contactPhone var editAddressId = value.addressId wx.navigateTo({ url: '/pages/addressAdd/addressAdd?form=address&type=0&province=' + editProvice + '&city=' + editCity + '&county=' + editCounty + '&detailAddress=' + editDetailAddress + '&contactName=' + editContactName + '&contactPhone=' + editContactPhone + '&addressId=' + editAddressId }) }, /** * 点击地址Item 我的地址进入不做处理 预约页面进入返回预约页面 */ handleAddressChose (e) { if (e.currentTarget.dataset.info.isEnable) { if (this.data.formback == '1') { const address = e.currentTarget.dataset.info app.globalData.navigateBackParams.contactName = address.contactName app.globalData.navigateBackParams.addressId = address.addressId app.globalData.navigateBackParams.contactPhone = address.contactPhone app.globalData.navigateBackParams.province = address.province app.globalData.navigateBackParams.city = address.city app.globalData.navigateBackParams.county = address.county app.globalData.navigateBackParams.address = address.province + address.city + address.county + address.detailAddress wx.navigateBack() } } else { wx.showToast({ title: '该地区未开通服务!', icon: "error" }) } }, /** * 用户点击删除地址按钮 */ handleDelAddres(e) { var delId = e.currentTarget.dataset.addressid var that = this this.setData({ addressId: delId }) wx.showModal({ content: '确定要删除吗?', cancelColor: '#666', confirmColor: '#333', success (res) { if (res.confirm) { that.handleConfirm() } } }) }, // 删除地址接口函数 handleConfirm () { var that = this var data = { addressId: that.data.addressId } wx.showLoading({ title: '加载中...', mask: true }) deleteAddress(data).then(res => { wx.hideLoading() that.setData({ currentPage: 1 }) that.getAddressList() }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 用户点击 新增地址 */ handleAddressAdd() { wx.navigateTo({ url: '/pages/addressAdd/addressAdd?form=address&type=1', }) } })