ll-package
Version:
2 lines (1 loc) • 3.19 kB
JavaScript
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),k=require("../../../hooks/uselocale.js"),B=require("../../../hooks/useDesign.js"),s=require("../../../utils/commonLib.js");require("../../../../node_modules/ant-design-vue/es/form/index.js");const x=require("../../../../node_modules/ant-design-vue/es/form/Form.js"),D=require("../../../../node_modules/@vueuse/shared/index.js"),V={key:1},_={key:2,class:"amount-chinese-name"},w=e.defineComponent({name:"LlCalculate"}),F=e.defineComponent({...w,props:{value:{},formData:{},expression:{},tableVModel:{},componentVModel:{},isStorage:{default:0},rowIndex:{},detailed:{type:Boolean,default:!1},isAmountChinese:{type:Boolean,default:!1},thousands:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},precision:{}},emits:["update:value","change"],setup(v,{emit:g}){const{t:i}=k.useLocale(),o=v,c=g,{prefixCls:h}=B.useDesign("calculate"),t=e.ref(""),d=e.ref(null),m=x.default.useInjectFormItemContext(),b=e.computed(()=>s.toRPN(s.mergeNumberOfExps(o.expression))),p=e.computed(()=>!o.isAmountChinese||!t.value&&t.value!==0?"":s.getAmountChinese(t.value)),r=e.computed(()=>o.thousands?s.thousandsFormat(t.value):t.value);e.watch(()=>o.formData,l=>{l&&(d.value||(d.value=D.useDebounceFn(C,100)),e.unref(d)())},{immediate:!0,deep:!0}),e.watch(()=>o.value,l=>{t.value=l},{immediate:!0});function y(l){try{if(l.indexOf(".")>-1){let[a,n]=l.split(".");return typeof o.rowIndex=="number"?!Array.isArray(o.formData[a])||o.formData[a].length<o.rowIndex+1?0:o.formData[a][o.rowIndex][n]||0:o.formData[a].length?o.formData[a].reduce((u,f)=>(f[n]?Number(f[n]):0)+u,0):0}return o.formData[l]||0}catch(a){return console.warn(i("component.LlCalculate.warning"),a),0}}function C(){const l=e.unref(b).map(a=>typeof a=="object"?y(a.__vModel__):a);t.value=Number.parseFloat(s.calcRPN(l)),isNaN(t.value)&&(t.value=0),t.value=Number.parseFloat(t.value.toFixed(o.precision||0)),o.rowIndex>=0&&o.componentVModel&&o.tableVModel?o.formData[o.tableVModel][o.rowIndex]&&o.formData[o.tableVModel][o.rowIndex][o.componentVModel]!==t.value&&o.isStorage&&(c("update:value",t.value),c("change",t.value),m.onFieldChange()):o.isStorage&&(c("update:value",t.value),m.onFieldChange())}return(l,a)=>{const n=e.resolveComponent("ll-input");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(`${e.unref(h)}`)},[l.detailed?(e.openBlock(),e.createElementBlock("p",V,e.toDisplayString(r.value),1)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[l.isStorage?(e.openBlock(),e.createBlock(n,{key:0,value:r.value,"onUpdate:value":a[0]||(a[0]=u=>r.value=u),readonly:"",disabled:l.disabled,placeholder:e.unref(i)("LlCalculate.isStorageplaceholder")},null,8,["value","disabled","placeholder"])):(e.openBlock(),e.createBlock(n,{key:1,value:r.value,"onUpdate:value":a[1]||(a[1]=u=>r.value=u),readonly:"",disabled:l.disabled,placeholder:e.unref(i)("LlCalculate.otherPlaceholder")},null,8,["value","disabled","placeholder"]))],64)),l.isAmountChinese&&p.value?(e.openBlock(),e.createElementBlock("p",_,e.toDisplayString(p.value),1)):e.createCommentVNode("",!0)],2)}}});exports.default=F;
;