| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 | // pages/editAddress/editAddress.jsvar http = require("../../utils/http.js");var util = require("../../utils/util.js");var show = false;var moveY = 200;Page({  /**   * 页面的初始数据   */  data: {    value: [0, 0, 0],    provArray: [],    cityArray: [],    areaArray: [],    province: "",    city: "",    area: "",    provinceId: 0,    cityId: 0,    areaId: 0,    receiver: "",    mobile: "",    addr: "",    addrId: 0,    sel_address:{},    is_select:false,  },  onLoad: function (options) {    if (options.addrId) {      wx.showLoading();      var params = {        url: "/p/address/addrInfo/" + options.addrId,        method: "GET",        callBack: res => {          this.setData({            is_select:true,            sel_address:res,            province: res.province,            city: res.city,            area: res.area,            provinceId: res.provinceId,            cityId: res.cityId,            areaId: res.areaId,            receiver: res.receiver,            mobile: res.mobile,            addr: res.addrDetail,            addrId: options.addrId          });          // this.initCityData(res.provinceId, res.cityId, res.areaId);          wx.hideLoading();        }      }      http.request(params);    } else {      // this.initCityData(this.data.provinceId, this.data.cityId, this.data.areaId);    }  },  // initCityData: function (provinceId, cityId, areaId) {  //   var ths = this;  //   wx.showLoading();  //   var params = {  //     url: "/p/area/listByPid",  //     method: "GET",  //     data: {  //       pid: 0  //     },  //     callBack: function (res) {  //       ths.setData({  //         provArray: res  //       });  //       if (provinceId) {  //         for (var index in res) {  //           if (res[index].areaId == provinceId) {  //             ths.setData({  //               value: [index, ths.data.value[1], ths.data.value[2]]  //             });  //           }  //         }  //       }  //       ths.getCityArray(provinceId ? provinceId : res[0].areaId, cityId, areaId);  //       wx.hideLoading();  //     }  //   }  //   http.request(params);  // },  /**   * 生命周期函数--监听页面显示   */  onShow: function () {  },  onReady: function () {    this.animation = wx.createAnimation({      transformOrigin: "50% 50%",      duration: 0,      timingFunction: "ease",      delay: 0    })    this.animation.translateY(200 + 'vh').step();    this.setData({      animation: this.animation.export(),      show: show    })  },  //移动按钮点击事件  translate: function (e) {    let that = this    wx.chooseLocation({      success: function (res) {        that.setData({          sel_address:res,          is_select:true        })      },      fail: function (err) {        console.log(err, '---err');      },      complete: function (e) {        // console.log(e, '-----callback');      }    })  },  //隐藏弹窗浮层  hiddenFloatView(e) {    //console.log(e);    moveY = 200;    show = true;    t = 0;    this.animationEvents(this, moveY, show);  },  //动画事件  animationEvents: function (that, moveY, show) {    //console.log("moveY:" + moveY + "\nshow:" + show);    that.animation = wx.createAnimation({      transformOrigin: "50% 50%",      duration: 400,      timingFunction: "ease",      delay: 0    })    that.animation.translateY(moveY + 'vh').step()    that.setData({      animation: that.animation.export()    })  },  /**   * 根据省份ID获取 城市数据   */  // getCityArray: function (provinceId, cityId, areaId) {  //   var ths = this;  //   var params = {  //     url: "/p/area/listByPid",  //     method: "GET",  //     data: {  //       pid: provinceId  //     },  //     callBack: function (res) {  //       //console.log(res)  //       ths.setData({  //         cityArray: res  //       });  //       if (cityId) {  //         for (var index in res) {  //           if (res[index].areaId == cityId) {  //             ths.setData({  //               value: [ths.data.value[0], index, ths.data.value[2]]  //             });  //           }  //         }  //       }  //       ths.getAreaArray(cityId ? cityId : res[0].areaId, areaId);  //       wx.hideLoading();  //     }  //   }  //   http.request(params);  // },  /**   * 根据城市ID获取 区数据   */  // getAreaArray: function (cityId, areaId) {  //   var ths = this;  //   var params = {  //     url: "/p/area/listByPid",  //     method: "GET",  //     data: {  //       pid: cityId  //     },  //     callBack: function (res) {  //       //console.log(res)  //       ths.setData({  //         areaArray: res  //       });  //       if (areaId) {  //         for (var _index in res) {  //           if (res[_index].areaId == areaId) {  //             ths.setData({  //               value: [ths.data.value[0], ths.data.value[1], _index]  //             });  //           }  //         }  //         index = ths.data.value;  //         ths.setData({  //           province: ths.data.province,  //           city: ths.data.city,  //           area: ths.data.area,  //           provinceId: ths.data.provinceId,  //           cityId: ths.data.cityId,  //           areaId: ths.data.areaId  //         })  //       } else {  //         ths.setData({  //           // province: ths.data.provArray[ths.data.value[0]].areaName,  //           // city: ths.data.cityArray[ths.data.value[1]].areaName,  //           // area: ths.data.areaArray[ths.data.value[2]].areaName,  //           // provinceId: ths.data.provArray[ths.data.value[0]].areaId,  //           // cityId: ths.data.cityArray[ths.data.value[1]].areaId,  //           // areaId: ths.data.areaArray[ths.data.value[2]].areaId  //         })  //       }  //       wx.hideLoading();  //     }  //   }  //   http.request(params);  // },  bindRegionChange: function (e) {    //console.log('picker发送选择改变,携带值为', e.detail.value)    this.setData({      region: e.detail.value    })  },  /**   * 保存地址   */  onSaveAddr: function () {    var ths = this;    var receiver = ths.data.receiver;    var mobile = ths.data.mobile;    var addr = ths.data.addr;    if (!receiver) {      wx.showToast({        title: '请输入收货人姓名',        icon: "none"      })      return;    }    if (!mobile) {      wx.showToast({        title: '请输入手机号码',        icon: "none"      })      return;    }    if (!util.checkPhoneNumber(this.data.mobile)) {      wx.showToast({        title: '请输入正确的手机号码',        icon: "none"      })      return;    }    if (!addr) {      wx.showToast({        title: '请输入详细地址',        icon: "none"      })      return;    }    wx.showLoading();    var url = "/p/address/addAddr";    var method = "POST";    if (ths.data.addrId != 0) {      url = "/p/address/updateAddr";      method = "PUT";    }    //添加或修改地址    var params = {      url: url,      method: method,      data: {        receiver: ths.data.receiver,        mobile: ths.data.mobile,        addrDetail: ths.data.addr,        province: ths.data.province,        provinceId: ths.data.provinceId,        city: ths.data.city,        cityId: ths.data.cityId,        areaId: ths.data.areaId,        area: ths.data.area,        userType: 0,        addrId: ths.data.addrId,        addressName:ths.data.sel_address.addressName||ths.data.sel_address.name,        address:ths.data.sel_address.address,        longitude:ths.data.sel_address.longitude,        latitude:ths.data.sel_address.latitude      },      callBack: function (res) {        wx.hideLoading();        wx.navigateBack({          delta: 1        })      }    }    http.request(params);  },  onReceiverInput: function (e) {    this.setData({      receiver: e.detail.value    });  },  onMobileInput: function (e) {    this.setData({      mobile: e.detail.value    });  },  onAddrInput: function (e) {    this.setData({      addr: e.detail.value    });  },  //删除配送地址  onDeleteAddr: function (e) {    var ths = this;    wx.showModal({      title: '',      content: '确定要删除此收货地址吗?',      confirmColor: "#006CE8",      success(res) {        if (res.confirm) {          var addrId = ths.data.addrId;          wx.showLoading();          var params = {            url: "/p/address/deleteAddr/" + addrId,            method: "DELETE",            data: {},            callBack: function (res) {              wx.hideLoading();              wx.navigateBack({                delta: 1              })            }          }          http.request(params);        } else if (res.cancel) {          console.log('用户点击取消')        }      }    })  },})
 |