123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- // pages/editAddress/editAddress.js
- const request = require("../../utils/request.js");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- districtData: {},
- multiArray: [[], [], []],//picker窗口显示数据
- multiIndex: [0, 0, 0],
- districtArray: [[], [], []],//实际显示数据
- districtIndex: [0, 0, 0],
- districtId: null,
- name: '',
- phone: '',
- detailAddress: '',
- defaultAddress: false,
- userAddressId: null,//修改
- editAdressData: {},
- delViewStatus: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getDistrictData().then(res=>{
- if(options.userAddressId) {
- wx.setNavigationBarTitle({
- title: '编辑收货地址'
- })
- this.setData({
- userAddressId: options.userAddressId
- })
- this.getAddressDetail();
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- deleteFun() {
- this.setData({
- delViewStatus: true
- })
- },
- cancelDel() {
- this.setData({
- delViewStatus: false
- })
- },
- sureDel() {
- let that = this;
- request.postData(
- 'app/user/address/remove',
- {userAddressId: that.data.userAddressId},
- res => {
- wx.navigateBack({
- delta: 1
- })
- }
- )
- },
- getAddressDetail() {
- let that = this;
- request.getData(
- 'app/user/address/detail',{userAddressId: that.data.userAddressId},
- res => {
- that.data.districtArray[1] = that.data.multiArray[1] = that.findarr(res.data.data.districtList[0].districtId, that.data.districtData.cityList);
- that.data.districtArray[2] = that.data.multiArray[2] = that.findarr(res.data.data.districtList[1].districtId, that.data.districtData.districtList);
- that.data.districtIndex[0] = that.data.multiIndex[0] = that.findIndex(res.data.data.districtList[0].districtId, that.data.districtArray[0]);
- that.data.districtIndex[1] = that.data.multiIndex[1] = that.findIndex(res.data.data.districtList[1].districtId, that.data.districtArray[1]);
- that.data.districtIndex[2] = that.data.multiIndex[2] = that.findIndex(res.data.data.districtList[2].districtId, that.data.districtArray[2]);
- let data = {
- name: res.data.data.name,
- phone: res.data.data.phone,
- districtId: res.data.data.districtList[2].districtId,
- detailAddress: res.data.data.detailAddress,
- defaultAddress: res.data.data.defaultAddress,
- multiArray: that.data.multiArray,
- districtArray: that.data.districtArray,
- districtIndex: that.data.districtIndex,
- multiIndex: that.data.multiIndex
- };
- that.setData(data)
- }
- )
- },
- toSave() {
- let that = this;
- if(that.data.name == '') {
- wx.showToast({
- title: '请输入姓名',
- icon: 'none',
- duration: 2000
- })
- return
- }else if(that.data.phone == '') {
- wx.showToast({
- title: '请输入手机号码',
- icon: 'none',
- duration: 2000
- })
- return
- }else if(that.data.detailAddress == '') {
- wx.showToast({
- title: '请输入详细地址',
- icon: 'none',
- duration: 2000
- })
- return
- }
- let addressObject
- if(that.data.userAddressId) {
- addressObject = {
- userAddressId: that.data.userAddressId,
- name: that.data.name,
- phone: that.data.phone,
- districtId: that.data.districtId,
- detailAddress: that.data.detailAddress,
- defaultAddress: that.data.defaultAddress
- }
- request.postData(
- 'app/user/address/update',
- addressObject,
- res => {
- console.log(res.data.data)
- wx.navigateBack({
- delta: 1
- })
- }
- )
- }else{
- addressObject = {
- name: that.data.name,
- phone: that.data.phone,
- districtId: that.data.districtId,
- detailAddress: that.data.detailAddress,
- defaultAddress: that.data.defaultAddress
- }
- request.postData(
- 'app/user/address/create',
- addressObject,
- res => {
- console.log(res.data.data)
- wx.navigateBack({
- delta: 1
- })
- }
- )
- }
- console.log(addressObject)
- },
- switchDefaultAddressChange(event) {
- this.setData({
- defaultAddress: event.detail.value
- })
- },
- getDetailAddressInput(event) {
- this.setData({
- detailAddress: event.detail.value
- })
- },
- getPhoneInput(event) {
- this.setData({
- phone: event.detail.value
- })
- },
- getNameInput(event) {
- this.setData({
- name: event.detail.value
- })
- },
- findIndex(districtId, arr) {
- for(let index=0; index<=arr.length; index++) {
- if(arr[index].districtId == districtId) {
- return index
- }
- }
- },
- findarr(pid, arr) {
- var obj = []
- arr.forEach((val)=> {
- if(val.pid == pid) {
- obj.push(val)
- }
- })
- return obj
- },
- getDistrictData() {
- let that = this;
- return new Promise((resolve, reject) => {
- var districtData = wx.getStorageSync('districtData')
- that.data.multiArray[0] = districtData.provinceList;
- that.data.multiArray[1] = that.findarr(that.data.multiArray[0][0].districtId, districtData.cityList);
- that.data.multiArray[2] = that.findarr(that.data.multiArray[1][0].districtId, districtData.districtList);
- that.setData({
- districtData: districtData,
- multiArray: that.data.multiArray,
- districtArray: that.data.multiArray,
- })
- resolve(districtData)
- })
- },
- // getDistrictData() {
- // let that = this;
- // return new Promise((resolve, reject) => {
- // request.getData(
- // 'app/district/list',{},
- // res => {
- // that.data.multiArray[0] = res.data.data.provinceList;
- // that.data.multiArray[1] = that.findarr(that.data.multiArray[0][0].districtId, res.data.data.cityList);
- // that.data.multiArray[2] = that.findarr(that.data.multiArray[1][0].districtId, res.data.data.districtList);
- // that.setData({
- // districtData: res.data.data,
- // multiArray: that.data.multiArray,
- // districtArray: that.data.multiArray,
- // })
- // resolve(res)
- // }
- // )
- // })
- // },
- bindMultiPickerChange: function (e) {
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- let districtId = this.data.multiArray[2][e.detail.value[2]].districtId;
- this.setData({
- districtArray: this.data.multiArray,
- districtIndex: e.detail.value,
- districtId: districtId
- })
- },
- bindMultiPickerColumnChange: function (e) {
- let that = this;
- // console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
- var data = {
- multiArray: that.data.multiArray,
- multiIndex: that.data.multiIndex
- };
- data.multiIndex[e.detail.column] = e.detail.value;
- switch (e.detail.column) {
- case 0:
- data.multiArray[1] = that.findarr(data.multiArray[0][e.detail.value].districtId, that.data.districtData.cityList);
- data.multiArray[2] = that.findarr(data.multiArray[1][0].districtId, that.data.districtData.districtList);
- data.multiIndex[1] = 0;
- data.multiIndex[2] = 0;
- break;
- case 1:
- data.multiArray[2] = that.findarr(data.multiArray[1][e.detail.value].districtId, that.data.districtData.districtList);
- data.multiIndex[2] = 0;
- break;
- }
- // console.log(data.multiIndex);
- that.setData(data);
- },
- })
|