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