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