jm-expense-vue-ts/assets/Record.c7e780f9.js

36 lines
8.0 KiB
JavaScript
Raw Permalink Normal View History

2022-04-24 05:11:48 +00:00
import{r as h}from"./record.727acb18.js";import{g as S}from"./dateFormat.a9df66b7.js";import{_ as y,c as b,d as R,T as _}from"./index.6b72a0c0.js";import{S as I}from"./Spinner.9807c4e4.js";import{p as E,_ as U}from"./CreateRecordModalButton.aa1ff3c2.js";import{e as D,i as k,o as r,g as m,S as N,F as B,j as x,h as o,t as v,x as C,C as M,k as L,n as j,p as F,m as $,P as T,A as O,B as P}from"./vendor.961f4417.js";const z=D({props:{record:null},setup(d){const p=d,n=b(),a=k("refetchRecords"),u=async()=>{try{const e=p.record,{value:l}=await R.fire({title:"\u8CC7\u6599\u7DE8\u8F2F",html:`
2022-04-16 13:28:48 +00:00
<div class="d-flex mb-2">
<div class="col-auto me-3">
<label for="swal-item" class="col-form-label">\u9805\u76EE</label>
</div>
<div class="col-auto">
<input value="${e.item}" type="text" id="swal-item" class="form-control"/>
</div>
</div>
<div class="d-flex mb-2">
<div class="col-auto me-3">
<label for="swal-merchant" class="col-form-label">\u5546\u5BB6</label>
</div>
<div class="col-auto">
<input value="${e.merchant}" type="text" id="swal-merchant" class="form-control" >
</div>
</div>
<div class="d-flex mb-2">
<div class="col-auto me-3">
<label for="swal-amount" class="col-form-label">\u91D1\u984D</label>
</div>
<div class="col-auto">
<input value="${e.amount}" type="number" id="swal-amount" class="form-control" >
</div>
</div>
<div class="d-flex mb-2">
<div class="col-auto me-3">
<label for="swal-date" class="col-form-label">\u65E5\u671F</label>
</div>
<div class="col-auto">
<input value="${new Date(e.date).toISOString().substring(0,10)}" type="date" id="swal-date" class="form-control" >
</div>
</div>
`,preConfirm:()=>{const t=document.getElementById("swal-item").value,c=document.getElementById("swal-merchant").value,s=document.getElementById("swal-amount").value,f=new Date(document.getElementById("swal-date").value);if((!t||!c||!s||!f)&&N.showValidationMessage("\u6240\u6709\u8CC7\u6599\u90FD\u662F\u5FC5\u586B\uFF01\u82E5\u7DE8\u8F2F\u8005\u70BA\u7A7A\uFF0C\u8ACB\u767B\u5165~"),n.currentUser)return{id:e.id,input:{item:t,merchant:c,amount:s,date:f,UserId:n.currentUser.id}};_.fire({icon:"error",title:"\u7121\u6CD5\u53D6\u5F97\u4F7F\u7528\u8005ID"})}});l!=null&&l.input&&i(l)}catch(e){console.error("error",e)}},i=async function(e){try{await h.edit(e.id,e.input),a(),_.fire({icon:"success",title:"\u6210\u529F\u7DE8\u8F2F\u8CC7\u6599\uFF01"}),E(`${n.nickName}${n.icon}\u7DE8\u8F2F\u4E86\u4E00\u7B46\u7D00\u9304 \u2192
${e.input.merchant}-${e.input.item} $${e.input.amount}`)}catch(l){console.error("error",l),_.fire({icon:"error",title:"\u7DE8\u8F2F\u8CC7\u6599\u5931\u6557\uFF01"})}};return(e,l)=>(r(),m("i",{class:"fas fa-edit",onClick:u}))}});var q=y(z,[["__scopeId","data-v-34229604"]]);const G={class:"d-flex mb-3",style:{width:"100vw"}},H={class:"btn btn-info fw-bold"},J=D({props:{propData:null},emits:["closeFunction"],setup(d,{emit:p}){const n=d,a=b(),u=k("refetchRecords"),i=async()=>{var t;const{isConfirmed:l}=await R.fire({icon:"info",title:"\u78BA\u5B9A\u7D50\u7B97\u8CC7\u6599\uFF1F",text:`\u7D50\u7B97\u91D1\u984D\u70BA $${n.propData.closeRecordsAmount} [\u7D50\u7B97\u8005: ${(t=a.currentUser)==null?void 0:t.displayName}]`});l&&e(n.propData.closeRecordsAmount)},e=async l=>{var t;try{if(a.currentUser){const{data:c}=await h.close({records:n.propData.closeRecords.toString(),totalAmount:l,UserId:(t=a.currentUser)==null?void 0:t.id});p("closeFunction","closeRecord"),u(),c.data.recordsNotFound.length||c.data.recordsClosedBefore.length?_.fire({icon:"success",title:"\u6210\u529F\u7D50\u7B97\u8CC7\u6599\uFF01\u6709\u90E8\u5206\u8CC7\u6599\u672A\u80FD\u627E\u5230\u6216\u662F\u5DF2\u7D93\u7D50\u7B97\u904E\u3002"}):_.fire({icon:"success",title:"\u6210\u529F\u7D50\u7B97\u8CC7\u6599\uFF01"}),E(`${a.nickName}${a.icon}\u7D50\u7B97\u7D00\u9304 \u2192 \u7E3D\u91D1\u984D $${l}`)}}catch(c){console.error("error",c),_.fire({icon:"error",title:"\u7D50\u7B97\u8CC7\u6599\u5931\u6557\uFF01"})}};return(l,t)=>(r(),m("div",G,[d.propData.isCloseStatus?(r(),m(B,{key:1},[o("div",H,"\u7D50\u7B97\u91D1\u984D $"+v(d.propData.closeRecordsAmount),1),o("button",{type:"button",class:"btn btn-secondary ms-3",onClick:t[1]||(t[1]=c=>p("closeFunction","cancelBtnClick"))}," \u53D6\u6D88\u7D50\u7B97 "),o("button",{type:"button",class:"btn btn-success ms-3",onClick:i},"\u78BA\u5B9A\u7D50\u7B97")],64)):(r(),m(B,{key:0},[x(U,{view:"Record",class:"me-3"}),o("button",{type:"button",class:"btn btn-danger",onClick:t[0]||(t[0]=c=>p("closeFunction","closeBtnClick"))},"\u958B\u59CB\u7D50\u7B97")],64))]))}});const K=D({props:{record:null},setup(d){const p=d,n=k("refetchRecords"),a=async()=>{try{const{isConfirmed:i}=await R.fire({title:`\u78BA\u5B9A\u522A\u9664\u7D00\u9304[${p.record.item}]\u561B\uFF1F`,showCancelButton:!0});i&&u(p.record.id)}catch(i){console.error("error",i)}},u=async function(i){try{const{data:e}=await h.delete(i);if(e.status!=="success")throw new Error(`[SERVER ERROR] ${e.message}`);n(),_.fire({icon:"success",title:`\u6210\u529F\u522A\u9664\u7D00\u9304[${e.data.item}]`})}catch(e){console.error("error",e),_.fire({icon:"error",title:"\u522A\u9664\u7D00\u9304\u5931\u6557\uFF01"})}};return(i,e)=>(r(),m("i",{class:"fas fa-trash",onClick:a}))}});var Q=y(K,[["__scopeId","data-v-841b8e8a"]]);const V=d=>(O("data-v-072f01d7"),d=d(),P(),d),W={key:0},X={key:0,class:"table table-info table-hover"},Y=V(()=>o("thead",null,[o("tr",null,[o("th",{scope:"col"},"#"),o("th",{scope:"col"}),o("th",{scope:"col"},"\u9805\u76EE"),o("th",{scope:"col"},"\u5546\u5BB6"),o("th",{scope:"col"},"\u91D1\u984D"),o("th",{scope:"col"},"\u65E5\u671F"),o("th",{scope:"col",id:"column-item"},"\u9996\u6B21\u8A18\u9304\u8005"),o("th",{scope:"col",id:"column-item"},"\u9996\u6B21\u8A18\u9304\u6642\u9593"),o("th",{scope:"col",id:"column-item"},"\u66F4\u65B0\u6642\u9593")])],-1)),Z=["onClick"],ee=["checked"],te={id:"column-item"},oe={id:"column-item"},se={id:"column-item"},ue={key:1,class:"img-fluid",src:"https://memeprod.sgp1.digitaloceanspaces.com/user-wtf/1581909112681.jpg",alt:""},ce=D({setup(d){const p=b(),n=C(!0),a=C([]),u=C({isCloseStatus:!1,closeRecords:[],closeRecordsAmount:0}),i=async function(){try{const{data:t}=await h.getAll();a.value=t.data.filter(c=>c.isClosed===!1),n.value=!1}catch(t){console.error("error",t)}},e=(t,c)=>{if(console.log("checkboxClick"),u.value.isCloseStatus){const s=u.value.closeRecords.findIndex(f=>f===t);s!==void 0&&(s!==-1?(u.value.closeRecords.splice(s,1),u.value.closeRecordsAmount-=c):(u.value.closeRecords.push(t),u.value.closeRecordsAmount+=c))}},l=t=>{if(t==="cancelBtnClick