Преглед изворни кода

app分销中心页面保费数值精度丢失问题处理

@dongkboy пре 6 дана
родитељ
комит
d7cef84546
1 измењених фајлова са 33 додато и 16 уклоњено
  1. 33 16
      pages/tool/distributionCenter.vue

+ 33 - 16
pages/tool/distributionCenter.vue

@@ -66,13 +66,13 @@
 				</view>
 				<view class="content dis a-c f-c">
 					<view class=" totalCount dis a-c ">
-						<text class="sum">{{distributionInfo.totalPremium / 10000 || 0}}</text>
+						<text class="sum">{{formatPremium(distributionInfo.totalPremium)}}</text>
 						<text class="unit">万</text>
 					</view>
 					<view class="today  dis a-c mt-1 ">
 						<text>今日新增</text>
 						<image src="/static/image/income.png" mode=""></image>
-						<text class="sum">{{distributionInfo.todayPremium / 10000 || 0}}</text>
+						<text class="sum">{{formatPremium(distributionInfo.todayPremium)}}</text>
 						<text class="unit">万</text>
 					</view>
 				</view>
@@ -172,10 +172,12 @@
 				</view>
 			</view>
 		</u-overlay>
+		<global-loading :show="loadingShow" :text="loadingText"></global-loading>
 	</view>
 </template>
 
 <script>
+	import Decimal from 'decimal.js';
 	import QR from "@/common/wxqrcode.js"
 	import {
 		pathToBase64,
@@ -191,6 +193,8 @@
 	export default {
 		data() {
 			return {
+				loadingShow: false, //加载
+				loadingText: '加载中', //加载提示文字
 				showLargeImageShow: false, //大图预览弹窗
 				sctiveimg: "", // 放大显示的图片
 				shareImage: "", //分享图片
@@ -203,20 +207,26 @@
 		onShow() {
 
 		},
-		onLoad() {
-			this.getUserInfo() //获取用户信息
-
-			this.getDistribution();
-			this.qrcodeImg = QR.createQrCodeImg(this.$base.h5BaseUrl + `/#/pages/registr/h5Registr?systemCode=${this
-				.system_code}&page=分销员注册&info=${JSON.stringify({
-					name: this.Info.name,
-					infoId: this.Info.infoId,
-					id: this.Info.id,
-					headSculpture: this.Info.headSculpture,
-					deptName: this.Info.deptName,
-				})}`, {
-				size: parseInt(300), //二维码大小
-			})
+		async onLoad() {
+			this.loadingShow = true;
+			try {
+				await this.getUserInfo() //获取用户信息
+				await this.getDistribution();
+				this.qrcodeImg = QR.createQrCodeImg(this.$base.h5BaseUrl + `/#/pages/registr/h5Registr?systemCode=${this
+					.system_code}&page=分销员注册&info=${JSON.stringify({
+						name: this.Info.name,
+						infoId: this.Info.infoId,
+						id: this.Info.id,
+						headSculpture: this.Info.headSculpture,
+						deptName: this.Info.deptName,
+					})}`, {
+					size: parseInt(300), //二维码大小
+				})
+				this.loadingShow = false;
+			} catch (error) {
+				this.loadingShow = false;
+			}
+
 
 		},
 		computed: {
@@ -243,6 +253,13 @@
 			numberFormat(value) {
 				return (value).toLocaleString('en-US');
 			},
+			//保费(元)转万元,Decimal 高精度计算
+			formatPremium(value) {
+				if (value === undefined || value === null || value === '') {
+					return '0';
+				}
+				return new Decimal(value).dividedBy(10000).toString();
+			},
 			async getDistribution() {
 				let res = await this.$http.post('/sysDistributionSetting/distributionCenter');
 				if (res.code == 200) {