Browse Source

原始百分数做小数进位的处理

Karsa 1 year ago
parent
commit
29a98ab071

+ 2 - 2
src/utils/calculate.js

@@ -21,9 +21,9 @@ function multiply(a, b) {
 
 // 除法
 function divide(a, b) {
-  const precision = getPrecision(b) - getPrecision(a);
+  const precision = Math.max(getPrecision(b), getPrecision(a));
   const divisor = Math.pow(10, precision);
-  return Math.round((a / b) * divisor) / divisor;
+  return (a * divisor) / (b * divisor);
 }
 
 // 获取浮点数的精度

+ 18 - 8
src/views/datasheet_manage/common/customTable.js

@@ -280,8 +280,11 @@ export function transDecimalPlace(str,{pn,nt}) {
   //是否是原数字后设置百分比的
   let transPercent = (nt==='percent'&&!str.endsWith('%')) ? true : false;
 
+  //原百分比设置为数字的
+  let transDecimal = (nt==='number'&&str.endsWith('%')) ? true : false
+
   //后缀 百分号
-  let suffix = (str.endsWith('%')||transPercent) ? '%' : '';
+  let suffix = ((str.endsWith('%')&&nt!=='number')||transPercent) ? '%' : '';
 
   let num = parseFloat(s);
 
@@ -292,28 +295,35 @@ export function transDecimalPlace(str,{pn,nt}) {
         : `${multiply(num,100)}${suffix}`;
     }
 
+    if(transDecimal) {
+      return decimalNum > 0 
+        ? `${divide(num,100)}${'0'.repeat(decimalNum)}`
+        : `${divide(num,100)}`;
+    }
+
     // 补零
     return decimalNum > 0 
       ? `${s}.${'0'.repeat(decimalNum)}${suffix}`
       : `${s}${suffix}`;
   }
 
-  // let integerStr = str.split('.')[0],
-  // decimalStr = str.split('.')[1];
-
   if(decimalNum > 0) {
     let addPointStr = `${s}${'0'.repeat(decimalNum)}`;
     
     return transPercent 
       ? `${parseFloat(multiply(num,100)).toFixed(decimalPlaces+decimalNum-2)}${suffix}`
-      : `${addPointStr}${suffix}`
+      : transDecimal
+        ? `${parseFloat(divide(num,100)).toFixed(decimalPlaces+decimalNum+2)}`
+        : `${addPointStr}${suffix}`
   }else {
     let maxDecimal = Math.max(0,decimalNum+decimalPlaces);
     let maxDecimalPercent = Math.max(0,maxDecimal-2);
 
     return transPercent 
-    ? `${parseFloat(multiply(num,100)).toFixed(maxDecimalPercent)}${suffix}`
-    : `${parseFloat(num.toFixed(maxDecimal))}${suffix}`
+      ? `${parseFloat(multiply(num,100)).toFixed(maxDecimalPercent)}${suffix}`
+      : transDecimal
+        ? `${parseFloat(divide(num,100)).toFixed(maxDecimal+2)}`
+        : `${parseFloat(num.toFixed(maxDecimal))}${suffix}`
   }
 }
 
@@ -353,6 +363,6 @@ export function transNumPercentType(str,type) {
     const percenStr = parseFloat(multiply(num,100)) + '%';
     return percenStr;
   }else {
-    return parseFloat(num/100);
+    return parseFloat(divide(num,100));
   }
 }

+ 3 - 4
src/views/datasheet_manage/components/MixedTable.vue

@@ -393,10 +393,10 @@ export default {
       }
 
       //选择指标弹窗打开时选择日期更新弹窗数据
-      // this.isSelectTargetValueDialog&&this.$refs.selectTargetValueRef.changeDateType(this.selectCell)
+      this.isSelectTargetValueDialog&&this.$refs.selectTargetValueRef.changeRleationDate(this.selectCell)
 
       //计算指标弹窗打开时选择日期更新弹窗数据
-      // this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.showResult&&this.$refs.calculateEdbDiaRef.calculateHandle()
+      this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.changeRleationDate(this.selectCell)
 
       //日期计算弹窗打开选中日期框时且有选中item时更新选中值
       cell.DataType===1&&this.isInsertCalculateDate&&this.$refs.calculateDateDiaRef.selectIndex&&this.$refs.calculateDateDiaRef.setSelectItemValue(this.selectCell)
@@ -1181,7 +1181,6 @@ export default {
       
       this.$set(this.selectCell,'ShowStyle',ShowStyle)
       this.$set(this.selectCell,'ShowFormatValue',ShowFormatValue)
-      console.log(this.selectCell)
     }
   },
 };
@@ -1344,7 +1343,7 @@ export default {
       background: #fff;
       position: absolute;
       right: -178px;
-      top:-210px;
+      top:-205px;
       max-height: 400px;
       overflow-y: auto;
     }

+ 6 - 1
src/views/datasheet_manage/components/calculateEdbDia.vue

@@ -185,7 +185,7 @@
               </div>
               <div class="flex">
                 <el-radio v-model="dateSelectForm.Type" :label="2" style="margin-left:50px">表格日期</el-radio>
-                <span v-if="dateSelectForm.relationDate">{{dateSelectForm.relationDate}}</span>
+                <span v-if="dateSelectForm.relationDate&&dateSelectForm.Type===2">{{dateSelectForm.relationDate}}</span>
 
               </div>
             </li>
@@ -360,6 +360,11 @@ export default {
         this.edbArrFromTable = res.Data.List;
     },
 
+    // 在选择表格中日期的话在弹窗中显示所选日期 无实际作用 显示用一下
+    changeRleationDate(cell) {
+      this.dateSelectForm.relationDate=cell.DataType===1?cell.ShowValue:'';
+    },
+
     /* 计算结果 */
     async calculateHandle() {
       await this.$refs.form.validate();

+ 5 - 8
src/views/datasheet_manage/components/selectTargetValueDia.vue

@@ -44,7 +44,7 @@
           </div>
           <div class="flex">
             <el-radio v-model="dateSelectForm.Type" :label="2" style="margin-left:50px">表格日期</el-radio>
-            <span v-if="dateSelectForm.relationDate">{{dateSelectForm.relationDate}}</span>
+            <span v-if="dateSelectForm.relationDate&&dateSelectForm.Type===2">{{dateSelectForm.relationDate}}</span>
 
           </div>
         </li>
@@ -126,13 +126,10 @@ export default {
       this.edbInfo = edb;
     },
 
-    // 切换日期依赖类型,在选择表格中日期的话默认切换到表格日期 在弹窗中手动切换类型不做处理
-    // changeDateType(cell) {
-    //   //根据表格中点选的是否是日期来勾选类型
-    //   this.dateSelectForm.Type=cell.DataType === 1?2:1;
-    //   this.dateSelectForm.relationDate=cell.DataType === 1?'':cell.ShowValue;
-    //   // this.chooseEdb(this.edbInfo);
-    // },
+    // 在选择表格中日期的话在弹窗中显示所选日期 无实际作用 显示用一下
+    changeRleationDate(cell) {
+      this.dateSelectForm.relationDate=cell.DataType===1?cell.ShowValue:'';
+    },
 
     /* 获取指标信息回显 */
     async getEdbInfo(EdbInfoId) {