소스 검색

Merge branch 'feature/合同' into develop

liuzl 3 년 전
부모
커밋
769c0b9ca4
2개의 변경된 파일99개의 추가작업 그리고 68개의 파일을 삭제
  1. 85 0
      src/components/amountInput/index.vue
  2. 14 68
      src/views/contract/components/ProductTable.vue

+ 85 - 0
src/components/amountInput/index.vue

@@ -0,0 +1,85 @@
+<!--
+ * @Author: liuzhenlin 461480418@qq.ocm
+ * @Date: 2023-01-10 16:18:28
+ * @LastEditors: liuzhenlin
+ * @LastEditTime: 2023-01-10 17:49:42
+ * @Description: file content
+ * @FilePath: \订单全流程管理系统\src\components\amountInput\index.vue
+-->
+<template>
+  <div>
+    <el-input
+      v-bind="$attrs"
+      v-model.trim="num"
+      oninput="value=value.replace(/[^0-9.]/g,'')"
+      @blur="inputMoney($event)"
+      @change="handleChange"
+      @focus="uninputMoney($event)"
+      @input="returnNum" />
+  </div>
+</template>
+
+<script>
+  export default {
+    name: 'AmountInput',
+    props: {
+      value: {
+        type: [String, Number],
+        default: '',
+      },
+    },
+    data() {
+      return {
+        num: '',
+      }
+    },
+    watch: {
+      value(val) {
+        console.log(this.value)
+        this.num = this.formatPrice(val)
+      },
+    },
+
+    mounted() {
+      console.log(this.value)
+      this.num = this.formatPrice(this.value)
+    },
+
+    methods: {
+      returnNum() {
+        this.$emit('input', this.num)
+      },
+      handleChange(val) {
+        console.log('val', val)
+        this.$nextTick(() => {
+          this.$emit('change', this.delcommafy(val))
+        })
+      },
+      // 失焦显示数字类型
+      inputMoney(el) {
+        let temp = Number(el.target.value) || null
+        this.num = this.formatPrice(temp)
+      },
+      // 获得焦点金额去掉格式
+      uninputMoney(el) {
+        console.log('el', el.target.value)
+        if (el.target.value) {
+          this.num = this.delcommafy(el.target.value)
+        } else {
+          this.num = null
+        }
+        this.$emit('input', this.num)
+      },
+      //去除千分位中的‘,’
+      delcommafy(num) {
+        if (!num) return num
+        num = num.toString()
+        num = num.substring(1).replace(/,/gi, '')
+        if (num.indexOf('.00') > 0) num = parseInt(num)
+        return num
+      },
+    },
+  }
+</script>
+
+<style lang="scss" scoped></style>

+ 14 - 68
src/views/contract/components/ProductTable.vue

@@ -18,14 +18,11 @@
         show-overflow-tooltip>
         <template #default="{ row }">
           <span v-if="item.prop == 'price'">
-            <el-input
+            <amount-input
               v-model.trim="row.price"
               placeholder="请输入金额"
-              @blur="inputMoney($event, row, 'price')"
-              @change="handleChange(row)"
-              @focus="uninputMoney($event, row, 'price')">
-              <!-- <template slot="append">元</template> -->
-            </el-input>
+              :value="row.price"
+              @change="handleChange(row)" />
           </span>
           <span v-else-if="item.prop == 'count'">
             <el-input-number v-model="row.count" :min="0" size="mini" @change="handleChange(row)" />
@@ -46,12 +43,12 @@
 </template>
 
 <script>
-  // import AmountInput from '@/components/AmountInput'
+  import AmountInput from '@/components/amountInput'
 
   export default {
     name: 'ProductTable',
     components: {
-      // AmountInput,
+      AmountInput,
     },
     props: {
       productData: {
@@ -107,81 +104,30 @@
       productData() {
         this.data = []
         this.data = this.productData.map((item) => {
-          return { ...item, price: this.setPriceFormat(item['price']) }
+          return { ...item, price: item['price'] }
         })
       },
     },
     created() {
       this.data = []
       this.data = this.productData.map((item) => {
-        return { ...item, price: this.setPriceFormat(item['price']) }
+        return { ...item, price: item['price'] }
       })
     },
     methods: {
       // input修改
-      handleChange(item) {
-        this.$emit('changeProductData', item)
+      handleChange(row) {
+        console.log('row', row)
+        this.$emit('changeProductData', row)
       },
       // 删除
-      handleDel(item) {
-        this.$emit('delProductData', item)
-      },
-      // 失焦显示数字类型
-      inputMoney(el, row, key) {
-        let temp = Number(el.target.value) || null
-        row[key] = this.priceFormat(temp)
-      },
-      // 获得焦点金额去掉格式
-      uninputMoney(el, row, key) {
-        if (el.target.value) {
-          row[key] = this.delcommafy(el.target.value)
-        } else {
-          row[key] = null
-        }
-      },
-      setPriceFormat(num) {
-        if (!num) {
-          return (num = 0)
-        } else if (typeof num == 'number') {
-          return this.priceFormat(num)
-        } else {
-          return num
-        }
-      },
-      // 金额格式化
-      priceFormat(num, n) {
-        n = n || 2
-        let symbol = ','
-        if (num === null) return num
-        if (typeof num !== 'number') throw new TypeError('num参数应该是一个number类型')
-        if (n < 0) throw new Error('参数n不应该小于0')
-        let hasDot = parseInt(num) != num //这里检测num是否为小数,true表示小数
-        let m = n != undefined && n != null ? n : 1
-        num = m == 0 ? num.toFixed(m) + '.' : hasDot ? (n ? num.toFixed(n) : num) : num.toFixed(m)
-        symbol = symbol || ','
-        num = num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function (match, p1) {
-          return p1 + symbol
-        })
-        if (n == 0 || (!hasDot && !n)) {
-          //如果n为0或者传入的num是整数并且没有指定整数的保留位数,则去掉前面操作中的小数位
-          num = num.substring(0, num.indexOf('.'))
-        }
-        return num
-      },
-      //去除千分位中的‘,’
-      delcommafy(num) {
-        if (!num) return num
-        num = num.toString()
-        num = num.replace(/,/gi, '')
-        if (num.indexOf('.00') > 0) num = parseInt(num)
-        return num
+      handleDel(row) {
+        this.$emit('delProductData', row)
       },
       // 计算总价
       calculatedDiscount(price, count) {
-        let intPrice = null
-        if (typeof price === 'string') intPrice = this.delcommafy(price) * 100
-        else intPrice = price * 100
-        return this.priceFormat((intPrice * count) / 100)
+        let intPrice = price * 100
+        return this.formatPrice((intPrice * count) / 100)
       },
     },
   }