shish 1 месяц назад
Родитель
Сommit
e1ff776fa1
3 измененных файлов с 116 добавлено и 68 удалено
  1. 12 2
      hdApp/src/admin/ghs/pay.vue
  2. 5 0
      hdApp/src/api/purchase/index.js
  3. 99 66
      hdApp/src/pagesPurchase/wechatPay.vue

+ 12 - 2
hdApp/src/admin/ghs/pay.vue

@@ -133,13 +133,18 @@
 				}
 				this.id = id
 				this.salt = salt
+				if (this.option.amount && Number(this.option.amount) > 0) {
+					that.amount = parseFloat(Number(this.option.amount).toFixed(2))
+				}
 				getGhsData({id:id,salt:salt}).then(res=>{
 					if(res.code == 1){
 						if (res.data && res.data.ghs && !this.$util.isEmpty(res.data.ghs)){
 							that.ghsInfo = res.data.ghs
 							that.customInfo = res.data.custom?res.data.custom:[]
-							if(that.customInfo.remainDebtAmount && Number(that.customInfo.remainDebtAmount)>0){
-								that.amount = parseFloat(that.customInfo.remainDebtAmount)
+							if (!(that.option.amount && Number(that.option.amount) > 0)) {
+								if(that.customInfo.remainDebtAmount && Number(that.customInfo.remainDebtAmount)>0){
+									that.amount = parseFloat(that.customInfo.remainDebtAmount)
+								}
 							}
 							that.imgUrl = res.data.imgUrl ? res.data.imgUrl : ''
 						}
@@ -237,6 +242,11 @@
 				}				
 			},
 			paySuccess() {
+				if (this.option.from === 'wechatPay' && this.option.purchaseId) {
+					uni.setStorageSync('wechatPayNeedRefresh', '1')
+					uni.navigateBack({ delta: 1 })
+					return
+				}
 				this.$util.pageTo({url: '/admin/ghs/result?id='+this.id+'&salt='+this.salt,type: 2})
 			},
 			payFail() {

+ 5 - 0
hdApp/src/api/purchase/index.js

@@ -106,6 +106,11 @@ export const purchaseClearAliPay = async data => {
 	return https.get("/purchase/balance-pay", data);
 };
 
+/** 采购待支付:xhGhsCustom 净余额支付 */
+export const purchaseCustomBalancePay = async data => {
+	return https.post('/purchase/custom-balance-pay', data);
+};
+
 /** *
  * 延期支付
  */

+ 99 - 66
hdApp/src/pagesPurchase/wechatPay.vue

@@ -26,16 +26,22 @@
           <div class="order-num app-color-3" style="margin-top:12upx;">订单号 {{ orderSn || ''}}</div>
           <div v-if="remainPayTime > 0" class="order-num app-color-3" style="margin-top:18upx;font-size:26upx;"><span style="font-weight:bold;padding-right:8upx;">{{remainPayTime}}</span>秒后失效</div>
           <div v-else class="order-num app-color-3" style="margin-top:12upx;font-size:26upx;">订单已失效</div>
+          <view class="balance" v-if="Number(customNetBalance) > 0">
+            <text>余额</text>
+            <text class="app-size-30" style="color:#3385ff;font-weight:bold;margin-left:10upx;">¥{{ parseFloat(customNetBalance) }}</text>
+          </view>
         </block>
         <block>
         <!-- #ifdef MP-WEIXIN -->
         <div class="call-one-btn">
-          <view v-if="Number(balance) >= Number(realPrice)">
-            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" style="height:100upx;line-height:50upx;" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
-          </view>
-          <view v-else>
-            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" style="height:100upx;line-height:50upx;" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
-          </view>
+          <button
+            v-if="showBalancePay == 1"
+            class="button-com pay-balance"
+            :class="[remainPayTime > 0 ? 'blue' : 'default']"
+            :disabled="remainPayTime > 0 ? false : true"
+            @click="balancePay"
+          >余额支付</button>
+          <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" style="height:100upx;line-height:50upx;margin-top:50upx;" :disabled="remainPayTime >0 ? false : true" @click="wxPayFn">微信支付</button>
           <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" style="height:100upx;line-height:100upx;margin-top:50upx;padding:0;display:flex;align-items:center;justify-content:center;width:70%;margin-left:auto;margin-right:auto;" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'">挂账</button>
 
           <button class="button-com" @click="useAliPay()" :class="[remainPayTime >0 ? 'ali-btn green':'default']" style="height:100upx;line-height:100upx;margin-top:50upx;margin-bottom:40upx;padding:0;display:flex;align-items:center;justify-content:center;width:70%;margin-left:auto;margin-right:auto;" :disabled="remainPayTime > 0 ? false : true">支付宝付款</button>
@@ -48,8 +54,19 @@
         <!-- #endif -->
         <!-- #ifdef APP-PLUS -->
         <div class="call-one-btn">
+          <view class="balance" v-if="Number(customNetBalance) > 0" style="margin-bottom:30upx;">
+            <text>余额</text>
+            <text class="app-size-30" style="color:#3385ff;font-weight:bold;margin-left:10upx;">¥{{ parseFloat(customNetBalance) }}</text>
+          </view>
+          <button
+            v-if="showBalancePay == 1"
+            class="button-com pay-balance"
+            :class="[remainPayTime > 0 ? 'blue' : 'default']"
+            :disabled="remainPayTime > 0 ? false : true"
+            @click="balancePay"
+          >余额支付</button>
           <view>
-            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="appAliPayFn(0)">微信支付</button>
+            <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="appAliPayFn(0)" style="margin-top:50upx;">微信支付</button>
           </view>
           <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'ali-btn':'default']" :disabled="remainPayTime >0 ? false : true" @click="appAliPayFn(1)" style="margin-top:50upx;">支付宝支付</button>
           <button class="button-com pay-wx" :class="[remainPayTime >0 ? 'green':'default']" :disabled="remainPayTime >0 ? false : true" @click="debtPay" v-if="hasDebtPay === '1'" style="margin-top:50upx;">挂账</button>
@@ -63,7 +80,6 @@
         </block>
       </div>
     </div>
-    <keyboard-module :show="keyShow" @comfirm="hideKeyFn" @clickKey="clickKeyFn" :psdShow="true" :type="typeNum" @closeKey="closeKeyFn" />
     <alert-module>
       <div class="go-login-module">
         <div>请先设置支付密码!</div>
@@ -73,8 +89,7 @@
 </template>
 
 <script>
-import { purchaseBalancePay, purchaseDebtPay, purchaseWxPay,purchaseAliPay,getDetail } from "@/api/purchase";
-import keyboardModule from './components/keyboard'
+import { purchaseCustomBalancePay, purchaseDebtPay, purchaseWxPay,purchaseAliPay,getDetail } from "@/api/purchase";
 import { mapGetters } from "vuex";
 import wexinPay from "@/utils/pay/wxPay";
 import { postWxCode } from '@/api/mini'
@@ -82,24 +97,19 @@ import { updateMiniOpenId } from '@/api/admin'
 export default {
   name: "wechatPay",
   components: {
-    keyboardModule
   },
   data () {
     return {
       options: {},
-      type: '',
-      keyShow: false,
-      modalForm: {
-        payPassword: ''
-      },
-      psdKey: '',
       orderSn: '',
       realPrice: '',
-      typeNum: '1',
       pageId: '',
       remainPayTime:120,
       hasDebtPay:0,
       balance:0,
+      customNetBalance:0,
+      showBalancePay:0,
+      ghsSalt:'',
       info:[],
       hasRequestApi:false,
       needCheck:0,
@@ -116,6 +126,10 @@ export default {
   },
   onShow(){
     let that = this
+    if (uni.getStorageSync('wechatPayNeedRefresh') == '1') {
+      uni.removeStorageSync('wechatPayNeedRefresh')
+      that.init()
+    }
     if(that.needCheck == 1){
       that.needCheck = 0
       that.$util.confirmModal({content:'已付款成功?',okText:'是的',cancelText:'没有'},() => {
@@ -156,7 +170,10 @@ export default {
           this.realPrice = res.data.realPrice ? parseFloat(res.data.realPrice) : ''
           this.orderSn = res.data.orderSn
           that.hasDebtPay = res.data.hasDebtPay
-          that.balance = res.data.balance
+          that.balance = res.data.balance || 0
+          that.customNetBalance = res.data.customNetBalance != null ? res.data.customNetBalance : (res.data.balance || 0)
+          that.showBalancePay = res.data.showBalancePay == 1 ? 1 : 0
+          that.ghsSalt = res.data.ghsSalt || ''
           this.info = res.data
           that.remainPayTime = res.data.remainPayTime
           if(that.remainPayTime > 0){
@@ -368,61 +385,55 @@ export default {
       let that = this
       that.pageTo({ url: '/pagesPurchase/particulars?id=' + that.pageId, type: 2 })
     },
-    // 关闭键盘
-    closeKeyFn () {
-      this.keyShow = false
-    },
     getError () {
     },
     balancePay () {
-      let self = this
-      if(Number(this.balance) < Number(this.realPrice)){
-        this.$msg('余额不足')
-        return false;
+      let that = this
+      if (this.remainPayTime <= 0) {
+        this.$msg('订单已失效')
+        return false
       }
-      if (this.getLoginInfo.payPassword) {
-        self.keyShow = true
-      } else {
-        uni.showModal({
-          title: '',
-          content: '请先设置支付密码',
-          success: function (res) {
-            if (res.confirm) {
-              self.pageTo({
-                url: '/pagesPurchase/setPsd'
-              })
+      if (this.hasRequestApi) {
+        this.$msg('正在请求,请稍后再试')
+        return false
+      }
+      const available = Number(this.customNetBalance)
+      const needPay = Number(this.realPrice)
+      if (available < needPay) {
+        const shortfall = parseFloat((needPay - available).toFixed(2))
+        const ghsId = this.info.ghsId || 0
+        const salt = this.ghsSalt || ''
+        const purchaseId = this.option.id || this.id || ''
+        this.$util.confirmModal({ content: '余额不足,请先充值' }, () => {
+          that.pageTo({
+            url: '/admin/ghs/pay',
+            query: {
+              id: ghsId,
+              salt: salt,
+              amount: shortfall,
+              from: 'wechatPay',
+              purchaseId: purchaseId
             }
-          }
-        });
+          })
+        })
+        return false
       }
-    },
-    // 点击数字键盘
-    clickKeyFn (val) {
-      this.psdKey = val
-      console.log(this.psdKey)
-    },
-    // 点击了完成
-    hideKeyFn () {
-      uni.showLoading({title: '加载中',mask:true})
-      if (this.psdKey.length === 6) {
-        let data = {
-          orderSn: this.orderSn,
-          password: this.psdKey
-        }
-        purchaseBalancePay(data).then(res => {
-          //关闭加载中
+      this.$util.confirmModal({ content: '确认余额支付?' }, () => {
+        that.hasRequestApi = true
+        uni.showLoading({ title: '支付中', mask: true })
+        purchaseCustomBalancePay({ orderSn: that.orderSn }).then(res => {
           uni.hideLoading()
-          if(res.code == 1){
-            this.pageTo({
-              url: '/pagesPurchase/particulars?id=' + res.data.id,
-              type: 2
-            })
+          that.hasRequestApi = false
+          if (res.code == 1) {
+            const id = res.data.id || that.option.id
+            that.pageTo({ url: '/pagesPurchase/particulars?id=' + id, type: 2 })
           }
-        }).catch(err => {})
-      } else {
-        this.$msg('请输入六位数支付密码')
-      }
-    }
+        }).catch(() => {
+          uni.hideLoading()
+          that.hasRequestApi = false
+        })
+      })
+    },
   }
 };
 </script>
@@ -433,6 +444,24 @@ export default {
     border:1upx solid #3385ff;
     color:white;
   }
+  .pay-balance {
+    height: 100upx;
+    line-height: normal;
+    padding: 0;
+    box-sizing: border-box;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 70%;
+    margin-left: auto;
+    margin-right: auto;
+    margin-top: 20upx;
+  }
+  .pay-balance.blue {
+    background-color: #3385ff;
+    border: 1upx solid #3385ff;
+    color: #fff;
+  }
   .callback-wrap {
     padding-top:40upx;
     background-repeat: no-repeat;
@@ -473,6 +502,10 @@ export default {
           font-size: 32upx;
           margin-top:20upx;
         }
+        .button-com.pay-balance {
+          padding-top: 0;
+          padding-bottom: 0;
+        }
       }
     }
   }