瀏覽代碼

保养套餐

twt 3 年之前
父節點
當前提交
bbe0111b34
共有 1 個文件被更改,包括 92 次插入15 次删除
  1. 92 15
      pages/module/maintain.vue

+ 92 - 15
pages/module/maintain.vue

@@ -58,7 +58,7 @@
 										<view class="goodsCont">
 											<view class="goodsContTop">
 												<view class="goodsItemName">{{v.showName}}</view>
-												<view class="replace" @click.stop="replace(vf,index,findex,i)" v-if="vf.length>1">更换</view>
+												<view class="replace" @click.stop="replace(vf,index,findex,i)" v-if="vf.goodsList.length>1">更换</view>
 											</view>
 											<view class="goodsCOntBOttom">
 												<view class="salePrice">¥{{v.salePrice?v.salePrice:'0.00'}}</view>
@@ -461,22 +461,99 @@ export default {
 									list.listGoodsAll.forEach((goods,index)=>{
 										//console.log(goods.goodsGroupDetail)
 										
-										 if(goods.goodsList[0].capacity&&!goods.goodsList[0].del){
-											//console.log(Number(list.referenceDosageQty)/goods[0].capacity)
-											if(Number(list.referenceDosageQty)/goods.goodsList[0].capacity>1){
-												console.log("添加一条")
-												var addDta=goods.goodsList[0];
-												addDta.del=true;
-												/* addDta.forEach(add=>{
-													add.del=true;
-												}) */
-												//addDta.splice(1,0)
-												console.log(addDta)
-												var add=JSON.parse(JSON.stringify(addDta))
-												list.listGoodsAll[0].goodsList.splice(index+1, 0,add)
+										
+										if(goods.goodsGroupDetail.length==0){
+											//同组品为空的情况
+											if(goods.goodsList[0].capacity&&!goods.goodsList[0].del){
+												//console.log(Number(list.referenceDosageQty)/goods[0].capacity)
+												if(Number(list.referenceDosageQty)/goods.goodsList[0].capacity>1){
+													console.log("添加一条")
+													var addDta={
+														goodsGroupDetail:[],
+														goodsList:goods.goodsList
+													}
+													
+													addDta.goodsList.forEach(add=>{
+														add.del=true;
+													}) 
+													//addDta.splice(1,0)
+													console.log(addDta)
+													var add=JSON.parse(JSON.stringify(addDta))
+													list.listGoodsAll.splice(index+1, 0,add)
+													
+												}
+											} 
+										}else{
+											//同组品不为空的情况 
+											//console.log("同组品不为空的情况 ")
+											var remainder=0;
+											console.log("list.referenceDosageQty - "+list.referenceDosageQty+list.name)
+										    var referenceDosageQty=Number(list.referenceDosageQty)
+											//var addArr= goods.goodsList
+											goods.goodsList.splice(300);
+											var addArr=JSON.parse(JSON.stringify(goods.goodsList))
+											if(list.referenceDosageQty&&!goods.goodsList[0].del){
+											
+											goods.goodsGroupDetail.forEach((tgoods,tindex)=>{
+											
+												if(tindex==0){
+													if(referenceDosageQty>tgoods.capacity){
+														var parseIntNum=parseInt(referenceDosageQty/tgoods.capacity)
+														tgoods.qty=parseIntNum
+														var reduce= tgoods.capacity*parseIntNum
+														referenceDosageQty=referenceDosageQty - reduce
+													}else{
+														addArr.unshift(tgoods)
+														referenceDosageQty=referenceDosageQty-tgoods.capacity
+													}
+													/* remainder=referenceDosageQty%tgoods.capacity
+													console.log('--remainder---'+remainder)
+													if(remainder>0){
+														//addArr.unshift(tgoods)
+													} */
+													
+													
+												}else{
+													if(referenceDosageQty>0){
+														/* remainder=Number(referenceDosageQty)%tgoods.capacity
+														console.log('--remainder---'+remainder)
+														if(remainder>1){
+															addArr.unshift(tgoods)
+														}
+														referenceDosageQty=referenceDosageQty-tgoods.capacity */
+													    if(referenceDosageQty>tgoods.capacity){
+															var parseIntNum=parseInt(referenceDosageQty/tgoods.capacity)
+															tgoods.qty=parseIntNum
+															var reduce= tgoods.capacity*parseIntNum
+															referenceDosageQty=referenceDosageQty - reduce
+														}else{
+															addArr.unshift(tgoods)
+															referenceDosageQty=referenceDosageQty-tgoods.capacity
+														} 
+													}
+													
+													
+												}
 												
+												var addDta={
+													goodsGroupDetail:[],
+													goodsList:addArr
+												}
+												addDta.goodsList.forEach(add=>{
+													add.del=true;
+												}) 
+												 if(tindex==0){
+													 console.log(addDta.goodsList[0])
+													//list.listGoodsAll.splice(index, 0,addDta)
+													console.log(list.listGoodsAll[index])
+												}else{
+													list.listGoodsAll.splice(index+1, 0,addDta)
+												} 
+											} ) 
+											
 											}
-										} 
+										}
+									
 									})
 								
 						}