谢杰标 2 tahun lalu
induk
melakukan
cff79edd63

+ 8 - 0
src/api/goods/index.js

@@ -102,3 +102,11 @@ export function getPointsRule(data) {
   });
 }
 
+// 新增核销订单
+export function orderIntegral(data) {
+  return request({
+    url: "/store/order/integral",
+    method: "post",
+    data,
+  });
+}

+ 3 - 2
src/directive/common/int.js

@@ -6,12 +6,13 @@ export default {
       if (!value) {
         return;
       }
-      const { max, set = 2 } = binding.value || {};
+      const { max, min, set = 2 } = binding.value || {};
       if (max && value > max) {
         value = max + "";
       }
       e.target.value = checkNum(value, set) || null;
-      el.firstElementChild.dispatchEvent(
+      const node = el.firstElementChild || el;
+      node.dispatchEvent(
         new Event("input", {
           bubbles: true,
         })

+ 4 - 4
src/directive/filter/index.js

@@ -1,7 +1,7 @@
 // 金额格式化
 export function formatPrice(price) {
-  return price?.toLocaleString(
-    "zh-CN",
-    (undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
-  );
+  return price?.toLocaleString("zh", {
+    minimumFractionDigits: 2,
+    maximumFractionDigits: 2,
+  });
 }

+ 89 - 24
src/views/components/index/payContain.vue

@@ -35,9 +35,10 @@
       <div class="input-ward fl">
         <input
-          @focus="$emit('changeFocusType', 'payPrice')"
+          @focus="$emit('changeFocusType', 'allPrice')"
           placeholder="请输入金额"
-          v-model="from.payPrice"
+          @input="$emit('checkValue', from.allPrice)"
+          v-model="from.allPrice"
           v-int
         />
       </div>
@@ -48,31 +49,38 @@
         <input
           type="text"
           v-model="from.discount"
+          v-int
+          @input="$emit('checkValue', from.discount)"
           @focus="$emit('changeFocusType', 'discount')"
         />
-        <span class="text-21f">({{ from.discount * getRules }}积分)</span>
+        <span class="mr1">元</span>
+        <span class="text-21f">({{ morePointsValue }}积分)</span>
       </div>
       <div class="integral-box c48">
         <div>
-          可用积分:{{ userInfo.pointsValue }}积分({{
-            (userInfo.pointsValue / getRules) | formatPrice
+          可用积分:{{ memberInfo.pointsValue }}积分({{
+            (memberInfo.pointsValue / getRules) | formatPrice
           }}元)
         </div>
         <div>
-          抵扣积分:100积分({{
-            (userInfo.pointsValue / getRules) | formatPrice
+          抵扣积分:{{ deductionIntegral }}积分({{
+            (deductionIntegral / getRules) | formatPrice
           }}元)
         </div>
         <div>
-          积分补差:100积分({{
-            (userInfo.pointsValue / getRules) | formatPrice
+          积分补差:{{ paidPointsValue }}积分({{
+            (paidPointsValue / getRules) | formatPrice
           }}元)
         </div>
         <div class="line"></div>
         <div class="c48">
-          优惠金额:<span class="discount-money">¥100.00</span>
+          优惠金额:<span class="discount-money"
+            >¥{{ (deductionIntegral / getRules) | formatPrice }}</span
+          >
+        </div>
+        <div class="c48">
+          实付金额:<span class="money">¥{{ payPrice | formatPrice }}</span>
         </div>
-        <div class="c48">实付金额:<span class="money">¥2243.00</span></div>
         <div class="fl c48">
           支付方式:
           <div
@@ -88,7 +96,7 @@
         </div>
       </div>
       <div class="btn">
-        <el-button type="danger">立即收款</el-button>
+        <el-button type="danger" @click="handelPay">立即收款</el-button>
       </div>
     </div>
   </container>
@@ -114,7 +122,7 @@ export default {
     type: {
       type: [Number, String],
     },
-    userInfo: {
+    memberInfo: {
       type: Object,
       default: () => {
         return {};
@@ -133,7 +141,7 @@ export default {
         },
         {
           lebel: "现金支付",
-          value: 4,
+          value: 3,
           src: require("../../../assets/images/icon_cash.png"),
         },
       ],
@@ -144,6 +152,47 @@ export default {
   mounted() {},
 
   methods: {
+    handelPay() {
+      if (this.list.length == 0) {
+        this.$message({
+          message: "请选择至少一个商品",
+          type: "warning",
+        });
+        return;
+      }
+      if (!this.memberInfo.userId) {
+        this.$message({
+          message: "请先扫描会员信息",
+          type: "warning",
+        });
+        return;
+      }
+      this.from.userId = this.memberInfo.userId;
+      if (this.active == 1) {
+        this.from.orderStatus = 0;
+        this.from.payStatus = 0;
+      } else {
+        this.from.orderStatus = 1;
+        this.from.payStatus = 2;
+      }
+      this.from.payType = this.active;
+      this.from.payPrice = this.payPrice;
+      this.from.deductionIntegral = this.deductionIntegral;
+      this.from.deductionMoney = (
+        this.deductionIntegral / this.getRules
+      ).toFixed(2);
+      this.from.integralRule = this.getRules;
+      this.from.goodsList = this.list.map((e) => {
+        return {
+          goodsId: e.goodsId,
+          goodsPrice: e.standPrice,
+          goodsReceived: e.specialPrice,
+          specialPrice: e.specialPrice,
+          payStatus: this.from.payStatus,
+        };
+      });
+      this.$emit("pay");
+    },
     del(index) {
       this.list.splice(index, 1);
     },
@@ -151,17 +200,29 @@ export default {
       this.$emit("update:type", type);
     },
   },
-  watch: {
-    list: {
-      handler(val) {
-        // console.log(val);
-      },
-      immediate: true,
-      deep: true,
-    },
-  },
   computed: {
     ...mapGetters(["getRules"]),
+    payPrice() {
+      return (
+        this.from.allPrice -
+        this.from.discount +
+        this.paidPointsValue / this.getRules
+      ).toFixed(2);
+    },
+    deductionIntegral() {
+      return this.memberInfo.pointsValue > this.morePointsValue
+        ? this.morePointsValue
+        : this.memberInfo.pointsValue;
+    },
+    paidPointsValue() {
+      return this.morePointsValue - this.deductionIntegral;
+    },
+    paidPrice() {
+      return this.formatPrice(this.paidPointsValue / this.getRules);
+    },
+    morePointsValue() {
+      return this.from.discount * this.getRules;
+    },
   },
 };
 </script>
@@ -249,6 +310,11 @@ export default {
     margin-bottom: 18px;
     .mr {
       margin: 0 8px 0 12px;
+      color: #666666;
+    }
+    .mr1 {
+      margin-left: 8px;
+      color: #666666;
     }
     .discount-text {
       color: #000;
@@ -261,7 +327,6 @@ export default {
       height: 36px;
       padding: 0 10px;
       border-radius: 6px;
-      color: #eb5757;
     }
   }
   .integral-box {

+ 8 - 8
src/views/components/index/scan.vue

@@ -6,17 +6,17 @@
           <el-input
             @focus="$emit('changeFocusType', 'cardSn')"
             placeholder="请扫描会员卡"
-            v-model="userInfo.cardSn"
+            v-model="memberInfo.cardSn"
             :max="8"
             v-int="{ set: 0 }"
           >
             <img src="../../../assets/images/icon_scan.png" slot="suffix" />
           </el-input>
         </div>
-        <template v-if="userInfo.userId">
+        <template v-if="memberInfo.userId">
           <div class="code">
             <vue-barcode
-              :value="userInfo.code"
+              :value="memberInfo.code"
               line-color="#222222"
               width="2"
               marginBottom="1"
@@ -29,11 +29,11 @@
           <button class="cancel" @click="$emit('cancel')">取消</button>
           <h1 class="contain-title">会员信息</h1>
           <div class="info">
-            <p>姓名:{{ userInfo.userName }}</p>
-            <p>会员卡号:{{ userInfo.code }}</p>
-            <p>手机号码:{{ userInfo.telphone }}</p>
+            <p>姓名:{{ memberInfo.userName }}</p>
+            <p>会员卡号:{{ memberInfo.code }}</p>
+            <p>手机号码:{{ memberInfo.telphone }}</p>
             <p>
-              剩余积分:<span class="text-21f">{{ userInfo.pointsValue }}</span>
+              剩余积分:<span class="text-21f">{{ memberInfo.pointsValue }}</span>
             </p>
           </div>
         </template>
@@ -56,7 +56,7 @@ import VueBarcode from "vue-barcode";
 export default {
   name: "SaasScan",
   props: {
-    userInfo: {
+    memberInfo: {
       type: Object,
       default: () => {
         return {};

+ 52 - 39
src/views/index.vue

@@ -7,17 +7,19 @@
       <el-col :span="8">
         <pay-contain
           @changeFocusType="changeFocusType"
+          @checkValue="checkValue"
+          @pay="pay"
           :list="selectedGoodList"
           :from="payForm"
-          :userInfo="userInfo"
+          :memberInfo="memberInfo"
         ></pay-contain>
       </el-col>
       <el-col :span="8">
         <scan
-          :userInfo="userInfo"
+          :memberInfo="memberInfo"
           @comfirm="comfirm"
-          @change="inputBoard"
-          @backspace="backspace"
+          @change="inputValue"
+          @backspace="inputValue"
           @changeFocusType="changeFocusType"
           @cancel="reset"
         ></scan>
@@ -32,11 +34,12 @@ import goodsList from "./components/index/goodsList.vue";
 import payContain from "./components/index/payContain.vue";
 import MenbetDlg from "./components/index/menbetDlg.vue";
 import { getUserDetail } from "@/api/index/index";
+import { orderIntegral } from "@/api/goods/index";
 export default {
   name: "Index",
   data() {
     return {
-      userInfo: {},
+      memberInfo: {},
       selectedGoodList: [],
       payForm: {},
       inputFocusType: "",
@@ -46,7 +49,7 @@ export default {
   created() {
     this.reset();
     setTimeout(() => {
-      this.userInfo.cardSn = '1000146902628081';
+      this.memberInfo.cardSn = "1000146902628081";
     }, 500);
   },
   methods: {
@@ -55,77 +58,83 @@ export default {
       this.payForm = {
         discount: 0,
         orderPrice: 0,
-        deductionIntegral: 20.0,
-        deductionMoney: 1,
-        compensationMoney: 0,
         payPrice: 0,
+        deductionIntegral: 0,
+        deductionMoney: 0,
+        compensationMoney: 0,
+        allPrice: 0,
+        integralRule: 0,
+        payStatus: 0,
+        orderStatus: 0,
+        payType: 0,
+        userId: "",
+        goodsList: [],
       };
       this.resetUser();
     },
     comfirm() {
       console.log("确认");
     },
-    backspace() {
+    inputValue(val) {
       const _t = this.inputFocusType;
       if (!_t) {
         return;
       }
-      const key = _t == "cardSn" ? "userInfo" : "payForm";
-      this[key][_t] = this[key][_t].substr(0, this[key][_t].length - 1);
+      const key = _t == "cardSn" ? "memberInfo" : "payForm";
+      if (val === undefined) {
+        val = this[key][_t].substr(0, this[key][_t].length - 1);
+      } else {
+        val = this[key][_t] + val.toString();
+      }
+      this.checkValue(val);
     },
-    inputBoard(val) {
+    checkValue(val) {
       const _t = this.inputFocusType;
       if (!_t) {
         return;
       }
-      val = val.toString();
-      this[_t == "cardSn" ? "userInfo" : "payForm"][_t] += val;
+      const originalValue = this.payForm[_t + "Backup"];
+      if (originalValue && val < originalValue) {
+        val = originalValue;
+      }
+      this[_t == "cardSn" ? "memberInfo" : "payForm"][_t] = val;
     },
     changeFocusType(type) {
       this.inputFocusType = type;
     },
     getUserDetail() {
-      getUserDetail(this.userInfo.cardSn)
+      getUserDetail(this.memberInfo.cardSn)
         .then((res) => {
           res.data.code = res.data.cardSn;
-          this.userInfo = res.data;
-          console.log(this.userInfo)
+          this.memberInfo = res.data;
         })
         .catch((e) => {
-          this.resetUser(this.userInfo.cardSn);
+          this.resetUser(this.memberInfo.cardSn);
         });
     },
     resetUser(cardSn = "") {
-      this.userInfo = { cardSn };
+      this.memberInfo = { cardSn };
     },
     pay() {
       let form = {
-        payType: 3,
+        orderType: 3,
         orderFrom: 7,
         status: 1,
-        payStatus: 0,
-        orderPrice: "",
-        goodsList: [
-          {
-            goodsId: 113828,
-            goodsPrice: 10.0,
-            goodsReceived: 10.0,
-            specialPrice: 10.0,
-            payStatus: 1,
-          },
-        ],
       };
+      orderIntegral({ ...this.payForm, ...form }).then((res) => {
+        console.log(res, 789);
+      });
     },
   },
   watch: {
-    "userInfo.cardSn": {
+    "memberInfo.cardSn": {
       handler(val) {
         if (val.length >= 16) {
           let cardSn = val.slice(0, 16);
-          if (this.userInfo.code === cardSn) {
+          if (this.memberInfo.code === cardSn) {
             return;
           }
-          this.userInfo.cardSn = cardSn;
+          this.memberInfo.cardSn = cardSn;
           this.getUserDetail();
         }
       },
@@ -134,14 +143,18 @@ export default {
     selectedGoodList: {
       handler(list) {
         let orderPrice = 0;
-        let payPrice = 0;
+        let allPrice = 0;
         list.forEach((item) => {
           orderPrice += item.standPrice;
-          payPrice += item.specialPrice;
+          allPrice += item.specialPrice;
         });
-        this.payForm.payPrice = payPrice;
+        allPrice += "";
+        const discount = parseInt(orderPrice - allPrice) + "";
+        this.payForm.allPrice = allPrice;
+        this.payForm.allPriceBackup = allPrice;
         this.payForm.orderPrice = orderPrice;
-        this.payForm.discount = parseInt(orderPrice - payPrice);
+        this.payForm.discount = discount;
+        this.payForm.discountBackup = discount;
       },
       immediate: true,
       deep: true,