Explorar o código

项目金额,报销金额,都从整数改成小数点后两位

seyason %!s(int64=3) %!d(string=hai) anos
pai
achega
6835fbefd5

+ 14 - 4
fhKeeper/formulahousekeeper/timesheet/src/views/expense/expense.vue

@@ -138,7 +138,7 @@
             </el-table-column>
             <el-table-column label="费用金额" width="135px">
               <template slot-scope="scope">
-                <el-input size="small"  v-model="scope.row.amount" @change="shiqu(scope.row.amount)"></el-input>
+                <el-input size="small" :id="'upam'+scope.$index" v-model="scope.row.amount" @change="shiqu(scope.row.amount)" @keyup.native="restrictNumber('upam'+scope.$index)"></el-input>
               </template>
             </el-table-column>
             <el-table-column prop="invoiceNo" label="发票号" width="135px">
@@ -318,7 +318,7 @@
             </el-table-column>
             <el-table-column prop="amount" label="费用金额(元)" width="172">
               <template slot-scope="scope">
-                <el-input size="small"  v-if="!flg" v-model="scope.row.amount" @change="kan"></el-input>
+                <el-input size="small"  v-if="!flg" :id="'am'+scope.$index" v-model="scope.row.amount" @change="kan" @keyup.native="restrictNumber('am'+scope.$index)"></el-input>
                 <span v-else>¥{{scope.row.amount}}</span>
               </template>
             </el-table-column>
@@ -447,6 +447,16 @@ export default {
       }
   },
   methods: {
+    restrictNumber(targetId) {
+        let inpu = document.getElementById(targetId);
+        inpu.value = inpu.value.replace(/[^\d.]/g, "");  //仅保留数字和"."
+        inpu.value = inpu.value.replace(/\.{2,}/g, "."); //两个连续的"."仅保留第一个"."
+        inpu.value = inpu.value.replace(".", "$#*").replace(/\./g,'').replace('$#*','.');//去除其他"."
+        inpu.value = inpu.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');;//限制只能输入两个小数
+        if (inpu.value.indexOf(".") < 0 && inpu.value != "") { //首位是0的话去掉
+            inpu.value = parseFloat(inpu.value);
+        }
+    },
     getExpList() {
       this.http.post('/expense-type/getList', {
         },
@@ -790,12 +800,12 @@ export default {
     // 费用金额失去焦点时触发
     shiqu(){
       this.addForm.totalAmount = this.invoiceList.reduce((prev, next) => {
-        return prev + Number(next.amount);
+        return prev + parseFloat(next.amount);
       }, 0)
     },
     kan(){
       this.ParticularsList.totalAmount = this.ParticularsList.invoiceList.reduce((prev, next) => {
-        return prev + Number(next.amount)
+        return prev + parseFloat(next.amount)
       }, 0)
     }
   },

+ 14 - 4
fhKeeper/formulahousekeeper/timesheet/src/views/team/index.vue

@@ -141,12 +141,12 @@
                     </el-radio-group>
                 </el-form-item>
                 <el-form-item label="月成本" prop="monthCost" v-if="insertForm.salaryType == 0">
-                    <el-input v-model.number="insertForm.monthCost" @input="oninput" placeholder="请输入月成本,单位:元" clearable></el-input>
+                    <el-input v-model="insertForm.monthCost" id="mc" @input="oninput" placeholder="请输入月成本,单位:元" clearable @keyup.native="restrictNumber('mc')"></el-input>
                     <span style="color:orange;font-size:12px;">按照每个月工作{{timeType.monthDays}}天,每天{{timeType.allday}}小时预估时薪</span>
                     <el-link :underline="false" style="color:blue;font-size:12px;margin-left:7px;" href="#/timetype">修改工作时长</el-link>
                 </el-form-item>
                 <el-form-item label="时薪" prop="cost">
-                    <el-input v-model.number="insertForm.cost" :disabled="insertForm.salaryType == 0" style="width:120px;"
+                    <el-input v-model="insertForm.cost" :disabled="insertForm.salaryType == 0" id="cc" style="width:120px;" @keyup.native="restrictNumber('cc')"
                      placeholder="请输入成本 单位:元/小时" clearable></el-input>
                     <span style="margin-left:25px;">生效日期</span>
                     <el-date-picker v-model="insertForm.costApplyDate" value-format="yyyy-MM-dd"></el-date-picker>
@@ -190,12 +190,12 @@
                     </el-radio-group>
                 </el-form-item>
                 <el-form-item label="月成本" prop="monthCost" v-if="insertForm.salaryType == 0">
-                    <el-input v-model.number="insertForm.monthCost" @input="oninput" placeholder="请输入月成本,单位:元" clearable></el-input>
+                    <el-input v-model="insertForm.monthCost" id="monthCost" @input="oninput" @keyup.native="restrictNumber('monthCost')" placeholder="请输入月成本,单位:元" clearable></el-input>
                     <span style="color:orange;font-size:12px;">按照每个月工作{{timeType.monthDays}}天,每天{{timeType.allday}}小时预估时薪</span>
                     <el-link :underline="false" style="color:blue;font-size:12px;margin-left:7px;" href="#/timetype">修改工作时长</el-link>
                 </el-form-item>
                 <el-form-item label="时薪" prop="cost">
-                    <el-input v-model.number="insertForm.cost" :disabled="insertForm.salaryType == 0" style="width:120px;"
+                    <el-input v-model="insertForm.cost" id="cost" :disabled="insertForm.salaryType == 0" @keyup.native="restrictNumber('cost')" style="width:120px;"
                      placeholder="请输入成本 单位:元/小时" clearable></el-input>
                     <span style="margin-left:25px;">生效日期</span>
                     <el-date-picker v-model="insertForm.costApplyDate"  value-format="yyyy-MM-dd"></el-date-picker>
@@ -368,6 +368,16 @@
             };
         },
         methods: {
+            restrictNumber(targetId) {
+                let inpu = document.getElementById(targetId);
+                inpu.value = inpu.value.replace(/[^\d.]/g, "");  //仅保留数字和"."
+                inpu.value = inpu.value.replace(/\.{2,}/g, "."); //两个连续的"."仅保留第一个"."
+                inpu.value = inpu.value.replace(".", "$#*").replace(/\./g,'').replace('$#*','.');//去除其他"."
+                inpu.value = inpu.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');;//限制只能输入两个小数
+                if (inpu.value.indexOf(".") < 0 && inpu.value != "") { //首位是0的话去掉
+                    inpu.value = parseFloat(inpu.value);
+                }
+            },
             showConfirmDialog() {
                 if (this.toUserId == null || this.toUserId == '') {
                     this.$message({