Просмотр исходного кода

排到可选优惠的金额计算

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

+ 6 - 19
mall/src/components/app-coupon-sel.vue

@@ -11,7 +11,6 @@
               >会员身份({{ shopUser.userAsset.member }}级 {{ shopUser.userAsset.discount }}折)</span>
             </radio>
           </div>
-          <!-- <div class="app-price app-size-28">-¥{{ totalDiscountPrice }}</div> -->
           <div class="app-price app-size-28"></div>
         </div>
         <!-- 优惠券优惠 -->
@@ -50,7 +49,7 @@
                   <div class="coupon-message">
                     <div class="app-color-2">优惠券</div>
                     <div>适用:全品类</div>
-                    <div>有效至:2020-10-11</div>
+                    <div>有效至:{{ item.deadline | formatTime('YYYY-MM-DD') }}</div>
                   </div>
                 </div>
               </div>
@@ -64,7 +63,6 @@
 
 <script>
 import { mapGetters } from "vuex";
-// api
 import { userDiscount } from "@/api/member";
 import { getShopUser } from "@/utils/auth";
 export default {
@@ -88,7 +86,7 @@ export default {
   },
   computed: {
     ...mapGetters({ shopUser: "getShopUser" }),
-    // 可使用优惠列表
+    //可使用优惠列表
     discountArr() {
       let newArr = [];
       if (this.$util.isEmpty(this.data)) {
@@ -106,10 +104,7 @@ export default {
     },
     // 优惠金额
     totalDiscountPrice() {
-      console.log(this.price);
       if (this.price) {
-        // console.log(this.$util.floatFormat((this.price - this.price * this.shopUser.userAsset.discount / 10), 1))
-        // return this.$util.floatFormat((this.price - this.price * this.shopUser.userAsset.discount / 10), 1)
         return (
           (this.price * 1000000 -
             ((this.price * this.shopUser.userAsset.discount) / 10) * 1000000) /
@@ -120,18 +115,8 @@ export default {
       }
     }
   },
-  mounted() {
-    // this.init()
-    // getShopUser()
-    // if (this.discountArr.indexOf('member') > -1) {
-    // 	this.selIndex = 1
-    // 	this.memberCheck = true
-    // }
-  },
+  mounted() {},
   methods: {
-    mInit() {
-      // this._getUserDiscount()
-    },
     async _getUserDiscount() {
       let arr = [];
       await userDiscount().then(res => {
@@ -142,6 +127,8 @@ export default {
     },
     checkChange(e) {
       this.selIndex = e.detail.value;
+      console.log('radio')
+      console.log(this.selIndex)
       if (this.selIndex == 1) {
         this.couponId = 0;
       }
@@ -218,4 +205,4 @@ export default {
   background-color: $mainColor !important;
   border-color: $mainColor !important;
 }
-</style>
+</style>

+ 1 - 1
mall/src/components/app-delivery.vue

@@ -160,7 +160,7 @@
           placeholder-style="color:#ccc"
           class="tui-input"
           name="remark"
-          placeholder="请填写备注内容(选填)"
+          placeholder="请填写备注(选填)"
         />
       </tui-list-cell>
     </div>

+ 7 - 12
mall/src/pages/goods/detail.vue

@@ -83,8 +83,9 @@ import SelPopup from "./components/sel-popup.vue";
 import GoLogin from "@/pages/home/components/go-login.vue";
 import AppShareMask from "@/components/module/app-share-mask";
 import { share } from "@/mixins";
-// api
+import { mapGetters } from "vuex";
 import { getDetail } from "@/api/goods";
+import { getShopUser } from "@/utils/auth";
 export default {
   name: "goods-detail",
   mixins: [share],
@@ -111,19 +112,10 @@ export default {
   },
   onLoad(option) {},
   mounted() {
-    // this.$util.getCheckLogin().then(res => {
-    // 	if (!res) return false
-    // this.init()
-    // })
+   
   },
   computed: {
-    // imgNormal() {
-    // 	if (!this.$util.isEmpty(this.data)) {
-    // 		return this.data.imgList[0]
-    // 	} else {
-    // 		return ''
-    // 	}
-    // }
+   ...mapGetters({ shopUser: "getShopUser" })
   },
   methods: {
     init() {
@@ -153,6 +145,9 @@ export default {
         };
         this.jweixinFn(shareParams);
       });
+
+      getShopUser(true)
+
     },
     async _getDetail() {
       await getDetail({ id: this.option.id }).then(res => {

+ 31 - 39
mall/src/pages/order/buy.vue

@@ -48,7 +48,7 @@
 
           <div class="shop-prompt">
             <div>总计</div>
-            <div>¥{{ totalPrice() }}</div>
+            <div>¥{{ totalPrice }}</div>
           </div>
         </div>
       </div>
@@ -56,11 +56,7 @@
       <div class="module-com discount-wrap" v-if="!$util.isEmpty(discountArr)">
         <div class="module-tit">可选优惠</div>
         <div class="module-det">
-          <app-coupon-sel
-            ref="couponSel"
-            :price="goodsInfo.price * option.goodsNum"
-            :discountArr="['member', 'coupon']"
-          />
+          <app-coupon-sel ref="couponSel" :price="totalPrice" :discountArr="['member', 'coupon']" />
         </div>
       </div>
       <app-trademark />
@@ -70,7 +66,7 @@
           <span>应付款</span>
           <span class="app-price">
             <span>¥</span>
-            <span class="app-size-40">{{ mayPayAmount() }}</span>
+            <span class="app-size-40">{{ mayPayAmount }}</span>
           </span>
         </div>
         <button class="button-com red" formType="submit">确认</button>
@@ -79,7 +75,9 @@
     <!-- 弹窗 -->
     <alert-module :show="showAlert" @click="hideAlert" @cancel="hideAlert">
       <div class="alt-content" v-if="!$util.isEmpty(orderShop)">
-        <div><span class="app-price">{{ `${orderShop.freight.first}公里`}}</span>内免运费</div>
+        <div>
+          <span class="app-price">{{ `${orderShop.freight.first}公里`}}</span>内免运费
+        </div>
         <div>
           <span>超过每增加1公里运费加</span>
           <span class="app-price">{{ `${orderShop.freight.add}元` }}</span>
@@ -128,7 +126,6 @@ export default {
       ],
       showAlert: false,
       // form
-      // 初始form
       form: {
         anonymity: "0", // 是否匿名 0不 1要
         sendDistance: "", // 配送距离,根据腾讯js进行计算
@@ -141,39 +138,33 @@ export default {
       },
       // 自提form
       mentionForm: {
-        bookMobile: ''
+        bookMobile: ""
       },
       discountArr: false,
       // 运费
       freightPrice: 0,
       goodsNum: 1,
       //显示的距离
-      showDistance:0
+      showDistance: 0,
+      totalPrice: 0,
+      mayPayAmount: 0
     };
   },
   mounted() {},
   computed: {
     ...mapGetters({ orderShop: "getOrderShop" }),
-    ...mapGetters({ shopUser: "getShopUser" }),
-    //计算总金额
-    totalPrice() {
-      return function() {
-        let totalPrice =
-          this.goodsInfo.price * this.goodsNum + this.freightPrice;
-        return totalPrice.toFixed(2);
-      };
-    },
-    //计算应付款
-    mayPayAmount(){
-      return function() {
-        let totalPrice =
-          this.goodsInfo.price * this.goodsNum + this.freightPrice;
-        return totalPrice.toFixed(2);
-      };
+    ...mapGetters({ shopUser: "getShopUser" })
+  },
+  watch: {
+    //运费变化则总金额和应付金额变化
+    freightPrice(newVal) {
+      let price = this.goodsInfo.price * this.goodsInfo.buyNum + newVal;
+      this.totalPrice = price.toFixed(2);
+      this.mayPayAmount = price.toFixed(2);
     }
   },
   onLoad(option) {
-    this.goodsNum = option.goodsNum
+    //已有手机号则自动补全
     this.$set(this.mentionForm, "bookMobile", this.shopUser.mobile);
   },
   created() {},
@@ -186,10 +177,9 @@ export default {
         : goodsInfo.price;
 
       getOrderShop().then(() => {
-        this.$refs.couponSel._getUserDiscount().then(status => {
-          console.log('discount'+status)
-          this.discountArr = status;
-        })
+        this.$refs.couponSel._getUserDiscount().then(discountData => {
+          this.discountArr = discountData;
+        });
       });
 
       getShopUser();
@@ -197,11 +187,13 @@ export default {
       goodsInfo.buyNum = this.option.goodsNum;
       this.goodsInfo = goodsInfo;
 
+      this.totalPrice = goodsInfo.price * this.option.goodsNum;
+      this.mayPayAmount = this.totalPrice;
+
       // 初始化上个页面带入的值
       Object.keys(this.form).forEach((i, index) => {
         this.form[i] = this.option[i];
       });
-
     },
     // 生成订单
     createOrderFn() {
@@ -242,14 +234,14 @@ export default {
     anonymityChange(e) {
       this.form.anonymity = this.form.anonymity == 1 ? 0 : 1;
     },
-    // 选择地址 
+    // 选择地址
     changeAddress(e) {
       // 计算客户距离和运费
-      let lat = this.$refs.appDelivery.region.latitude
-      let long = this.$refs.appDelivery.region.longitude
-      getUserDistance({lat:lat,lng:long}).then(res => {
-        this.freightPrice = res.data.fee
-        this.showDistance = res.data.showDistance
+      let lat = this.$refs.appDelivery.region.latitude;
+      let long = this.$refs.appDelivery.region.longitude;
+      getUserDistance({ lat: lat, lng: long }).then(res => {
+        this.freightPrice = res.data.fee;
+        this.showDistance = res.data.showDistance;
       });
     },
     // 表单验证