import{_ as _e,r as o,u as fe,D as ye,o as me,m as h,a as he,b as B,h as ge,c as v,d as Q,w as _,e as s,z as D,k as f,g,t as $,p as X,j as ke,f as k,i as Y,F as be,l as we,n as A,E as u,q as Ce,s as xe}from"./index-BVz4Ohfy.js";import{e as U,f as Ve,g as $e,h as Pe}from"./store-C3TkF7fN.js";/* empty css */const P=j=>(Ce("data-v-3ea085c1"),j=j(),xe(),j),Se=P(()=>s("h4",null,"选择支付方式",-1)),Ee={class:"dra-body"},Fe={class:"header"},ze={key:0,style:{display:"inline-block","margin-right":"20px"}},Be={style:{display:"inline-block","margin-right":"20px"}},De=P(()=>s("div",{style:{color:"#999",padding:"2rem 0 0.3rem 0"}},"原价:",-1)),je={style:{color:"#f5222d","padding-bottom":"2rem"}},Ae={style:{"font-size":"1.6rem"}},Le={style:{display:"inline-block"}},Re=P(()=>s("div",{style:{color:"#999",padding:"2rem 0 0.3rem 0"}},"活动折扣: ",-1)),Te={style:{color:"#f5222d","padding-bottom":"2rem"}},Ne={style:{"font-size":"1.6rem"}},Ue={style:{display:"inline-block"}},Ie=P(()=>s("div",{style:{color:"#999",padding:"2rem 0 0.3rem 0"}},"应收金额(元):",-1)),Oe={style:{color:"#f5222d","padding-bottom":"2rem"}},Ke={key:0,style:{"font-size":"1.6rem"}},Me={key:1,style:{"font-size":"1.6rem"}},qe={key:0,"element-loading-text":"支付中",class:"card1"},We=P(()=>s("div",{class:"tips"},null,-1)),Ge={key:1,class:"card2"},He={class:"drawer-body"},Je={class:"counter"},Qe={class:"received"},Xe={key:0},Ye={key:1,style:{"font-size":"1rem",color:"#999"}},Ze={key:0,class:"balance"},ea={class:"money"},aa=P(()=>s("div",{class:"tips"},"按回车(Enter)确认支付",-1)),sa={key:1,class:"balance"},ta=P(()=>s("div",null,"不够找零, 请支付更多金额",-1)),la=P(()=>s("div",{class:"tips"},"按下小键盘输入金额",-1)),oa=[ta,la],na={class:"keypad"},ia={class:"left"},ca={class:"right"},ua={key:2,class:"card3"},da={class:"codes"},ra={style:{width:"100%",display:"flex","justify-content":"center"}},va={__name:"pay",emits:["paySuccess"],setup(j,{expose:Z,emit:ee}){const p=o(!1),l=o(1),c=o(""),b=o("");fe(),o(0);const S=a=>{Pe({id:a}).then(e=>{h.emit("letPrintReceipt",e.data)})},ae=()=>{m()},se=()=>{A(()=>{setTimeout(()=>{var a;C.value=!1,c.value="",I.value=!0,(a=b.value)==null||a.focus(),y(l.value)},300)})},y=a=>{l.value=a,l.value==2?window.addEventListener("keydown",T):(window.removeEventListener("keydown",T),A(()=>{var e;c.value="",(e=b.value)==null||e.focus()}))},i=o({}),F=o([]),w=o(""),L=o(!1),te=a=>{i.value=a.data,F.value=a.cart_id,w.value=a.uid,console.log("选择了用户==",w.value||"游客"),L.value=a.isRePay||!1},le=a=>{i.value.pay_price=a.price,ie.value=a.order_id},oe=ee,I=o(!1),ne=o(["1","2","3","4","5","6","7","8","9","0","00","."]),O=/^(10|11|12|13|14|15)\d{16}$/,K=/^(25|26|27|28|29|30)\d{14,22}$/,ie=o(""),ce=()=>{if(C.value=!0,b.value.blur(),L.value)M();else{let a;if(O.test(c.value))a="9";else if(K.test(c.value))a="13";else return C.value=!1,c.value="",b.value.focus(),console.log("=====",22),u.error("请输入正确的支付码");U({key:i.value.key,cart_id:F.value,pay_type:a,auth_code:c.value,uid:w.value}).then(e=>{e.data.out_trade_no&&e.msg=="支付成功"?(p.value=!1,u({message:"支付成功",type:"success"}),m(e.data),S(e.data.id)):e.msg=="用户支付中"&&e.code==1&&(u.warning(e.msg),h.on("pay_success",t=>{u({message:"支付成功",type:"success"}),S(e.data.id),setTimeout(()=>{h.off("pay_success")},200),p.value=!1,m(t)}))}).catch(e=>{C.value=!1,A(()=>{var t;(t=b.value)==null||t.focus()})})}},M=()=>{let a=17;if(l.value==1)if(O.test(c.value))a="9";else if(K.test(c.value))a="13";else return C.value=!1,c.value="",b.value.focus(),u.error("请输入正确的支付码");Ve({order_id:i.value.order_id,pay_type:a,auth_code:c.value,uid:w.value}).then(e=>{var t;(t=e.msg)!=null&&t.includes("成功")?(p.value=!1,u({message:"支付成功",type:"success"}),S(e.data.id),m()):e.msg=="用户支付中"&&e.code==1&&(u.warning(e.msg),h.on("pay_success",V=>{u({message:"支付成功",type:"success"}),S(e.data.id),setTimeout(()=>{h.off("pay_success")},200),p.value=!1,m(V)}))}).catch(e=>{c.value="",C.value=!1,A(()=>{var t;(t=b.value)==null||t.focus()})})};o(0);const m=a=>{var e;try{window.removeEventListener("keydown",T),I.value=!1,C.value=!1,c.value="",d.value="",x.value=[],(e=b.value)==null||e.blur(),oe("paySuccess",a),p.value=!1}catch{}},C=o(!1);Z({drawer:p,setForm:te,setRePay:le,beforeClose:m});const x=o([]),d=o(""),z=ye(()=>+d.value>0?(+d.value-i.value.pay_price).toFixed(2):-1),q=o(!1),R=a=>{a===-1?x.value=[]:x.value.pop(),d.value=x.value.length?x.value.join(""):0},r=a=>{q.value===!1&&(d.value="",q.value=!0);let e=String(d.value).indexOf(".")+1,t=String(d.value).length-e;console.log(e,t),(e===0||t<2)&&(x.value.join("")<=9999999&&x.value.push(a),d.value=x.value.join("")>99999999?99999999:x.value.join(""))},W=()=>{if(z.value===""||z.value===null||z.value===void 0||+d.value<+i.value.pay_price)return u.error("收款金额应该大于等于应收金额");L.value?M():U({cart_id:F.value,pay_type:"17",uid:w.value}).then(a=>{p.value=!1,u({message:a.msg,type:"success"}),S(a.data.id),y(1),m()}).catch(a=>{C.value=!1})},T=a=>{let t=(a||window.event).keyCode;if(t==37)return y(2);if(t==120)return h.emit("F9");if(t==27)return m();switch(a.stopPropagation(),a.preventDefault(),t){case 96:case 48:r(0);break;case 97:case 49:r(1);break;case 98:case 50:r(2);break;case 99:case 51:r(3);break;case 100:case 52:r(4);break;case 101:case 53:r(5);break;case 102:case 54:r(6);break;case 103:case 55:r(7);break;case 104:case 56:r(8);break;case 105:case 57:r(9);break;case 110:r(".");break;case 190:r(".");break;case 8:R();break;case 13:W();break}},ue=()=>{if(!w.value)return u.error("请先选择用户");let a=1;l.value==4&&(a=2),$e({cart_id:F.value,uid:w.value,type:a}).then(e=>{u({message:"发送成功",type:"success"})})},N=o(""),G=()=>{if(!w.value)return u.error("请先选择用户");let a=18;l.value==4&&(a=19),U({pay_type:a,sms_code:N.value,cart_id:F.value,uid:w.value}).then(e=>{p.value=!1,u({message:e.msg,type:"success"}),S(e.data.id),y(1),m()})},E=o(!1),H=()=>{if(!(!p.value||E.value&&c.value.length>0)&&l.value!=1)return y(l.value-1)},J=()=>{if(!(!p.value||E.value&&c.value.length>0)&&l.value!=4)return y(l.value+1)};return me(()=>{h.on("left",H),h.on("right",J)}),he(()=>{h.off("left",H),h.off("right",J)}),(a,e)=>{const t=B("el-input"),V=B("el-button"),de=B("Delete"),re=B("el-icon"),ve=B("el-drawer"),pe=ge("loading");return v(),Q(ve,{size:"60rem",modelValue:p.value,"onUpdate:modelValue":e[11]||(e[11]=n=>p.value=n),direction:"rtl",onOpen:se,"before-close":m},{header:_(()=>[Se]),default:_(()=>[s("div",Ee,[s("div",Fe,[s("div",{class:D(["left",{active:l.value==1}]),onClick:e[0]||(e[0]=n=>y(1))}," 微信/支付宝 ",2),s("div",{class:D(["center",{active:l.value==2}]),onClick:e[1]||(e[1]=n=>y(2))}," 现金收款 ",2),s("div",{class:D(["center",{active:l.value==3}]),style:{"border-left":"none"},onClick:e[2]||(e[2]=n=>y(3))}," 采购款 ",2),s("div",{class:D(["right",{active:l.value==4}]),onClick:e[3]||(e[3]=n=>y(4))}," 礼品券兑换 ",2)]),s("div",null,[i.value.activities==1&&l.value!=4?(v(),f("div",ze,[s("div",Be,[De,s("div",je,[g(" ¥"),s("span",Ae,$(i.value.original_price),1)])]),s("div",Le,[Re,s("div",Te,[g($(i.value.activity)+"¥",1),s("span",Ne,$(i.value.activity_price),1)])])])):X("",!0),s("div",Ue,[Ie,s("div",Oe,[g(" ¥"),l.value==2&&i.value.activities==1?(v(),f("span",Ke,$(Math.ceil(i.value.original_price-i.value.activity_price).toFixed(2)),1)):(v(),f("span",Me,$(l.value==4?i.value.original_price:i.value.pay_price),1))])])]),l.value==1?ke((v(),f("div",qe,[k(t,{ref_key:"codeRef",ref:b,modelValue:c.value,"onUpdate:modelValue":e[4]||(e[4]=n=>c.value=n),autofocus:"",class:"code-input",placeholder:"请点击输入框聚焦扫码或输入编码号",onKeyup:Y(ce,["enter"]),onFocus:e[5]||(e[5]=n=>E.value=!0),onBlur:e[6]||(e[6]=n=>E.value=!1)},null,8,["modelValue"]),We])),[[pe,C.value]]):l.value==2?(v(),f("div",Ge,[s("div",He,[s("div",Je,[s("div",Qe,[d.value?(v(),f("span",Xe,$(d.value),1)):(v(),f("span",Ye,"按下键盘输入客户支付金额"))]),z.value>=0?(v(),f("div",Ze,[s("div",null,[g(" 需找零(元):"),s("span",ea,"¥"+$(z.value),1)]),aa])):(v(),f("div",sa,oa)),s("div",na,[s("div",ia,[(v(!0),f(be,null,we(ne.value,n=>(v(),Q(V,{key:n,onClick:pa=>r(n)},{default:_(()=>[g($(n),1)]),_:2},1032,["onClick"]))),128))]),s("div",ca,[k(V,{onClick:R},{default:_(()=>[k(re,null,{default:_(()=>[k(de)]),_:1})]),_:1}),k(V,{onClick:e[7]||(e[7]=n=>R(-1))},{default:_(()=>[g("C")]),_:1}),k(V,{class:D(["enter",{"enter-disable":+d.value<+i.value.pay_price}]),disabled:+d.value<+i.value.pay_price,onClick:W},{default:_(()=>[g(" 确认 ")]),_:1},8,["class","disabled"])])])])])])):l.value==3||l.value==4?(v(),f("div",ua,[s("div",da,[k(t,{modelValue:N.value,"onUpdate:modelValue":e[8]||(e[8]=n=>N.value=n),autofocus:"",class:"code-input",placeholder:"请输入验证码",onKeyup:Y(G,["enter"]),onFocus:e[9]||(e[9]=n=>E.value=!0),onBlur:e[10]||(e[10]=n=>E.value=!1)},null,8,["modelValue"]),k(V,{type:"primary",onClick:ue,class:"get-code-btn"},{default:_(()=>[g("获取验证码")]),_:1})]),k(V,{type:"primary",onClick:G,class:"code-pay"},{default:_(()=>[g("确认支付")]),_:1})])):X("",!0)])]),footer:_(()=>[s("div",ra,[k(V,{class:"cancel-btn",onClick:ae},{default:_(()=>[g("取消收款")]),_:1})])]),_:1},8,["modelValue"])}}},ma=_e(va,[["__scopeId","data-v-3ea085c1"]]);export{ma as p};