import{A as v,_ as ie,r,D as de,o as ve,m as E,a as pe,b as j,j as fe,c as y,d as J,w as h,e as o,l as Q,g as L,t as F,p as _e,h as C,f as A,k as me,F as ge,i as ye,n as V,E as k,s as he,u as ke}from"./index-u0hj8LVS.js";function Ge(t){return v.post("user/cart/create",t)}function He(t){return v.get("user/cart/lst",{params:t})}function Je(t,c){return v.post(`user/cart/change/${t}`,c)}function Qe(t){return v.post("v2/order/check",t)}function Xe(t){return v.post("user/cart/delete",t)}function X(t){return v.post("v2/order/create",t)}function be(t,c){return v.post(`order/pay/${t}`,c)}function we(t){return v.get("micropay_query",{params:t})}function Ye(t,c){return v.get(`admin/${t}/order_list`,{params:c})}function Ze(t,c){return v.get(`verifier/${t}/order/${c}`)}function ea(t){return v.get("order_lading",{params:t})}const T=t=>{if(!t)return;let c=new window.SpeechSynthesisUtterance(t);window.speechSynthesis.speak(c)},U=t=>(he("data-v-9c62934a"),t=t(),ke(),t),Ce=U(()=>o("h4",null,"选择支付方式",-1)),Ae={class:"dra-body"},xe={class:"header"},Se=U(()=>o("div",{style:{color:"#999",padding:"2rem 0 0.3rem 0"}},"应收金额(元):",-1)),$e={style:{color:"#f5222d","padding-bottom":"2rem"}},Le={style:{"font-size":"1.6rem"}},Ve={key:0,"element-loading-text":"支付中",class:"card1"},De=U(()=>o("div",{class:"tips"},null,-1)),Be={key:1,class:"card2"},Ee={class:"drawer-body"},je={class:"counter"},Pe={class:"received"},Fe={key:0},Te={key:1,style:{"font-size":"1rem",color:"#999"}},ze={key:0,class:"balance"},Ie={class:"money"},Ne={key:1,class:"balance"},Oe={class:"keypad"},Ue={class:"left"},qe={class:"right"},Re={style:{width:"100%",display:"flex","justify-content":"center"}},Ke={__name:"pay",emits:["paySuccess"],setup(t,{expose:c,emit:Y}){const m=r(!1),g=r(1),l=r(""),i=r(""),Z=()=>{b()},ee=()=>{V(()=>{setTimeout(()=>{var e;n.value=!1,l.value="",I.value=!0,(e=i.value)==null||e.focus(),x(g.value)},300)})},x=e=>{g.value=e,g.value==2?window.addEventListener("keydown",O):(window.removeEventListener("keydown",O),V(()=>{var a;l.value="",(a=i.value)==null||a.focus()}))},S=r({}),z=r([]),ae=e=>{S.value=e.data,z.value=e.cart_id},se=e=>{S.value.order_price=e.price,p.value=e.order_id},te=Y,I=r(!1),oe=r(["1","2","3","4","5","6","7","8","9","0","00","."]);let $=0;const q=/^(10|11|12|13|14|15)\d{16}$/,R=/^(25|26|27|28|29|30)\d{14,22}$/,p=r(""),le=()=>{if(n.value=!0,i.value.blur(),p.value)K(p.value);else{let e;if(q.test(l.value))e="micropay";else if(R.test(l.value))e="alipayBar";else return n.value=!1,l.value="",i.value.focus(),k.error("请输入正确的支付码");X({address_id:"",key:S.value.key,cart_id:z.value,pay_type:e,auth_code:l.value,source:300}).then(a=>{if(a.status==200&&(a.message=="支付成功"||a.message=="success"))m.value=!1,k({message:a.message=="success"?"支付成功":a.message,type:"success"}),T(a.data.message||a.data.result.message),b();else if(a.data.group_order_sn)p.value=a.data.group_order_id,D.value=0,$=0,P(a.data.group_order_sn);else return p.value=a.data.result.order_id,n.value=!1,k({message:a.message,type:"error"})}).catch(a=>{n.value=!1,V(()=>{var s;(s=i.value)==null||s.focus()})})}},K=e=>{let a;if(g.value==1){let s;if(q.test(l.value))s="micropay";else if(R.test(l.value))s="alipayBar";else return n.value=!1,l.value="",i.value.focus(),k.error("请输入正确的支付码");a={type:s,auth_code:l.value}}else a={type:"cash_payment"};be(e,a).then(s=>{s.status==200&&(s.message=="支付成功"||s.message=="success")?(m.value=!1,k({message:s.message=="success"?"支付成功":s.message,type:"success"}),T(s.data.message||s.data.result.message),b()):(p.value=s.data.group_order_id,D.value=0,$=0,P(s.data.group_order_sn))}).catch(s=>{l.value="",n.value=!1,V(()=>{var w;(w=i.value)==null||w.focus()})})},D=r(0),P=e=>{e&&(D.value++,$+=5e3,we({order_sn:e}).then(a=>{a.data.paid==1||a.message=="支付成功"?(k({message:a.message,type:"success"}),T(a.data.message),b()):(k({message:a.message,type:"error"}),l.value="",n.value=!1,V(()=>{var s;(s=i.value)==null||s.focus()}))}).catch(a=>{I.value&&D.value<3?setTimeout(()=>{P(e)},15e3-$>0?15e3-$:0):(l.value="",n.value=!1,V(()=>{var s;(s=i.value)==null||s.focus()}))}))},b=()=>{var e;window.removeEventListener("keydown",O),I.value=!1,n.value=!1,l.value="",d.value="",f.value=[],(e=i.value)==null||e.blur(),te("paySuccess"),m.value=!1},n=r(!1);c({drawer:m,setForm:ae,setRePay:se,beforeClose:b});const f=r([]),d=r(""),B=de(()=>+d.value>0?(d.value-S.value.order_price).toFixed(2):-1),M=r(!1),N=e=>{e===-1?f.value=[]:f.value.pop(),d.value=f.value.length?f.value.join(""):0},u=e=>{M.value===!1&&(d.value="",M.value=!0);let a=String(d.value).indexOf(".")+1,s=String(d.value).length-a;console.log(a,s),(a===0||s<2)&&(f.value.join("")<=9999999&&f.value.push(e),d.value=f.value.join("")>99999999?99999999:f.value.join(""))},W=()=>{B.value===""||B.value===null||B.value===void 0||(p.value?K(p.value):X({address_id:"",key:S.value.key,cart_id:z.value,pay_type:"cash_payment",source:300}).then(e=>{if(e.status==200&&e.message=="支付成功")m.value=!1,k({message:e.message,type:"success"}),T(e.data.message),b();else if(e.data.group_order_sn)p.value=e.data.group_order_id,D.value=0,$=0,P(e.data.group_order_sn);else return p.value=e.data.result.order_id,d.value="",f.value=[],n.value=!1,k({message:e.message,type:"error"})}).catch(e=>{n.value=!1}))},O=e=>{let s=(e||window.event).keyCode;if(s==37)return x(2);if(s==120)return E.emit("F9");if(s==27)return b();switch(e.stopPropagation(),e.preventDefault(),s){case 96:case 48:u(0);break;case 97:case 49:u(1);break;case 98:case 50:u(2);break;case 99:case 51:u(3);break;case 100:case 52:u(4);break;case 101:case 53:u(5);break;case 102:case 54:u(6);break;case 103:case 55:u(7);break;case 104:case 56:u(8);break;case 105:case 57:u(9);break;case 110:u(".");break;case 190:u(".");break;case 8:N();break;case 13:W();break}},G=()=>{if(m.value&&g.value==2)return x(1)},H=()=>{if(m.value&&g.value==1)return x(2)};return ve(()=>{E.on("left",G),E.on("right",H)}),pe(()=>{E.off("left",G),E.off("right",H)}),(e,a)=>{const s=j("el-input"),w=j("el-button"),re=j("Delete"),ne=j("el-icon"),ue=j("el-drawer"),ce=fe("loading");return y(),J(ue,{size:800,modelValue:m.value,"onUpdate:modelValue":a[4]||(a[4]=_=>m.value=_),direction:"rtl",onOpen:ee,"before-close":b},{header:h(()=>[Ce]),default:h(()=>[o("div",Ae,[o("div",xe,[o("div",{class:Q(["left",{active:g.value==1}]),onClick:a[0]||(a[0]=_=>x(1))}," 微信/支付宝 ",2),o("div",{class:Q(["right",{active:g.value==2}]),onClick:a[1]||(a[1]=_=>x(2))}," 现金收款 ",2)]),Se,o("div",$e,[L(" ¥"),o("span",Le,F(S.value.order_price),1)]),g.value==1?_e((y(),C("div",Ve,[A(s,{ref_key:"codeRef",ref:i,modelValue:l.value,"onUpdate:modelValue":a[2]||(a[2]=_=>l.value=_),autofocus:"",class:"code-input",placeholder:"请点击输入框聚焦扫码或输入编码号",onKeyup:me(le,["enter"])},null,8,["modelValue"]),De])),[[ce,n.value]]):(y(),C("div",Be,[o("div",Ee,[o("div",je,[o("div",Pe,[d.value?(y(),C("span",Fe,F(d.value),1)):(y(),C("span",Te,"按下键盘输入客户支付金额"))]),B.value>=0?(y(),C("div",ze,[L(" 需找零(元):"),o("span",Ie,"¥"+F(B.value),1)])):(y(),C("div",Ne,"不够找零, 请支付更多金额")),o("div",Oe,[o("div",Ue,[(y(!0),C(ge,null,ye(oe.value,_=>(y(),J(w,{key:_,onClick:Me=>u(_)},{default:h(()=>[L(F(_),1)]),_:2},1032,["onClick"]))),128))]),o("div",qe,[A(w,{onClick:N},{default:h(()=>[A(ne,null,{default:h(()=>[A(re)]),_:1})]),_:1}),A(w,{onClick:a[3]||(a[3]=_=>N(-1))},{default:h(()=>[L("C")]),_:1}),A(w,{class:"enter",onClick:W},{default:h(()=>[L("确认")]),_:1})])])])])]))])]),footer:h(()=>[o("div",Re,[A(w,{class:"cancel-btn",onClick:Z},{default:h(()=>[L("取消收款")]),_:1})])]),_:1},8,["modelValue"])}}},aa=ie(Ke,[["__scopeId","data-v-9c62934a"]]);export{He as a,Je as b,Xe as c,Ge as d,Ye as e,ea as f,we as g,Qe as o,aa as p,Ze as v};