"use strict";var e=(e,t,a)=>new Promise(((l,u)=>{var o=e=>{try{i(a.next(e))}catch(t){u(t)}},s=e=>{try{i(a.throw(e))}catch(t){u(t)}},i=e=>e.done?l(e.value):Promise.resolve(e.value).then(o,s);i((a=a.apply(e,t)).next())}));const t=require("../../common/vendor.js"),a=require("../../utils/http.js"),l=require("../../utils/commUtils.js");require("../../utils/map-utils.js"),require("../../store/index.js");const u=require("../../service/auth.js"),o=require("../../store/user.js");if(!Array){t.resolveComponent("layout-default-uni")()}Math||s();const s=()=>"../../components/Map.js",i={__name:"door",setup(s){let i=null;const r=t.ref(null),n=t.ref(!!r.value),v=t.ref(""),c=t.ref(["宠物看护","宠物洗澡","宠物训练","宠物寄养"]),d=t.ref(0),h=t.ref(""),p=t.ref(0),f=t.ref(""),m=t.ref(!0),y=t.ref([]),x=t.ref(!0),g=t.ref({}),w=t.ref({}),b=o.useUserStore();t.onLoad((t=>e(this,null,(function*(){t.id&&(r.value=t.id,yield T())})))),t.onShow((()=>e(this,null,(function*(){yield j()}))));const j=()=>e(this,null,(function*(){if(!b.userInfo.isRealName){l.toast("您还未实名认证,请先实名认证!");try{const e=yield u.isBindPhone();if(200!=e.code||!e.data)return l.toast("您手机号还未绑定!"),void t.index.navigateTo({url:"/pages/permission/bind-phone"})}catch(e){}return l.toast("请先实名认证!"),void t.index.navigateTo({url:"/pages/permission/real-name-auth"})}})),q=e=>{x.value=!1,e.value=e,f.value=e.formatted_address},T=()=>e(this,null,(function*(){try{const e=yield a.httpPost("/personal-service/get",{id:r.value});if(200==e.code){const t=e.data;v.value=t.serviceName,d.value=c.value.indexOf(t.type),h.value=t.description,p.value=t.price,f.value=t.serviceHost,m.value=1===t.state,y.value=[t.url],g.value={latitude:t.latitude,longitude:t.longitude,address:t.address}}}catch(e){t.index.showToast({title:"获取服务数据失败",icon:"none"})}})),P=e=>{p.value=Math.max(p.value+e,0)},_=e=>{i=setInterval((()=>{P(e?10:-10)}),200)},N=()=>{clearInterval(i)},I=e=>{m.value=e.value},U=()=>{t.index.chooseImage({count:1,success:t=>e(this,null,(function*(){for(const e of t.tempFilePaths){const t=yield M(e);t&&(y.value.pop(),y.value.push(t))}})),fail:()=>{t.index.showToast({title:"图片选择失败",icon:"none"})}})},M=l=>e(this,null,(function*(){try{const e=yield a.httpUploadFile("/file/upload",l);return e&&e.data&&e.data.url?e.data.url:(t.index.showToast({title:"图片上传失败",icon:"none"}),"")}catch(e){return t.index.showToast({title:"图片上传失败",icon:"none"}),""}})),F=()=>{const e={id:r.value,serviceName:v.value,type:c.value[d.value],description:h.value,price:p.value,serviceHost:f.value,state:m.value?1:0,url:y.value[0],address:g.value.address,latitude:`${g.value.latitude}`,longitude:`${g.value.longitude}`,country:w.value.country,province:w.value.province,city:w.value.city,district:w.value.district,township:w.value.township,streetNumber:w.value.streetNumber.street+w.value.streetNumber.number},l=n.value?"/personal-service/update":"/personal-service/push";a.httpPost(l,e).then((e=>{200===e.code?t.index.showToast({title:n.value?"更新成功":"发布成功",icon:"success"}):t.index.showToast({title:n.value?"更新失败":"发布失败",icon:"none"})}))};return(e,a)=>t.e({a:v.value,b:t.o((e=>v.value=e.detail.value)),c:t.t(c.value[d.value]),d:c.value,e:h.value,f:t.o((e=>h.value=e.detail.value)),g:t.o((e=>_(!1))),h:t.o(N),i:t.o((e=>P(1))),j:p.value,k:t.o((e=>p.value=e.detail.value)),l:t.o((e=>_(!0))),m:t.o(N),n:t.o((e=>P(1))),o:t.t(f.value),p:x.value,q:t.o(q),r:m.value,s:t.o(I),t:t.o(U),v:y.value.length>0},y.value.length>0?{w:t.f(y.value,((e,a,u)=>({a:a,b:"url("+t.unref(l.baseUrl)+e+")"})))}:{},{x:t.t(n.value?"更新服务":"发布上门服务"),y:t.o(F)})}},r=t._export_sfc(i,[["__scopeId","data-v-c3a5a7b2"]]);wx.createPage(r);