"use strict";var e=(e,t,o)=>new Promise((u,a)=>{var l=e=>{try{i(o.next(e))}catch(t){a(t)}},n=e=>{try{i(o.throw(e))}catch(t){a(t)}},i=e=>e.done?u(e.value):Promise.resolve(e.value).then(l,n);i((o=o.apply(e,t)).next())});const t=require("../../common/vendor.js"),o=require("../../common/assets.js"),u=require("../../stores/price.js"),a=require("../../stores/bluetooth.js"),l=require("../../stores/order.js"),n=require("../../stores/region.js"),i=t.defineComponent({__name:"weigh",setup(i){const r=u.usePriceStore(),v=a.useBluetoothStore(),s=l.useOrderStore(),c=n.useRegionStore(),d=t.ref(""),g=t.ref(0),h=t.ref(0),m=t.ref(""),p=t.ref("bluetooth"),f=t.ref(""),x=t.computed(()=>r.getPriceByCategory(d.value)),b=t.computed(()=>{if(!x.value)return 0;const e="kg"===x.value.unit?"bluetooth"===p.value?g.value:parseFloat(f.value)||0:h.value;return Number((e*x.value.price).toFixed(2))});t.onLoad(t=>e(this,null,function*(){(null==t?void 0:t.category)&&(d.value=t.category),yield r.loadPrices(),v.init()}));const w=()=>{t.index.navigateTo({url:"/pages/bluetooth/bluetooth"})},k=()=>{v.resetWeight(),g.value=0},y=()=>{h.value>0&&(h.value--,m.value=h.value.toString())},F=()=>{h.value++,m.value=h.value.toString()},_=()=>{const e=parseInt(m.value)||0;h.value=Math.max(0,e)},S=e=>{h.value+=e,m.value=h.value.toString()},j=e=>{p.value=e,"manual"===e&&(f.value=g.value>0?g.value.toString():"")},q=()=>{const e=parseFloat(f.value);!isNaN(e)&&e>=0&&(g.value=e)},P=e=>{const t=parseFloat(f.value)||0;f.value=(t+e).toFixed(2),q()},$=()=>e(this,null,function*(){if(!x.value)return void t.index.showToast({title:"请选择回收种类",icon:"none"});const o="kg"===x.value.unit?"bluetooth"===p.value?g.value:parseFloat(f.value)||0:h.value;if(o<=0)return void t.index.showToast({title:"kg"===x.value.unit?"请输入重量":"请输入数量",icon:"none"});const u={category:x.value.category,name:x.value.name,weight:"kg"===x.value.unit?o:void 0,count:"piece"===x.value.unit?h.value:void 0,unit:x.value.unit,price:x.value.price,amount:b.value};t.index.showModal({title:"确认回收",content:`确定回收${x.value.name} ${o}${"kg"===x.value.unit?"kg":"个"},金额¥${b.value.toFixed(2)}?`,success:o=>e(this,null,function*(){if(o.confirm){t.index.showLoading({title:"保存中..."});const e=c.getRegion(),o=yield s.createOrder([u],e);t.index.hideLoading(),o?(t.index.showToast({title:"回收成功",icon:"success"}),setTimeout(()=>{t.index.navigateBack()},1500)):t.index.showToast({title:"保存失败",icon:"none"})}})})});return t.onMounted(()=>{const e=()=>{g.value=v.currentWeight};v.$subscribe(()=>{e()}),e()}),t.onShow(()=>{r.loadPrices()}),(e,u)=>{var a,l,n,i,r;return t.e({a:t.t(t.unref(v).isConnected?"🔵":"⚪"),b:t.t(t.unref(v).isConnected?"已连接":"未连接"),c:t.unref(v).isConnected?1:"",d:t.t((null==(a=x.value)?void 0:a.name)||"-"),e:t.t((null==(l=x.value)?void 0:l.price)||0),f:t.t("kg"===(null==(n=x.value)?void 0:n.unit)?"kg":"个"),g:"kg"===(null==(i=x.value)?void 0:i.unit)},"kg"===(null==(r=x.value)?void 0:r.unit)?t.e({h:"bluetooth"===p.value?1:"",i:t.o(e=>j("bluetooth")),j:"manual"===p.value?1:"",k:t.o(e=>j("manual")),l:"bluetooth"===p.value},"bluetooth"===p.value?{m:t.t(g.value.toFixed(2))}:{n:t.o([e=>f.value=e.detail.value,q]),o:f.value},{p:"bluetooth"===p.value},"bluetooth"===p.value?{q:o._imports_0$2,r:t.o(w),s:o._imports_1$1,t:t.o(k)}:{v:t.o(e=>P(.5)),w:t.o(e=>P(1)),x:t.o(e=>P(2)),y:t.o(e=>P(5))}):{z:t.o([e=>m.value=e.detail.value,_]),A:m.value,B:t.o(y),C:t.o(F),D:t.o(e=>S(1)),E:t.o(e=>S(5)),F:t.o(e=>S(10)),G:t.o(e=>S(50))},{H:t.t(b.value.toFixed(2)),I:t.o($)})}}}),r=t._export_sfc(i,[["__scopeId","data-v-95ce5baf"]]);wx.createPage(r);