From 6e54af776db885ad1a22ec582bdc97d7e1273c6c Mon Sep 17 00:00:00 2001
From: queenwuli <942534046@qq.com>
Date: Wed, 13 Jan 2021 17:31:30 +0800
Subject: [PATCH] 系统优化
---
hive-app/pages/workbench/selectService/index.vue | 95 +++++++++++++++++++++++++++++++++++++++--------
1 files changed, 79 insertions(+), 16 deletions(-)
diff --git a/hive-app/pages/workbench/selectService/index.vue b/hive-app/pages/workbench/selectService/index.vue
index ad8d172..e96b2c7 100644
--- a/hive-app/pages/workbench/selectService/index.vue
+++ b/hive-app/pages/workbench/selectService/index.vue
@@ -57,7 +57,7 @@
<text>{{op.num}}</text>
</template>
<text class="iconfont iconjia blue-btn-circle ml-10"
- @click.stop="addGoods(op, item.proj)"></text>
+ @click.stop="addGoods(op)"></text>
</view>
</view>
</view>
@@ -104,6 +104,9 @@
},
onLoad(options) {
this.id = options.id;
+ if(options.selectItems){
+ this.selectItems = JSON.parse(decodeURIComponent(options.selectItems));
+ }
uni.setNavigationBarTitle({
title: '当前客户:' + options.vipName
});
@@ -138,20 +141,34 @@
},'POST').then((res) => {
if(res.status == 200){
let result = res.mapInfo.proj;
- this.projectList = result.proj.map((item) => {
- return Object.assign(item, {num: 0});
+ let projectList = result.proj;
+ let comboList = result.composeProj;
+ // 项目
+ projectList.forEach((item) => {
+ item.num = 0;
+ this.selectItems.forEach((op) => {
+ if(item.id == op.id){
+ item.num = op.num;
+ }
+ })
});
+
// 套餐
- let arr = result.composeProj;
- arr.forEach((item) => {
+ comboList.forEach((item) => {
item.proj.forEach((op) => {
op.num = 0;
+ this.selectItems.forEach((key) => {
+ if(op.id == key.id){
+ op.num = key.num;
+ }
+ })
op.totalCount = item.count;
op.isCourse = item.isCourse;
op.parentId = item.id;
})
});
- this.comboList = arr;
+ this.projectList = projectList;
+ this.comboList = comboList;
}
})
},
@@ -172,11 +189,8 @@
* goods.isCourse: 套餐类型 Y-任选套餐 N-固定套餐
* */
addGoods(goods){
- let index = this.selectItems.indexOf(goods);
-
// 当前总数
- let curCount = this.getCurCount(goods.parentId)
-
+ let curCount = this.getCurCount(goods.parentId)
// 任选套餐,当前总数不能超出总剩余数
if(goods.isCourse === 'Y' && curCount >= goods.totalCount){
this.$toast.info('超出剩余次数~')
@@ -187,21 +201,70 @@
return;
}
goods.num++;
+
+ let selectIndex = this.selectItems.findIndex((item) => {
+ return item.id == goods.id;
+ });
// 该商品若已在购物车,则购物车数量上+1,否则加入购物车
- if(index > -1){
- this.selectItems[index].num = goods.num;
+ if(selectIndex > -1){
+ this.selectItems[selectIndex].num = goods.num;
}else{
this.selectItems.push(goods);
}
+
+ // 项目
+ let projectIndex = this.projectList.findIndex((item) => {
+ return item.id == goods.id;
+ })
+ if(projectIndex > -1){
+ this.projectList[projectIndex].num = goods.num;
+ }
+ // 套餐
+ let comboParentIndex = this.comboList.findIndex((item) => {
+ return item.id == goods.parentId;
+ })
+ let comboIndex = null;
+ if(comboParentIndex > -1){
+ comboIndex = this.comboList[comboParentIndex].proj.findIndex((item) => {
+ return item.id == goods.id;
+ })
+ }
+ if(comboParentIndex > -1 && comboIndex > -1){
+ this.comboList[comboParentIndex].proj[comboIndex].num = goods.num;
+ }
},
decreaseGoods(goods){
- let index = this.selectItems.indexOf(goods);
goods.num = goods.num <= 0 ? 0 : goods.num - 1;
+
+ let selectIndex = this.selectItems.findIndex((item) => {
+ return item.id == goods.id;
+ });
// 该商品若已在购物车,则购物车数量上-1,否则从购物车删除
- if(index > -1 && this.selectItems[index].num >= 1){
- this.selectItems[index].num = goods.num;
+ if(goods.num >= 1){
+ this.selectItems[selectIndex].num = goods.num;
}else{
- this.selectItems.splice(index, 1);
+ this.selectItems.splice(selectIndex, 1);
+ }
+
+ // 项目
+ let projectIndex = this.projectList.findIndex((item) => {
+ return item.id == goods.id;
+ })
+ if(projectIndex > -1){
+ this.projectList[projectIndex].num = goods.num;
+ }
+ // 套餐
+ let comboParentIndex = this.comboList.findIndex((item) => {
+ return item.id == goods.parentId;
+ })
+ let comboIndex = null;
+ if(comboParentIndex > -1){
+ comboIndex = this.comboList[comboParentIndex].proj.findIndex((item) => {
+ return item.id == goods.id;
+ })
+ }
+ if(comboParentIndex > -1 && comboIndex > -1){
+ this.comboList[comboParentIndex].proj[comboIndex].num = goods.num;
}
},
clearShopCart(){
--
Gitblit v1.9.1