queenwuli
2021-01-13 6e54af776db885ad1a22ec582bdc97d7e1273c6c
hive-app/pages/workbench/selectService/index.vue
@@ -57,14 +57,14 @@
                                 <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>
               </view>
               <view class="flex justify-between font-12 mt-10">
                  <text>有效期至: {{item.invalidTime}}<text class="red" v-if="item.isInvalid==1">({{item.isInvalid | formatIsInvalid}})</text></text>
                  <text>剩余总次数:{{item.count}}</text>
                  <text v-if="item.isCourse === 'Y'">剩余总次数:{{item.count}}</text>
               </view>
            </view>
            <no-record :isShow="!comboList.length" size="mini" txt="暂无套餐" class="no-record"></no-record>
@@ -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
         });
@@ -124,7 +127,7 @@
      },
      methods:{
         openShoppingCart(){
            this.$refs.shopCart.show()
            this.$refs.shopCart.toggle()
         },
         // 搜索
         search(val){
@@ -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(){
@@ -254,7 +317,7 @@
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
      box-shadow:0 6px 6px rgba(237,234,244,0.5);
      padding-bottom: 5px;
      padding:10px 0 1px;
   }
   .content{
      padding: 10px 10px 65px;
@@ -328,6 +391,6 @@
      font-size: 14px;
   }
   .no-record{
      margin: 20px 0;
      margin: 20px 0!important;
   }
</style>