shish 4 лет назад
Родитель
Сommit
6ec749dae7

+ 72 - 1
ghsApp/src/utils/util.js

@@ -420,6 +420,73 @@ export const isScanEnv = () =>{
 	//#endif
 	//#endif
 	return isScanEnv
 	return isScanEnv
 }
 }
+
+//加
+export const add = (arg1, arg2) => {
+    var r1, r2, m, n;
+    try {
+        r1 = arg1.toString().split(".")[1].length
+    } catch (e) {
+        r1 = 0
+    }
+    try {
+        r2 = arg2.toString().split(".")[1].length
+    } catch (e) { 
+        r2 = 0 
+    } 
+    m = Math.pow(10, Math.max(r1, r2))
+    n = (r1 >= r2) ? r1 : r2;
+    return ((arg1 * m + arg2 * m) / m).toFixed(n);
+}
+
+//减
+export const sub = (arg1, arg2) => {
+    var re1, re2, m, n;
+    try {
+        re1 = arg1.toString().split(".")[1].length;
+    } catch (e) {
+    re1 = 0;
+    }
+    try {
+        re2 = arg2.toString().split(".")[1].length;
+    } catch (e) {
+        re2 = 0;
+    }
+    m = Math.pow(10, Math.max(re1, re2)); 
+    n = (re1 >= re2) ? re1 : re2;
+    return ((arg1 * m - arg2 * m) / m).toFixed(n);
+}
+
+//乘
+export const mul = (arg1, arg2) => {
+    var m = 0;
+    var s1 = arg1.toString();
+    var s2 = arg2.toString();
+    try {
+        m += s1.split(".")[1].length;
+    } catch (e) {}
+    try {
+        m += s2.split(".")[1].length;
+    } catch (e) {}
+ 
+    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
+}
+
+// 除数,被除数, 保留的小数点后的位数
+export const div = (arg1,arg2,digit) =>{
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""))
+    r2=Number(arg2.toString().replace(".",""))
+    //获取小数点后的计算值
+   var result= ((r1/r2)*Math.pow(10,t2-t1)).toString()
+    var result2=result.split(".")[1];
+    result2=result2.substring(0,digit>result2.length?result2.length:digit);
+ 
+    return Number(result.split(".")[0]+"."+result2);
+}
+
 export default {
 export default {
 	isEmpty,
 	isEmpty,
 	copyObject,
 	copyObject,
@@ -442,5 +509,9 @@ export default {
 	callUp,
 	callUp,
 	hitRemind,
 	hitRemind,
 	confirmModal,
 	confirmModal,
-	isScanEnv
+	isScanEnv,
+	add,
+	sub,
+	mul,
+	div
 };
 };

+ 12 - 6
ghsPad/src/admin/home/components/leftItem.vue

@@ -5,12 +5,13 @@
             <view v-for="item in selectList" :key="item.id" @click="selectCurrentActive(item)" class="show-item_box">
             <view v-for="item in selectList" :key="item.id" @click="selectCurrentActive(item)" class="show-item_box">
                 <view :class="[ 'item-body_box', selectCurrentActiveItem.id===item.id?'active':'not-active']">
                 <view :class="[ 'item-body_box', selectCurrentActiveItem.id===item.id?'active':'not-active']">
                     <view class="flower-name_box">
                     <view class="flower-name_box">
-                        <view class="current-item-title"><text class="name">{{item.name}}</text><text @click.stop="delSelectItem" class="del">删除</text></view>
+                        <view class="current-item-title"><text class="name">{{item.name}}</text><text @click.stop="delItem(item)" class="del">删除</text></view>
                     </view>
                     </view>
                     <view class="item-price-num">
                     <view class="item-price-num">
-                        <view>{{parseFloat(item.bigPrice)}}元/{{item.bigUnit}}</view>
+                        <view v-if="item.unitType == 0">{{parseFloat(item.bigPrice)}}元/{{item.bigUnit}}</view>
+                        <view v-else>{{parseFloat(item.smallPrice)}}元/{{item.smallUnit}}</view>
                         <view>{{item.buyNum}} {{item.unitType == 0 ? item.bigUnit : item.smallUnit}}</view>
                         <view>{{item.buyNum}} {{item.unitType == 0 ? item.bigUnit : item.smallUnit}}</view>
-                        <view>¥{{item.buyNum * item.unitPrice}}</view>
+                        <view>¥{{parseFloat((item.buyNum * item.unitPrice).toFixed(2))}}</view>
                     </view>
                     </view>
                 </view>
                 </view>
             </view>
             </view>
@@ -18,12 +19,13 @@
         <view class="itemList-footer_box">
         <view class="itemList-footer_box">
             <view> 数量
             <view> 数量
                 <text style="margin-left:5upx;">
                 <text style="margin-left:5upx;">
-                    <text v-if="Number(totalShop.bigUnit)>0">{{totalShop.bigUnit}}扎</text>
-                    <text v-if="Number(totalShop.smallUnit)>0">{{totalShop.smallUnit}}支</text>
+                    <text v-if="Number(allCount.bigNum)>0">{{allCount.bigNum}}扎</text>
+                    <text v-if="Number(allCount.smallNum)>0">{{allCount.smallNum}}支</text>
                 </text>
                 </text>
             </view>
             </view>
-            <view> 合计 <text style="margin-left:5upx;">¥{{totalShop.totalPrice}}</text> </view>
+            <view> 合计 <text style="margin-left:5upx;">¥{{allPrice}}</text> </view>
         </view>
         </view>
+
     </view>
     </view>
 </template>
 </template>
 <script>
 <script>
@@ -55,6 +57,10 @@ export default {
         }
         }
     },
     },
     methods:{
     methods:{
+        delItem(item){
+            item.buyNum = 0
+            this.replaceItemFn(item,1,'sub')
+        }
     }
     }
 }
 }
 </script>
 </script>

+ 1 - 1
ghsPad/src/admin/home/components/rightItemArea.vue

@@ -73,7 +73,7 @@ export default {
             this.categoryId = this.shopListType[0].id
             this.categoryId = this.shopListType[0].id
             this.getShowList()
             this.getShowList()
 
 
-            this.initData()
+            this.initStorageData()
         },
         },
         async getShowList(){
         async getShowList(){
             let { data:{list} } =  await showList({})
             let { data:{list} } =  await showList({})

+ 23 - 137
ghsPad/src/mixins/product.js

@@ -14,14 +14,8 @@ export default {
 			autoLoad: true, //自动获取商品信息
 			autoLoad: true, //自动获取商品信息
 			allFilterProductInfo:'',
 			allFilterProductInfo:'',
 			globalClassItemList:'',
 			globalClassItemList:'',
-			top_list:'',
-			//id动态切换
-			scroll_into_view:"",
-			timeFun:"",
 			kdType:'HIT',//点击和扫码开单,HIT SCAN
 			kdType:'HIT',//点击和扫码开单,HIT SCAN
 			checkStock:true,// 考虑库存,盘点不需要考虑库存
 			checkStock:true,// 考虑库存,盘点不需要考虑库存
-			isAddModel:false,
-			isAddInputFocus:false,
 			customData: { buyNum: 0, unitPrice: 0,unitType:0 },
 			customData: { buyNum: 0, unitPrice: 0,unitType:0 },
 			globalItemList:[]
 			globalItemList:[]
 		};
 		};
@@ -35,74 +29,33 @@ export default {
 	onUnload() {},
 	onUnload() {},
 	computed: {
 	computed: {
 		...mapGetters(["getSelectInfo"]),
 		...mapGetters(["getSelectInfo"]),
-		//当前页面选中的商品列表
 		selectList() {
 		selectList() {
 			let selectInfo = this.getSelectInfo;
 			let selectInfo = this.getSelectInfo;
 			return selectInfo[this.selectJobType+'_'+this.selectJobId] || []
 			return selectInfo[this.selectJobType+'_'+this.selectJobId] || []
 		},
 		},
-		scrollClassId() {
-			const curClass = this.productInfoList[this.classIndex];
-			if (curClass) {
-				return `class_${curClass.classId}`;
-			}
-			return "";
-		},
 		allPrice() {
 		allPrice() {
 			let price = 0;
 			let price = 0;
 			if (this.selectList) {
 			if (this.selectList) {
 				for (const item of this.selectList) {
 				for (const item of this.selectList) {
-					const itemInfo = this.getSelectItemById(item.id, item.classId);
-					if (itemInfo && !this.$util.isEmpty(itemInfo.bigPrice) && !this.$util.isEmpty(itemInfo.smallPrice)) {
-						if(item.userPrice>0){
-							price += Number(item.bigCount) * Number(itemInfo.userPrice);
-							let currentSmallPrice = (itemInfo.userPrice/itemInfo.ratio).toFixed(2)
-							price += Number(item.smallCount)*Number(currentSmallPrice)
-						}else{
-							price += item.bigCount * Number(itemInfo.bigPrice);
-							price += item.smallCount * Number(itemInfo.smallPrice);
-						}
-					}
+					let currentPrice = this.$util.mul(item.unitPrice,item.buyNum)
+					price = this.$util.add(currentPrice,price)
 				}
 				}
 			}
 			}
-			return Math.round(price * 100) / 100;
+			return parseFloat(price)
 		},
 		},
-		//选择商品总数
 		allCount() {
 		allCount() {
-			let bigLength = 0;
-			let smallLength = 0;
+			let bigNum = 0;
+			let smallNum = 0;
 			if (this.selectList) {
 			if (this.selectList) {
 				for (const item of this.selectList) {
 				for (const item of this.selectList) {
-					bigLength += Number(item.bigCount)
-					smallLength += Number(item.smallCount)
-				}
-			}
-			return {bigLength:bigLength,smallLength:smallLength,};
-		},
-		//当前选中商品列表中是否有没有库存的商品
-		hasNoStock() {
-			let has = false;
-			if (this.selectList) {
-				for (const item of this.selectList) {
-					const {
-						bigCount,
-						smallCount,
-						bigNum,
-						bigUnit,
-						smallNum,
-						smallUnit,
-						ratio
-					} = item;
-					const ratioNum = Number(ratio);
-					if (
-						Number(bigCount) * ratioNum + Number(smallCount) >
-						Number(bigNum) * ratioNum + Number(smallNum)
-					) {
-						has = true;
-						break;
+					if(item.unitType == 0){
+						bigNum = this.$util.add(bigNum,item.buyNum)
+					}else{
+						smallNum = this.$util.add(smallNum,item.buyNum)
 					}
 					}
 				}
 				}
 			}
 			}
-			return has;
+			return {bigNum,smallNum}
 		}
 		}
 	},
 	},
 	onShow(){
 	onShow(){
@@ -112,7 +65,7 @@ export default {
 		...mapActions(["setSelectInfo", "reSetSelectInfo"]),
 		...mapActions(["setSelectInfo", "reSetSelectInfo"]),
 		init(){
 		init(){
 			if (this.autoLoad) {
 			if (this.autoLoad) {
-				this.initData();
+				this.initStorageData();
 			}
 			}
 		},
 		},
 		//放到仓库
 		//放到仓库
@@ -148,23 +101,10 @@ export default {
 				this.$forceUpdate()
 				this.$forceUpdate()
 			}
 			}
 		},
 		},
-		//请求商品数据
-		initData() {
-			console.log('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
+		//取出缓存数据
+		initStorageData() {
 			let currentInfo = uni.getStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
 			let currentInfo = uni.getStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
 			if(!this.$util.isEmpty(currentInfo)){
 			if(!this.$util.isEmpty(currentInfo)){
-				currentInfo.forEach((currentItem,currentIndex,currentArray)=>{
-					let currentId = currentItem.id
-					if(this.globalItemList[currentId]){
-						currentArray[currentIndex].bigPrice = this.globalItemList[currentId].bigPrice
-						currentArray[currentIndex].smallPrice = this.globalItemList[currentId].smallPrice
-						//已经记住的花材,价格修改之后,被记住的价格也要同步修改
-						//不能放开会造成采购单已经填好的,也会变动 shish 20220114
-						// if(!this.$util.isEmpty(currentArray[currentIndex].userPrice)){
-						// 	currentArray[currentIndex].userPrice = this.globalItemList[currentId].bigPrice
-						// }
-					}
-				})
 				this.setSelectInfo({ selectJobType: this.selectJobType, info: currentInfo,selectJobId:this.selectJobId })
 				this.setSelectInfo({ selectJobType: this.selectJobType, info: currentInfo,selectJobId:this.selectJobId })
 			}
 			}
 		},
 		},
@@ -178,15 +118,6 @@ export default {
 			price = Math.round(sum * 100) / 100;
 			price = Math.round(sum * 100) / 100;
 			return price;
 			return price;
 		},
 		},
-		//通过id获取当前选中的商品信息
-		getSelectItemById(id, classId) {
-			let info = { bigCount: null, smallCount: null, autoPrice: null, itemPrice: null }
-			const item = this.selectList && this.selectList.find(ele => { return ele.id == id && ele.classId == classId })
-			if (item) {
-				info = { ...item, bigCount: Number(item.bigCount), smallCount: Number(item.smallCount), autoPrice: Number(item.autoPrice), itemPrice: Number(item.itemPrice)}
-			}
-			return info;
-		},
 		//添加删除和修改花材
 		//添加删除和修改花材
 		//multiple 0单个加减 1弹框方式多个加减
 		//multiple 0单个加减 1弹框方式多个加减
 		//calc 当multiple=0时,add表示加,sub表示减
 		//calc 当multiple=0时,add表示加,sub表示减
@@ -238,17 +169,14 @@ export default {
 				}else{
 				}else{
 					list[index].buyNum = item.buyNum
 					list[index].buyNum = item.buyNum
 					list[index].unitPrice = item.unitPrice
 					list[index].unitPrice = item.unitPrice
+					list[index].unitType = item.unitType
 				}
 				}
 			}
 			}
-
 			if(this.kdType == 'HIT' && multiple ==0){
 			if(this.kdType == 'HIT' && multiple ==0){
 				this.$util.hitRemind()
 				this.$util.hitRemind()
 			}
 			}
-			
 			//数据放到仓库永久存放
 			//数据放到仓库永久存放
 			this.pushToSave(list)
 			this.pushToSave(list)
-
-			this.itemNumPriceRefresh()
 		},
 		},
 		//显示可以修改花材的弹框
 		//显示可以修改花材的弹框
 		showAddModelFn(info) {
 		showAddModelFn(info) {
@@ -261,86 +189,44 @@ export default {
 			}
 			}
 			this.$refs.kdSelectNumPriceRef.open('center')
 			this.$refs.kdSelectNumPriceRef.open('center')
 			this.customData = copyObject(info)
 			this.customData = copyObject(info)
-			this.isAddInputFocus = false;
 			this.$nextTick(()=>{
 			this.$nextTick(()=>{
-				this.customData.smallCount = this.customData.smallCount==0?null:this.customData.smallCount;
-				this.customData.bigCount = this.customData.bigCount==0?null:this.customData.bigCount;
 				if(this.selectJobType == 'bill'){
 				if(this.selectJobType == 'bill'){
-					if(this.customData.userPrice == null || this.customData.userPrice == 0){
-						this.customData.userPrice =	this.customData.bigPrice;
-					}
-				}else{
-					this.customData.userPrice = this.customData.userPrice==0?null:this.customData.userPrice;
+					this.customData.unitPrice =	this.customData.bigPrice;
 				}
 				}
 			})
 			})
 		},
 		},
-		confirmAddItemModel(val) {
-			if (val.index === 0) {
+		confirmAddItemModel(item) {
+			if (item.index === 0) {
 				this.addItemModelHidden();
 				this.addItemModelHidden();
 				return false
 				return false
 			}
 			}
-
-			if(/(^[1-9]\d*$)/.test(this.customData.buyNum) == false){
+			if(/(^[1-9]\d*$)/.test(item.buyNum) == false){
 				uni.showToast({title:"请填写数值",icon:"none"})
 				uni.showToast({title:"请填写数值",icon:"none"})
 				return;
 				return;
 			}
 			}
-
-			if(/(^[1-9]\d*$)/.test(this.customData.buyNum)){
-				if(this.customData.bigCount<=0){
+			if(/(^[1-9]\d*$)/.test(item.buyNum)){
+				if(item.bigCount<=0){
 					uni.showToast({title:"数量要大于0",icon:"none"})
 					uni.showToast({title:"数量要大于0",icon:"none"})
 					return;
 					return;
 				}
 				}
 			}
 			}
-
 			//只有开单和采购需要使用价格
 			//只有开单和采购需要使用价格
 			if(this.selectJobType == 'bill' || this.selectJobType == 'purchase'){
 			if(this.selectJobType == 'bill' || this.selectJobType == 'purchase'){
-				if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.customData.unitPrice) == false){
+				if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(item.unitPrice) == false){
 					uni.showToast({title:"金额错误",icon:"none"})
 					uni.showToast({title:"金额错误",icon:"none"})
 					return;
 					return;
 				}
 				}
-				if(this.customData.unitPrice <=0){
+				if(item.unitPrice <=0){
 					uni.showToast({title:"金额要大于0",icon:"none"})
 					uni.showToast({title:"金额要大于0",icon:"none"})
 					return;
 					return;
 				}
 				}
 			}
 			}
-			this.replaceItemFn(this.customData,1)
+			this.replaceItemFn(item,1)
 			this.addItemModelHidden()			
 			this.addItemModelHidden()			
 		},
 		},
 		addItemModelHidden() {
 		addItemModelHidden() {
 			this.$refs.kdSelectNumPriceRef.close()
 			this.$refs.kdSelectNumPriceRef.close()
 			this.customData = {};
 			this.customData = {};
-		},
-		itemNumPriceRefresh(){
-			//涉及记住花材的代码和流程,请全项目搜索关键词remember_item
-			//将已选的花材按classId_productId键名组合
-			let selectListData = []
-			if(!this.$util.isEmpty(this.selectList)){
-				this.selectList.forEach((i)=>{
-					selectListData[i.id] = i
-				})
-			}
-			let upList = this.globalClassItemList;
-			for (let i=0;i<upList.length;i++){
-				//将已选的花材数量和价格组合到总列表里
-				if(!this.$util.isEmpty(upList[i].child)){
-					let currentChildren = upList[i].child
-					for(let x=0;x<currentChildren.length;x++){
-						let currentProduct = currentChildren[x]
-						let currentPId = currentProduct.id
-						let selectProduct = selectListData[currentPId] || []
-						if(!this.$util.isEmpty(selectProduct)){
-							upList[i].child[x].bigCount = selectProduct.bigCount || 0
-							upList[i].child[x].userPrice = selectProduct.userPrice || 0
-							upList[i].child[x].smallCount = selectProduct.smallCount || 0
-						}else{
-							upList[i].child[x].bigCount = 0
-							upList[i].child[x].userPrice = 0
-							upList[i].child[x].smallCount = 0
-						}
-					}
-				}
-			}
-			this.globalClassItemList = upList
 		}
 		}
 	}
 	}
 }
 }

+ 72 - 1
ghsPad/src/utils/util.js

@@ -420,6 +420,73 @@ export const isScanEnv = () =>{
 	//#endif
 	//#endif
 	return isScanEnv
 	return isScanEnv
 }
 }
+
+//加
+export const add = (arg1, arg2) => {
+    var r1, r2, m, n;
+    try {
+        r1 = arg1.toString().split(".")[1].length
+    } catch (e) {
+        r1 = 0
+    }
+    try {
+        r2 = arg2.toString().split(".")[1].length
+    } catch (e) { 
+        r2 = 0 
+    } 
+    m = Math.pow(10, Math.max(r1, r2))
+    n = (r1 >= r2) ? r1 : r2;
+    return ((arg1 * m + arg2 * m) / m).toFixed(n);
+}
+
+//减
+export const sub = (arg1, arg2) => {
+    var re1, re2, m, n;
+    try {
+        re1 = arg1.toString().split(".")[1].length;
+    } catch (e) {
+    re1 = 0;
+    }
+    try {
+        re2 = arg2.toString().split(".")[1].length;
+    } catch (e) {
+        re2 = 0;
+    }
+    m = Math.pow(10, Math.max(re1, re2)); 
+    n = (re1 >= re2) ? re1 : re2;
+    return ((arg1 * m - arg2 * m) / m).toFixed(n);
+}
+
+//乘
+export const mul = (arg1, arg2) => {
+    var m = 0;
+    var s1 = arg1.toString();
+    var s2 = arg2.toString();
+    try {
+        m += s1.split(".")[1].length;
+    } catch (e) {}
+    try {
+        m += s2.split(".")[1].length;
+    } catch (e) {}
+ 
+    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
+}
+
+// 除数,被除数, 保留的小数点后的位数
+export const div = (arg1,arg2,digit) =>{
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""))
+    r2=Number(arg2.toString().replace(".",""))
+    //获取小数点后的计算值
+   var result= ((r1/r2)*Math.pow(10,t2-t1)).toString()
+    var result2=result.split(".")[1];
+    result2=result2.substring(0,digit>result2.length?result2.length:digit);
+ 
+    return Number(result.split(".")[0]+"."+result2);
+}
+
 export default {
 export default {
 	isEmpty,
 	isEmpty,
 	copyObject,
 	copyObject,
@@ -442,5 +509,9 @@ export default {
 	callUp,
 	callUp,
 	hitRemind,
 	hitRemind,
 	confirmModal,
 	confirmModal,
-	isScanEnv
+	isScanEnv,
+	add,
+	sub,
+	mul,
+	div
 };
 };

+ 71 - 1
hdApp/src/utils/util.js

@@ -413,6 +413,72 @@ export const noStockRemind = () =>{
 	})
 	})
 }
 }
 
 
+//加
+export const add = (arg1, arg2) => {
+    var r1, r2, m, n;
+    try {
+        r1 = arg1.toString().split(".")[1].length
+    } catch (e) {
+        r1 = 0
+    }
+    try {
+        r2 = arg2.toString().split(".")[1].length
+    } catch (e) { 
+        r2 = 0 
+    } 
+    m = Math.pow(10, Math.max(r1, r2))
+    n = (r1 >= r2) ? r1 : r2;
+    return ((arg1 * m + arg2 * m) / m).toFixed(n);
+}
+
+//减
+export const sub = (arg1, arg2) => {
+    var re1, re2, m, n;
+    try {
+        re1 = arg1.toString().split(".")[1].length;
+    } catch (e) {
+    re1 = 0;
+    }
+    try {
+        re2 = arg2.toString().split(".")[1].length;
+    } catch (e) {
+        re2 = 0;
+    }
+    m = Math.pow(10, Math.max(re1, re2)); 
+    n = (re1 >= re2) ? re1 : re2;
+    return ((arg1 * m - arg2 * m) / m).toFixed(n);
+}
+
+//乘
+export const mul = (arg1, arg2) => {
+    var m = 0;
+    var s1 = arg1.toString();
+    var s2 = arg2.toString();
+    try {
+        m += s1.split(".")[1].length;
+    } catch (e) {}
+    try {
+        m += s2.split(".")[1].length;
+    } catch (e) {}
+ 
+    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
+}
+
+// 除数,被除数, 保留的小数点后的位数
+export const div = (arg1,arg2,digit) =>{
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""))
+    r2=Number(arg2.toString().replace(".",""))
+    //获取小数点后的计算值
+   var result= ((r1/r2)*Math.pow(10,t2-t1)).toString()
+    var result2=result.split(".")[1];
+    result2=result2.substring(0,digit>result2.length?result2.length:digit);
+ 
+    return Number(result.split(".")[0]+"."+result2);
+}
+
 export default {
 export default {
 	isEmpty,
 	isEmpty,
 	copyObject,
 	copyObject,
@@ -433,5 +499,9 @@ export default {
 	confirmModal,
 	confirmModal,
 	isScanEnv,
 	isScanEnv,
 	hitRemind,
 	hitRemind,
-	noStockRemind
+	noStockRemind,
+	add,
+	sub,
+	mul,
+	div
 };
 };

+ 72 - 1
hdPad/src/utils/util.js

@@ -373,6 +373,73 @@ export const isScanEnv = () =>{
 	//#endif
 	//#endif
 	return isScanEnv
 	return isScanEnv
 }
 }
+
+//加
+export const add = (arg1, arg2) => {
+    var r1, r2, m, n;
+    try {
+        r1 = arg1.toString().split(".")[1].length
+    } catch (e) {
+        r1 = 0
+    }
+    try {
+        r2 = arg2.toString().split(".")[1].length
+    } catch (e) { 
+        r2 = 0 
+    } 
+    m = Math.pow(10, Math.max(r1, r2))
+    n = (r1 >= r2) ? r1 : r2;
+    return ((arg1 * m + arg2 * m) / m).toFixed(n);
+}
+
+//减
+export const sub = (arg1, arg2) => {
+    var re1, re2, m, n;
+    try {
+        re1 = arg1.toString().split(".")[1].length;
+    } catch (e) {
+    re1 = 0;
+    }
+    try {
+        re2 = arg2.toString().split(".")[1].length;
+    } catch (e) {
+        re2 = 0;
+    }
+    m = Math.pow(10, Math.max(re1, re2)); 
+    n = (re1 >= re2) ? re1 : re2;
+    return ((arg1 * m - arg2 * m) / m).toFixed(n);
+}
+
+//乘
+export const mul = (arg1, arg2) => {
+    var m = 0;
+    var s1 = arg1.toString();
+    var s2 = arg2.toString();
+    try {
+        m += s1.split(".")[1].length;
+    } catch (e) {}
+    try {
+        m += s2.split(".")[1].length;
+    } catch (e) {}
+ 
+    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
+}
+
+// 除数,被除数, 保留的小数点后的位数
+export const div = (arg1,arg2,digit) =>{
+    var t1=0,t2=0,r1,r2;
+    try{t1=arg1.toString().split(".")[1].length}catch(e){}
+    try{t2=arg2.toString().split(".")[1].length}catch(e){}
+    r1=Number(arg1.toString().replace(".",""))
+    r2=Number(arg2.toString().replace(".",""))
+    //获取小数点后的计算值
+   var result= ((r1/r2)*Math.pow(10,t2-t1)).toString()
+    var result2=result.split(".")[1];
+    result2=result2.substring(0,digit>result2.length?result2.length:digit);
+ 
+    return Number(result.split(".")[0]+"."+result2);
+}
+
 export default {
 export default {
 	isEmpty,
 	isEmpty,
 	copyObject,
 	copyObject,
@@ -391,5 +458,9 @@ export default {
 	unique,
 	unique,
 	isMoney,
 	isMoney,
 	confirmModal,
 	confirmModal,
-	isScanEnv
+	isScanEnv,
+	add,
+	sub,
+	mul,
+	div
 };
 };