123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- // 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',
- })
- }
- })
|