소스 검색

feat:数据优化

钱新宇 2 일 전
부모
커밋
0cf116e5e5
5개의 변경된 파일140개의 추가작업 그리고 32개의 파일을 삭제
  1. 99 11
      pages/car/index.vue
  2. 19 3
      pages/car/order.vue
  3. 4 2
      pages/product/index.vue
  4. 8 8
      pages/product/list.vue
  5. 10 8
      pages/wait/index.vue

+ 99 - 11
pages/car/index.vue

@@ -39,7 +39,9 @@
                 <view class="box_center">
                   <navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_name">{{ item.name }}</navigator>
                   <navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_spec">{{ item.spec }}</navigator>
-                  <view v-if="item.promo_title" class="promo_title">{{ item.promo_title }}</view>
+                  <view v-if="item.promo_title" class="promo_title">
+                    <text v-for="(promoText, index) in getPromoText(item.promo_title)" :key="index">{{ promoText }}</text>
+                  </view>
                   <navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_price">
                     <text class="price">¥{{ item.price }}</text>
                     <text class="market_price">¥{{ item.market_price }}</text>
@@ -75,10 +77,16 @@
         ></image>
         <text class="checkall">全选</text>
       </view>
+
       <view class="price_box">
-        合计:<text class="price_total">¥{{ priceTotal }}</text>
+        <view style="display: flex; justify-content: flex-start; align-items: baseline; font-size: 24rpx">
+          已选{{ selectProductNum }}件,合计:<text class="price_total">¥{{ discountPrice }}</text></view
+        >
+        <view v-if="reductionMoney !== 0" style="display: flex; justify-content: flex-start; align-items: center; color: #999; font-size: 24rpx">
+          优惠减:<text>¥{{ reductionMoney.toFixed(2) }}</text>
+        </view>
       </view>
-      <view class="to_order" @click="toOrder()">{{ is_pay ? '购买' : '预约' }}</view>
+      <view class="to_order" @click="toOrder()">{{ is_pay ? `${reductionMoney !== 0 ? '优惠' : ''}购买` : `${reductionMoney !== 0 ? '优惠' : ''}预约` }}</view>
     </view>
     <cc-myTabbar :tabBarShow="3"></cc-myTabbar>
   </view>
@@ -103,8 +111,16 @@ export default {
       cartListByGroup: [],
       cartList: [],
       is_pay: 0,
+      reductionMoney: 0,
+      selectProductNum: 0,
+      debounceTimer: null,
+      changeQuantity: null,
     };
   },
+  // 在created钩子中初始化
+  created() {
+    this.changeQuantity = this.debounce(this.handleQuantityChange);
+  },
   onLoad() {
     // #ifdef MP-WEIXIN
     uni.hideTabBar();
@@ -211,12 +227,23 @@ export default {
       // 计算价格
       this.priceHandler();
     },
+    debounce(fn, delay = 500) {
+      return (...args) => {
+        if (this.debounceTimer) {
+          clearTimeout(this.debounceTimer);
+        }
+        this.debounceTimer = setTimeout(() => {
+          fn.apply(this, args);
+        }, delay);
+      };
+    },
     // 数量调整
-    changeQuantity(pIndex, index, number) {
+    handleQuantityChange(pIndex, index, number) {
+      //修改数量重新计算折扣
       // 如果不是0.表示两侧按钮点击,0表示输入的修改
       if (number != 0) {
         // 计算个数
-        this.cartListByGroup[pIndex].products[index].buy_num = this.cartListByGroup[pIndex].products[index].buy_num + number;
+        this.cartListByGroup[pIndex].products[index].buy_num = Number(this.cartListByGroup[pIndex].products[index].buy_num) + Number(number);
       }
       // 如果大于库存
       if (this.cartListByGroup[pIndex].products[index].buy_num > this.cartListByGroup[pIndex].products[index].stock) {
@@ -249,6 +276,7 @@ export default {
         .then((re) => {
           if (re.code == 'success') {
             // 计算价格
+            this.cartListByGroup[pIndex].products[index].buy_num = re.data.buy_num;
             this.priceHandler();
           } else {
             uni.showToast({
@@ -412,6 +440,59 @@ export default {
       this.deleteCar(e.pIndex, e.index);
     },
   },
+  watch: {
+    priceTotal: {
+      handler(newVal, oldVal) {
+        // 计算价格
+        // this.priceHandler();
+        let waitList = [];
+        // 循环处理
+        for (let index in this.cartListByGroup) {
+          // 如果选中的
+          for (const key in this.cartListByGroup[index].products) {
+            if (this.cartListByGroup[index].products[key].checked) {
+              // // 如果库存不足
+              // if (newVal[index].products[key].buy_num < 1) {
+              //   uni.showToast({ icon: 'none', title: '选择的产品至少需要1个' });
+              //   return;
+              // }
+              // // 如果库存不足
+              // if (newVal[index].products[key].buy_num > newVal[index].products[key].stock) {
+              //   uni.showToast({ icon: 'none', title: '产品库存不足' });
+              //   return;
+              // }
+              waitList.push(this.cartListByGroup[index].products[key].id);
+            }
+          }
+        }
+        this.selectProductNum = waitList.length;
+        if (waitList.length > 0) {
+          this.$http.request('api/shop_cart/check_list', { cart_ids: waitList.join(',') }).then((re) => {
+            if (re.code == 'success') {
+              this.reductionMoney = re.reduction;
+              this.priceHandler();
+            }
+          });
+        } else {
+          this.reductionMoney = 0;
+          this.priceHandler();
+        }
+      },
+      deep: true,
+    },
+  },
+  computed: {
+    getPromoText() {
+      return (promo_title) => {
+        //在逗号增加换行符
+        if (!promo_title) return [];
+        return promo_title.split(';');
+      };
+    },
+    discountPrice() {
+      return this.$decimal.sub(this.priceTotal, this.reductionMoney).toFixed(2);
+    },
+  },
 };
 </script>
 
@@ -514,12 +595,18 @@ export default {
         text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
       }
       .promo_title {
-        max-height: 80rpx;
+        max-width: 240rpx;
         font-size: 20rpx;
         line-height: 40rpx;
         overflow: hidden;
         padding: 0rpx 0rpx;
         color: #dd524d;
+        display: flex;
+        flex-direction: column;
+        //超出省省略号
+        // white-space: nowrap; /* 不换行 */
+        // overflow: hidden; /* 隐藏超出的内容 */
+        // text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
       }
       .car_spec {
         color: #999999;
@@ -618,13 +705,15 @@ export default {
   z-index: 999;
   left: 0rpx;
   width: 100%;
-  height: 100rpx;
+  height: 120rpx;
   display: block;
   position: fixed;
   overflow: hidden;
   background: #ffffff;
   padding: 0rpx 35rpx;
   bottom: 140rpx;
+  display: flex;
+  align-items: center;
   .check_all_label {
     float: left;
     width: 120rpx;
@@ -654,15 +743,15 @@ export default {
   .price_box {
     float: left;
     width: 400rpx;
-    display: block;
+    display: flex;
+    flex-direction: column;
     color: #666666;
     font-size: 26rpx;
     text-align: right;
-    line-height: 100rpx;
     margin-right: 20rpx;
     .price_total {
       color: red;
-      font-size: 30rpx;
+      font-size: 36rpx;
     }
   }
   .to_order {
@@ -672,7 +761,6 @@ export default {
     display: block;
     color: #ffffff;
     font-size: 28rpx;
-    margin-top: 20rpx;
     line-height: 60rpx;
     padding: 0rpx 0rpx;
     text-align: center;

+ 19 - 3
pages/car/order.vue

@@ -27,7 +27,9 @@
             <view class="box_center">
               <view class="car_name">{{ item.name }}</view>
               <view class="car_spec">{{ item.spec }}</view>
-              <view v-if="item.promo_title" class="promo_title">{{ item.promo_title }}</view>
+              <view v-if="item.promo_title" class="promo_title">
+                <text v-for="(promoText, index) in getPromoText(item.promo_title)" :key="index">{{ promoText }}</text>
+              </view>
               <view class="car_price">
                 <text class="price">¥{{ item.price }}</text>
               </view>
@@ -569,6 +571,15 @@ export default {
       });
     },
   },
+  computed: {
+    getPromoText() {
+      return (promo_title) => {
+        //在逗号增加换行符
+        if (!promo_title) return [];
+        return promo_title.split(';');
+      };
+    },
+  },
 };
 </script>
 
@@ -642,7 +653,6 @@ export default {
     }
   }
   .car_item {
-    height: 170rpx;
     display: block;
     overflow: hidden;
     margin: 0rpx auto;
@@ -689,12 +699,18 @@ export default {
       }
 
       .promo_title {
-        max-height: 80rpx;
+        max-width: 240rpx;
         font-size: 20rpx;
         line-height: 40rpx;
         overflow: hidden;
         padding: 0rpx 0rpx;
         color: #dd524d;
+        display: flex;
+        flex-direction: column;
+        //超出省省略号
+        // white-space: nowrap; /* 不换行 */
+        // overflow: hidden; /* 隐藏超出的内容 */
+        // text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
       }
 
       .car_price {

+ 4 - 2
pages/product/index.vue

@@ -102,7 +102,9 @@
         <image src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/car.png" class="car_icon"></image>
       </navigator>
       <button class="show_order" v-if="!productInfo.hide_orderbtn" data-eventsync="true" @click="showSpecPopup(1)">{{ is_pay ? '立即购买' : '立即预约' }}</button>
-      <button :class="productInfo.hide_orderbtn ? 'show_car hide_orderbtn ' : 'show_car'" data-eventsync="true" @click="showSpecPopup(2)">加入购物车</button>
+      <button :class="productInfo.hide_orderbtn ? 'show_car hide_orderbtn ' : 'show_car'" data-eventsync="true" @click="showSpecPopup(2)">
+        {{ productInfo.hide_orderbtn ? '加入购物车  下单更优惠' : '加入购物车' }}
+      </button>
     </view>
     <view class="to_bottom"> --- 到底了 --- </view>
     <uni-popup ref="specPopup" :show="true" type="bottom" class="popup" background-color="#FFFFFF" @change="popupChange">
@@ -171,7 +173,7 @@
         <view class="order_price" v-if="specBtnType == 1 || specBtnType == 3">合计: ¥{{ priceTotal }}</view>
         <view class="order_btn">
           <button class="to_order" @click="createOrder()" v-if="specBtnType == 1" data-eventsync="true">{{ is_pay ? '购买' : '预约' }}</button>
-          <button class="to_car" @click="createCart()" v-if="specBtnType == 2" data-eventsync="true">加入购物车</button>
+          <button class="to_car" @click="createCart()" v-if="specBtnType == 2" data-eventsync="true">{{ productInfo.promo_title !== '' ? '加入购物车  下单更优惠' : '加入购物车' }}</button>
           <button class="to_order" @click="createOrder()" v-if="specBtnType == 3" data-eventsync="true">{{ is_pay ? '拼团购买' : '拼团预约' }}</button>
           <button class="to_order" @click="createOrder()" v-if="specBtnType == 4" data-eventsync="true">{{ productInfo.regiment_title }}{{ is_pay ? '购买' : '预约' }}</button>
         </view>

+ 8 - 8
pages/product/list.vue

@@ -99,17 +99,17 @@ export default {
     // 获取分享信息
     let shareObj = {
       title: '999智控终端平台\n药优惠 得积分 兑豪礼',
-      path: '/pages/index/index',
+      path: '/pages/product/list',
       imageUrl: '',
     };
     // 循环列表
-    for (let i in shareList) {
-      if (shareList[i].pages == 'pages/index/index') {
-        shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
-        shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
-        shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
-      }
-    }
+    // for (let i in shareList) {
+    //   if (shareList[i].pages == 'pages/product/list') {
+    //     shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
+    //     shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
+    //     shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
+    //   }
+    // }
     // 返回分享信息
     return shareObj;
   },

+ 10 - 8
pages/wait/index.vue

@@ -66,6 +66,7 @@ export default {
       toSelectedCity: false,
       // 是否是管理员
       isManager: false,
+      pageName: '',
     };
   },
   onLoad(param) {
@@ -80,6 +81,7 @@ export default {
     this.imgUrl = `https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/index/banner_${param.id}.png`;
     this.imagePage = ['101', '11', '1'].includes(param.id);
     this.requestParam.class_id = param.id;
+    this.pageName = param.name;
     uni.setNavigationBarTitle({
       title: param.name,
     });
@@ -90,17 +92,17 @@ export default {
     // 获取分享信息
     let shareObj = {
       title: '999智控终端平台\n药优惠 得积分 兑豪礼',
-      path: '/pages/index/index',
+      path: `/pages/wait/index?id=${this.requestParam.class_id}&name=${this.pageName}`,
       imageUrl: '',
     };
     // 循环列表
-    for (let i in shareList) {
-      if (shareList[i].pages == 'pages/index/index') {
-        shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
-        shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
-        shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
-      }
-    }
+    // for (let i in shareList) {
+    //   if (shareList[i].pages == 'pages/index/index') {
+    //     shareObj.path = shareList[i].path ? shareList[i].path : shareObj.path;
+    //     shareObj.title = shareList[i].title ? `999智控终端平台\n${shareList[i].title}` : shareObj.title;
+    //     shareObj.imageUrl = shareList[i].image_url ? shareList[i].image_url : shareObj.imageUrl;
+    //   }
+    // }
     // 返回分享信息
     return shareObj;
   },