"use strict";var e=require("../common/vendor.js"),s=require("../api/common.js"),t=require("../api/userAddress.js");require("../common/request.js");const i={components:{},data:()=>({content:null,type:null,addressId:null,isDefault:!1,addressList:[[],[],[]],multiIndex:[0,0,0],address:[],form:{realName:null,phone:null,detail:null,address:null,isDefault:0}}),onLoad(s){this.type=s.type,"edit"==this.type?(e.index.setNavigationBarTitle({title:"修改收货地址"}),this.addressId=s.addressId,this.getAddressById()):e.index.setNavigationBarTitle({title:"新增收货地址"}),this.getCitys()},methods:{parseAddress(){if(null!=this.content&&""!=this.content){var s={content:this.content};t.parseAddress(s).then((s=>{200==s.code?(this.form.realName=s.data.name,this.form.phone=s.data.mobile,this.form.address=s.data.provinceName+s.data.cityName+s.data.expAreaName,this.form.province=s.data.provinceName,this.form.city=s.data.cityName,this.form.district=s.data.expAreaName,this.form.detail=s.data.streetName+s.data.address,this.form.detail=this.form.detail.replace(/\s+/g,"")):e.index.showToast({icon:"none",title:s.msg})}),(e=>{}))}else e.index.showToast({icon:"none",title:"请输入地址信息"})},getAddressById(){var s={addressId:this.addressId};t.getAddressById(s).then((s=>{200==s.code?(this.form=s.data,this.isDefault=1==this.form.isDefault,this.form.address=this.form.province+this.form.city+this.form.district):e.index.showToast({icon:"none",title:s.msg})}),(e=>{}))},submit(){"add"==this.type?this.addAddress():"edit"==this.type&&this.editAddress()},editAddress(){this.form.isDefault=this.isDefault?1:0,t.editAddress(this.form).then((s=>{200==s.code?(e.index.showToast({icon:"success",title:"操作成功"}),setTimeout((function(){e.index.$emit("refreshAddress"),e.index.navigateBack({delta:1})}),500)):e.index.showToast({icon:"none",title:s.msg})}),(e=>{}))},addAddress(){this.form.isDefault=this.isDefault?1:0,t.addAddress(this.form).then((s=>{200==s.code?(e.index.showToast({icon:"success",title:"操作成功"}),setTimeout((function(){e.index.$emit("refreshAddress"),e.index.navigateBack({delta:1})}),500)):e.index.showToast({icon:"none",title:s.msg})}),(e=>{}))},pickerChange(e){this.multiIndex=e.detail.value,this.form.address=this.addressList[0][this.multiIndex[0]].n+this.addressList[1][this.multiIndex[1]].n+this.addressList[2][this.multiIndex[2]].n,this.form.province=this.addressList[0][this.multiIndex[0]].n,this.form.city=this.addressList[1][this.multiIndex[1]].n,this.form.district=this.addressList[2][this.multiIndex[2]].n,this.form.cityId=this.addressList[1][this.multiIndex[1]].v},pickerColumnchange(e){0===e.detail.column&&(this.multiIndex[0]=e.detail.value,this.addressList[1]=this.address[this.multiIndex[0]].c,this.addressList[2]=this.address[this.multiIndex[0]].c[0].c,this.multiIndex.splice(1,1,0),this.multiIndex.splice(2,1,0)),1===e.detail.column&&(this.multiIndex[1]=e.detail.value,this.addressList[2]=this.address[this.multiIndex[0]].c[this.multiIndex[1]].c,this.multiIndex.splice(2,1,0)),2===e.detail.column&&(this.multiIndex[2]=e.detail.value)},getCitys(){s.getCitys().then((s=>{if(200==s.code){this.address=s.data;for(var t=0;t<this.address.length;t++)this.addressList[0].push(this.address[t]);for(t=0;t<this.address[0].c.length;t++)this.addressList[1].push(this.address[0].c[t]);for(t=0;t<this.address[0].c[0].c.length;t++)this.addressList[2].push(this.address[0].c[0].c[t])}else e.index.showToast({icon:"none",title:"请求失败"})}),(e=>{}))}}};if(!Array){e.resolveComponent("u-switch")()}Math;var d=e._export_sfc(i,[["render",function(s,t,i,d,a,r){return{a:a.form.realName,b:e.o((e=>a.form.realName=e.detail.value)),c:a.form.phone,d:e.o((e=>a.form.phone=e.detail.value)),e:a.form.address,f:e.o((e=>a.form.address=e.detail.value)),g:a.multiIndex,h:a.addressList,i:e.o(((...e)=>r.pickerChange&&r.pickerChange(...e))),j:e.o(((...e)=>r.pickerColumnchange&&r.pickerColumnchange(...e))),k:a.form.detail,l:e.o((e=>a.form.detail=e.detail.value)),m:a.content,n:e.o((e=>a.content=e.detail.value)),o:e.o((e=>r.parseAddress())),p:e.o((e=>a.isDefault=e)),q:e.p({activeColor:"#C39A58",modelValue:a.isDefault}),r:e.o((e=>r.submit()))}}]]);wx.createPage(d);
