"use strict";var e=Object.defineProperty,o=Object.defineProperties,r=Object.getOwnPropertyDescriptors,t=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,l=(o,r,t)=>r in o?e(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,n=(e,o)=>{for(var r in o||(o={}))i.call(o,r)&&l(e,r,o[r]);if(t)for(var r of t(o))a.call(o,r)&&l(e,r,o[r]);return e},s=(e,o,r)=>new Promise(((t,i)=>{var a=e=>{try{n(r.next(e))}catch(o){i(o)}},l=e=>{try{n(r.throw(e))}catch(o){i(o)}},n=e=>e.done?t(e.value):Promise.resolve(e.value).then(a,l);n((r=r.apply(e,o)).next())}));const d=require("../../../../common/vendor.js"),m=require("../../../../sheep/index.js"),u=require("../../../../sheep/validate/form.js"),p=require("../../../../sheep/api/system/area.js"),c=require("../../../../sheep/api/member/address.js");if(!Array){(d.resolveComponent("uni-easyinput")+d.resolveComponent("uni-forms-item")+d.resolveComponent("uni-icons")+d.resolveComponent("su-switch")+d.resolveComponent("uni-forms")+d.resolveComponent("su-fixed")+d.resolveComponent("su-region-picker")+d.resolveComponent("s-layout")+d.resolveComponent("layout-default-uni"))()}Math||((()=>"../../../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js")+(()=>"../../../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.js")+(()=>"../../../../uni_modules/uni-icons/components/uni-icons/uni-icons.js")+(()=>"../../../../sheep/ui/su-switch/su-switch.js")+(()=>"../../../../uni_modules/uni-forms/components/uni-forms/uni-forms.js")+(()=>"../../../../sheep/ui/su-fixed/su-fixed.js")+(()=>"../../../../sheep/ui/su-region-picker/su-region-picker.js")+(()=>"../../../../sheep/components/s-layout/s-layout.js"))();const f={__name:"edit",setup(e){const t=d.ref(null),i=d.reactive({showRegion:!1,model:{name:"",mobile:"",detailAddress:"",defaultStatus:!1,areaName:""},rules:{}}),a={name:{rules:[{required:!0,errorMessage:"请输入收货人姓名"}]},mobile:u.mobile,detailAddress:{rules:[{required:!0,errorMessage:"请输入详细地址"}]},areaName:{rules:[{required:!0,errorMessage:"请选择您的位置"}]}},l=e=>{i.model.areaName=`${e.province_name} ${e.city_name} ${e.district_name}`,i.model.areaId=e.district_id,i.showRegion=!1},f=()=>s(this,null,(function*(){if(!(yield d.unref(t).validate().catch((e=>{}))))return;const e=n({},i.model),{code:o}=i.model.id>0?yield c.AddressApi.updateAddress(e):yield c.AddressApi.createAddress(e);0===o&&m.sheep.$router.back()})),h=()=>{d.index.showModal({title:"提示",content:"确认删除此收货地址吗?",success:function(e){return s(this,null,(function*(){if(!e.confirm)return;const{code:o}=yield c.AddressApi.deleteAddress(i.model.id);0===o&&m.sheep.$router.back()}))}})};return d.onLoad((e=>s(this,null,(function*(){if(d.lodash.isEmpty(d.index.getStorageSync("areaData"))&&p.AreaApi.getAreaTree().then((e=>{0===e.code&&d.index.setStorageSync("areaData",e.data)})),e.id){const{code:o,data:r}=yield c.AddressApi.getAddress(e.id);if(0!==o)return;i.model=r}if(e.data){const l=JSON.parse(e.data),s=(e,o)=>e.find((e=>e.name===o)),m=s(d.index.getStorageSync("areaData"),l.province_name),u=m?s(m.children,l.city_name):void 0,p=((u?s(u.children,l.district_name):void 0)||u||m).id;i.model=(t=n({},i.model),a={areaId:p,areaName:[l.province_name,l.city_name,l.district_name].filter(Boolean).join(" "),defaultStatus:!1,detailAddress:l.address,mobile:l.mobile,name:l.consignee},o(t,r(a)))}var t,a})))),(e,o)=>d.e({a:d.o((e=>i.model.name=e)),b:d.p({placeholder:"请填写收货人姓名",inputBorder:!1,placeholderStyle:"color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",modelValue:i.model.name}),c:d.p({name:"name",label:"收货人"}),d:d.o((e=>i.model.mobile=e)),e:d.p({type:"number",placeholder:"请输入手机号",inputBorder:!1,placeholderStyle:"color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",modelValue:i.model.mobile}),f:d.p({name:"mobile",label:"手机号"}),g:d.p({type:"right"}),h:d.o((e=>i.model.areaName=e)),i:d.p({disabled:!0,inputBorder:!1,styles:{disableColor:"#fff",color:"#333"},placeholderStyle:"color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",placeholder:"请选择省市区",modelValue:i.model.areaName}),j:d.o((e=>i.showRegion=!0)),k:d.p({name:"areaName",label:"省市区"}),l:d.o((e=>i.model.detailAddress=e)),m:d.p({inputBorder:!1,type:"textarea",placeholderStyle:"color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal",placeholder:"请输入详细地址",clearable:!0,modelValue:i.model.detailAddress}),n:d.p({name:"detailAddress",label:"详细地址",formItemStyle:{alignItems:"flex-start"},labelStyle:{lineHeight:"5em"}}),o:d.o((e=>i.model.defaultStatus=e)),p:d.p({modelValue:i.model.defaultStatus}),q:d.sr(t,"4fa2a4b6-2,4fa2a4b6-1",{k:"addressFormRef"}),r:d.o((e=>i.model=e)),s:d.p({rules:a,validateTrigger:"bind",labelWidth:"160",labelAlign:"left",border:!0,labelStyle:{fontWeight:"bold"},modelValue:i.model}),t:d.o(f),v:i.model.id},i.model.id?{w:d.o(h)}:{},{x:d.p({bottom:!0,opacity:!1,bg:"",placeholder:!0,noFixed:!1,index:10}),y:d.o((e=>i.showRegion=!1)),z:d.o(l),A:d.p({show:i.showRegion}),B:d.p({title:i.model.id?"编辑地址":"新增地址"})})}},h=d._export_sfc(f,[["__scopeId","data-v-4fa2a4b6"]]);wx.createPage(h);