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