浏览代码

增加全局金额格式filter

jwyu 3 年之前
父节点
当前提交
acc9afabf7
共有 3 个文件被更改,包括 23 次插入2 次删除
  1. 2 0
      main.js
  2. 19 0
      mixin/index.js
  3. 2 2
      pages-approve/contract/detail.vue

+ 2 - 0
main.js

@@ -1,6 +1,7 @@
 import Vue from 'vue'
 import App from './App'
 import store from './store'
+import mixin from './mixin/index'
 
 import uniAsync from '@/utils/uni-async.js'// uni api async 化
 Vue.prototype.$uniAsync = uniAsync
@@ -15,6 +16,7 @@ Vue.config.productionTip = false
 
 App.mpType = 'app'
 
+Vue.mixin(mixin);
 const app = new Vue({
 	store,
     ...App

+ 19 - 0
mixin/index.js

@@ -0,0 +1,19 @@
+module.exports ={
+    filters:{
+        //  格式化金额 三位一个逗号
+		formatPriceHasPoint(e){
+			let str=e.toString()
+			let num1='',num2=''
+			if(str.indexOf(".")!=-1){
+				num1=str.substring(0,str.indexOf("."))
+				num2=str.substring(str.length,str.indexOf("."))
+				if(Number(num2)<=0){
+					num2=''
+				}
+			}else{
+				num1=str
+			}
+			return num1.replace(/(?!^)(?=(\d{3})+$)/g, ',')+num2
+		}
+    }
+}

+ 2 - 2
pages-approve/contract/detail.vue

@@ -29,11 +29,11 @@
 				<view style="padding-left:140rpx">({{detail.StartDate|formateYear(detail.EndDate)}})</view>
 				<view>
 					<text class="lable">{{detail.ContractBusinessType==='代付合同'?'代付金额':'合同金额'}}:</text>
-					<text style="color:#FE6B7C">{{detail.Price}}元</text>
+					<text style="color:#FE6B7C">{{detail.Price|formatPriceHasPoint}}元</text>
 				</view>
 				<view v-if="detail.ContractBusinessType==='代付合同'">
 					<text class="lable">合同金额:</text>
-					<text style="color:#FE6B7C">{{detail.RelationContractDetailList[0].Price}}元</text>
+					<text style="color:#FE6B7C">{{detail.RelationContractDetailList[0].Price|formatPriceHasPoint}}元</text>
 				</view>
 				<view>
 					<text class="lable">合同归属:</text>