石广澎
2025-01-14 ae43c2bc000691cbb8e3881298284b9256b00142
pay/scanpay.vue
@@ -13,15 +13,9 @@
      <view class="u-p-24 bg-fff u-m-32 u-br-10">
        <view class="u-flex u-row-between">
          <view class="u-font-28 color-666">金额</view>
          <view @click="buyerNote='';showRemark=true;" class="remark">添加备注</view>
          <view v-if="!onlineId" @click="buyerNote='';showRemark=true;" class="remark">添加备注</view>
        </view>
        <view v-if="smoney" class="u-p-v-20 u-flex u-col-bottom u-border-bottom u-relative money-box">
          <view class="money-icon color-333 lh-1">¥</view>
          <view class="u-flex-1 u-flex u-col-bottom u-m-l-10" style="height: 80rpx;">
            <view class="money-num lh-1">{{ smoney }}</view>
          </view>
        </view>
        <view v-else class="u-p-v-20 u-flex u-col-bottom u-border-bottom u-relative money-box">
        <view class="u-p-v-20 u-flex u-col-bottom u-border-bottom u-relative money-box">
          <view class="money-icon color-333 lh-1">¥</view>
          <view class="u-flex-1 u-flex u-col-bottom u-m-l-10" style="height: 80rpx;">
            <view v-if="money" class="money-num lh-1">{{ money }}</view>
@@ -52,15 +46,20 @@
          </wx-open-launch-weapp>
        </view>
      </view>
      <block v-if="payWay==2&&shopInfo.userCouponFlag==1">
      <block v-if="useCoupon">
        <view class="bg-fff u-m-32 u-br-10">
          <view class="u-flex u-p-24 u-border-bottom">
            <!-- <u-icon name="coupon-fill" size="60rpx" color="#D31F28"></u-icon> -->
            <view class="u-font-32 u-flex-1 u-m-h-16">优惠券</view>
            <view @click="showCoupon" class="u-flex">
              <view v-if="couponInfo.id" class="tag-pain">
                满{{ parseFloat((couponInfo.thresholdValue / 100).toFixed(2)) }}元减{{ parseFloat((couponInfo.discount / 100).toFixed(2)) }}元
              </view>
              <block v-if="couponInfo.id">
                <view v-if="couponInfo.discountType==1" class="tag-pain">
                  满{{ $utils.fenToYuan(couponInfo.thresholdValue) }}元减{{ $utils.fenToYuan(couponInfo.discount) }}元券
                </view>
                <view v-if="couponInfo.discountType==2" class="tag-pain">
                  {{ $utils.accMul(couponInfo.discount, 10) }}折券
                </view>
              </block>
              <view v-else class="u-font-28 lh-1 u-tips-color">请选择</view>
              <u-icon class="u-m-l-10" name="arrow-right" color="#999" size="16"></u-icon>
            </view>
@@ -82,38 +81,45 @@
          </view>
        </view>
      </block>
      <button class="pay-it" @click="pay">付款</button>
      <button class="pay-it" @click="checkLocation">付款</button>
      <view v-if="bordShow" style="height: 470rpx"></view>
      <!-- 数字键盘 -->
      <u-popup zIndex="500" :show="bordShow" :overlay="false" @close="bordShow = false">
        <key-bord @changeMoney="changeMoney" :num.sync="money" @close="bordShow = false" @pay="pay"></key-bord>
        <key-bord @changeMoney="changeMoney" :num.sync="money" @close="bordShow = false" @pay="checkLocation"></key-bord>
      </u-popup>
      <!-- 优惠券弹窗 -->
      <u-popup v-if="payWay==2" mode="bottom" :closeable="true" :show="couponShow" @close="couponShow = false" :round="10">
        <view class="u-font-32 color-333 u-text-center u-p-t-30">优惠券</view>
        <view v-if="checkCoupon.id" class="choose-coupon">
          已选择优惠券1张,共抵扣¥{{ parseFloat((checkCoupon.discount / 100).toFixed(2)) }}
          已选择优惠券1张,可抵扣¥{{ discount1 }}
        </view>
        <scroll-view scroll-y class="u-p-30 coupon-list">
          <u-loadmore v-if="!couponList" status="loading" />
          <u-loadmore v-if="!couponList" status="loading"/>
          <u-empty v-else-if="couponList.length===0" mode="coupon" icon="/static/no_coupon.png" text="暂无优惠券可用!"></u-empty>
          <block v-else>
            <view @click="clickCoupon(item)" class="u-m-b-24 u-flex coupon" v-for="(item, index) in couponList" :key="index">
              <view style="color: #D31F28;" class="u-p-h-28">
                <view class="font-bold">
              <view class="num-box">
                <view v-if="item.discountType==1" class="font-bold" style="color: #D31F28;">
                  <text class="u-font-36">¥</text>
                  <text class="money">{{ parseFloat(item.discount / 100) }}</text>
                  <text class="money">{{ $utils.fenToYuan(item.discount) }}</text>
                </view>
                <view class="u-font-24 u-m-t-20">满{{ parseFloat(item.thresholdValue / 100) }}元使用</view>
                <view v-if="item.discountType==2" class="font-bold" style="color: #D31F28;">
                  <text class="money">{{ $utils.accMul(item.discount, 10) }}</text>
                  <text class="u-font-36">折</text>
                </view>
                <view v-if="item.orderMax" class="u-font-24 u-m-t-20">低于{{ $utils.fenToYuan(item.orderMax) }}元可用</view>
                <view v-else-if="item.thresholdValue" class="u-font-24 u-m-t-20">满{{ $utils.fenToYuan(item.thresholdValue) }}元可用</view>
                <view v-else class="u-font-24 u-m-t-20">无门槛</view>
              </view>
              <view class="butt"></view>
              <view class="u-p-30 u-flex-1 u-flex">
                <view class="u-flex-1">
                  <view class="u-font-28 color-333 u-line-2">{{ item.name }}</view>
                  <view class="u-font-32 color-333 u-line-2">{{ item.name }}</view>
                  <view class="u-font-22 color-999 u-m-t-20">
                    有效期至:{{ $u.timeFormat(item.outTime, 'yyyy-mm-dd hh:MM') }}
                  </view>
                </view>
                <u-icon v-if="item.id==checkCoupon.id" name="checkmark-circle-fill" color="#D31F28" size="20">
                <u-icon v-if="item.id==checkCoupon.id" name="checkmark-circle-fill" color="#D31F28" size="24">
                </u-icon>
              </view>
            </view>
@@ -140,11 +146,13 @@
<script>
import {
  config,
  ACCESSTOKEN
  ACCESSTOKEN,
  CHECK_LOCATION
} from 'common/config.js';
import {
  queryShopByCid,
  queryShopByShopId,
  queryShopByOnlineId,
  queryShopByActQrId,
  userLogin,
  queryUseSweepPayCoupon,
  getWechatConfigInfo,
@@ -157,27 +165,31 @@
export default {
  data() {
    return {
      smoney: '',
      tips: '该商户暂未开通支付功能',
      payLoading: false,
      loading: false,
      remark: '',
      buyerNote: '',
      showRemark: false,
      UNIONID: null,
      payWay: this.$utils.getPlat(), //2 维信 5支付宝
      payWay: this.$utils.getPlat(), //2 微信公众号 3微信小程序 5支付宝 15云闪付
      cid: '', //码牌id  C扫B静态码时有
      activityQrcodeId: '', //动态收款码  C扫B动态码时有
      shopId: '', //商户id  C扫B动态码时有
      bordShow: false, // 显示键盘
      orderId: '',
      onlineId: '', //冀优邮线上订单id
      orderId: '', //
      shopInfo: {
        cusid: '',
        shopName: '',
        logoImage: '',
        checkLocation: false,
        scanFlag: -1,
        useScoreFlag: -1, //商铺是否可用积分 0否 1是
        userCouponFlag: -1, //商铺是否可用优惠券 0否 1是
      },
      lat: '', //纬度
      lng: '', //经度
      money: '', // 金额
      token: null,
      isNew: false, // 是否新用户,新用户查询不到积分和银行卡
@@ -197,43 +209,65 @@
    };
  },
  computed: {
    useCoupon() {
      if(this.onlineId){
        return this.couponInfo.id!=''
      }
      return this.payWay==2&&this.shopInfo.userCouponFlag==1
    },
    discount1() {
      if(!(this.money || 0)||!this.checkCoupon.id){
        return 0
      }
      if (this.checkCoupon.discountType == 1) {
        const num = this.$utils.fenToYuan(this.checkCoupon.discount)
        return parseFloat(num);
      }
      const dis = 1 - parseFloat(this.checkCoupon.discount)
      const dic = Math.floor(this.$utils.accMul(this.money,100) * dis)
      return this.$utils.fenToYuan(dic).toFixed(2);
    },
    discount() {
      let num = 0;
      num = (this.couponInfo.discount / 100).toFixed(2);
      return parseFloat(num);
      if(!(this.money || 0)||!this.couponInfo.id){
        return 0
      }
      if (this.couponInfo.discountType == 1) {
        const num = this.$utils.fenToYuan(this.couponInfo.discount)
        return parseFloat(num);
      }
      const dis = 1 - parseFloat(this.couponInfo.discount)
      const dic = Math.floor(this.$utils.accMul(this.money,100) * dis)
      return this.$utils.fenToYuan(dic).toFixed(2);
    },
    payMoney() {
      let num = 0;
      num = Number((this.money || 0) * 100) - this.couponInfo.discount;
      num = num > 0 ? (num / 100).toFixed(2) : '0.00';
      return parseFloat(num);
      if(this.discount===0||!Number(this.money || 0)){
        return 0
      }
      const num = this.$utils.accMul(this.money,100) - this.$utils.accMul(this.discount,100);
      return this.$utils.fenToYuan(num).toFixed(2);
    }
  },
  onLoad(opt) {
    uni.setStorageSync('CID', opt.cid)
    uni.setStorageSync('SHOPID', opt.shopId)
    uni.setStorageSync('SMONEY', opt.smoney)
    uni.setStorageSync('AQCI', opt.activityQrcodeId)
    this.UNIONID = uni.getStorageSync('UNIONID') || null
    this.isNew = uni.getStorageSync('IS_NEW')
    if (opt.smoney) {
      this.smoney = opt.smoney
      this.money = opt.smoney
    } else {
      this.bordShow = true
    }
    if (opt.activityQrcodeId) {
      this.activityQrcodeId = opt.activityQrcodeId
      // this.getOrderInfo()
    }
    if (opt.shopId) {
      this.shopId = opt.shopId
      this.init()
    }
    if (opt.cid) {
      this.bordShow = true
      this.cid = opt.cid
      this.init()
    } else if (opt.onlineId) {
      this.onlineId = opt.onlineId
      this.init()
    } else if (opt.activityQrcodeId) {
      this.activityQrcodeId = opt.activityQrcodeId
      this.shopId = opt.shopId
      this.init()
    } else {
      this.shopInfo.scanFlag = 0
      this.loading = false
      this.tips = '请扫描冀驿付码牌!'
    }
    if (opt.code || opt.auth_code || opt.userAuthCode) {
      let params = {
        code: opt.code
@@ -309,14 +343,14 @@
      uni.setStorageSync(ACCESSTOKEN, res.token)
      uni.setStorageSync('IS_NEW', res.isNew)
      this.isNew = res.isNew
      if (!res.isNew && !uni.$u.test.isEmpty(this.money)) {
      if (!this.onlineId&&!res.isNew && !uni.$u.test.isEmpty(this.money)) {
        this.queryUseSweepPayCoupon()
      }
    },
    /*授权unionid*/
    toRegister() {
      if (this.payWay == 2) {
        const redirect_uri = encodeURIComponent(`${config.webURL}/pay/scanpay?cid=${this.cid || ''}&shopId=${this.shopId || ''}&activityQrcodeId=${this.activityQrcodeId || ''}&smoney=${this.smoney || ''}`)
        const redirect_uri = encodeURIComponent(`${config.webURL}/pay/scanpay?cid=${this.cid || ''}&activityQrcodeId=${this.activityQrcodeId || ''}&onlineId=${this.onlineId||''}`)
        uni.clearStorageSync()
        window.location.href =
            `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${config.wx_appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`
@@ -338,6 +372,10 @@
    },
    // 展示键盘
    showBord() {
      if(this.onlineId||this.activityQrcodeId){
        this.bordShow = false;
        return
      }
      this.bordShow = true;
    },
    init() {
@@ -357,10 +395,16 @@
          cid: this.cid
        }
      }
      if (this.shopId) {
        api = queryShopByShopId
      if (this.activityQrcodeId) {
        api = queryShopByActQrId
        params = {
          shopId: this.shopId
          activityQrcodeId: this.activityQrcodeId
        }
      }
      if (this.onlineId) {
        api = queryShopByOnlineId
        params = {
          onlineId: this.onlineId
        }
      }
      //获取商铺信息
@@ -373,6 +417,20 @@
          res.logoImage = config.baseURL + res.logoImage
        }
        this.shopInfo = res
        if(res.total){
          this.money = this.$utils.fenToYuan(res.total)
        }
        if(this.onlineId){
          this.money = this.$utils.fenToYuan(res.totalPrice)
          if(res.couponId){
            this.couponInfo = {
              id: res.couponId,
              thresholdValue: res.thresholdValue,
              discount: res.discount,
              discountType: res.discountType,
            }
          }
        }
      }).catch((err) => {
        clearTimeout(timer)
        this.shopInfo.scanFlag = 0
@@ -391,18 +449,74 @@
            timestamp: res.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.noncestr, // 必填,生成签名的随机串
            signature: res.signature, // 必填,签名
            jsApiList: ['hideAllNonBaseMenuItem'], // 必填,需要使用的JS接口列表
            jsApiList: ['hideAllNonBaseMenuItem','getLocation'], // 必填,需要使用的JS接口列表
            openTagList: ['wx-open-launch-weapp'] //可选,需要使用的开放标签列表
          });
          wx.ready(function () {
          wx.ready( ()=> {
            wx.hideAllNonBaseMenuItem();
          })
        })
      }
      if(this.payWay == 5){
        ap.hideOptionButton();
      }
    },
    apGetLocation(callback){
      ap.getLocation((res)=> {
        console.log('apGetLocation',res)
          if(res.latitude){
            this.lat = parseFloat(res.latitude).toFixed(6); // 纬度,浮点数,范围为90 ~ -90
            this.lng = parseFloat(res.longitude).toFixed(6); // 经度,浮点数,范围为180 ~ -180。
            if(callback) callback()
          }else{
            uni.showModal({
              title: '提示',
              content: "获取地理位置失败,无法进行支付!请打开手机定位权限并同意获取位置后重试!",
              confirmText: '重新授权',
              cancelText: '退出',
              success: ret=>{
                if(ret.confirm){
                  this.apGetLocation(callback)
                }else{
                  this.clickDone()
                }
              }
            })
          }
        })
    },
    wxGetLocation(callback){
      wx.getLocation({
        type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
        complete:  (res)=> {
          if(res.errMsg==="getLocation:ok"){
            this.lat = parseFloat(res.latitude).toFixed(6); // 纬度,浮点数,范围为90 ~ -90
            this.lng = parseFloat(res.longitude).toFixed(6); // 经度,浮点数,范围为180 ~ -180。
            if(callback) callback()
          }else{
            uni.showModal({
              title: '提示',
              content: "获取地理位置失败,无法进行支付!请打开手机定位权限并同意获取位置后重试!",
              confirmText: '重新授权',
              cancelText: '退出',
              success: ret=>{
                if(ret.confirm){
                  this.wxGetLocation(callback)
                }else{
                  this.clickDone()
                }
              }
            })
          }
        }
      });
    },
    // 获取会员相关信息
    showCoupon() {
      if (this.UNIONID) {
      if(this.onlineId){
        return
      }
      if (this.UNIONID||this.payWay==5) {
        if (uni.$u.test.isEmpty(this.money)) {
          uni.$u.toast('请输入金额!')
          return
@@ -415,15 +529,24 @@
      }
    },
    //获取用户优惠券
    queryUseSweepPayCoupon(){
    queryUseSweepPayCoupon() {
      //2 微信 5支付宝 15云闪付
      const applyPayWayStr = {
        2: 1,
        5: 2,
        15: 3
      }
      queryUseSweepPayCoupon({
        params: {
          applyPayWayStr: this.payWay,
          score: 0,
          applyPayWayStr: applyPayWayStr[this.payWay],
          cusid: this.shopInfo.id,
          money: Number(this.money * 100),
          money: this.$utils.accMul(this.money,100),
        }
      }).then(res => {
        this.couponList = res
      }).catch(() => {
        this.couponList = []
      })
    },
    //选择优惠券
@@ -444,6 +567,26 @@
      this.couponInfo = this.checkCoupon;
      this.couponShow = false;
    },
    checkLocation(){
      if(!CHECK_LOCATION){
        this.pay()
        return
      }
      if (uni.$u.test.isEmpty(this.money)) {
        uni.$u.toast('请输入金额!')
        return
      }
      if(!this.lat){
        if(this.payWay == 2){
          this.wxGetLocation(this.pay)
        }
        if(this.payWay == 5){
          this.apGetLocation(this.pay)
        }
      }else{
        this.pay()
      }
    },
    //确认支付
    pay() {
      if (uni.$u.test.isEmpty(this.money)) {
@@ -451,21 +594,31 @@
        return
      }
      this.bordShow = false
      if (this.payLoading) return
      this.payLoading = true
      // 金额 this.money
      uni.showLoading()
      const params = {
      uni.showLoading({
        title: '下单中',
        mask: true
      })
      let params = {
        money: this.$utils.accMul(this.money,100),
        shopId: this.shopInfo.id,
        payWay: this.payWay,
        buyerNote: this.buyerNote,
        score: 0,
        couponDetailId: this.couponInfo.id
        couponDetailId: this.couponInfo.id,
        lat: this.lat,
        lng: this.lng
      }
      if (this.activityQrcodeId) {
        params.activityQrcodeId = this.activityQrcodeId
      }
      if (this.cid) {
        params.money = Number(this.money * 100)
        params.shopId = this.shopInfo.id
        params.cid = this.cid
      }
      if (this.onlineId) {
        params.onlineId = this.onlineId
      }
      //生成订单
      saveOrder(params).then(res => {
@@ -480,11 +633,15 @@
          if (this.payWay == 5) {
            this.aliPay(res.paymentData)
          }
          if (this.payWay == 15) {
            this.aliPay(res.paymentUrl)
          }
        } catch (e) {
          //TODO handle the exception
          console.error(e);
        }
      }).catch(() => {
        this.payLoading = false
        uni.hideLoading()
      })
    },
@@ -501,6 +658,7 @@
              "paySign": res.paySign //微信签名
            },
            (res) => {
              this.payLoading = false
              if (res.err_msg == "get_brand_wcpay_request:ok") {
                // 使用以上方式判断前端返回,微信团队郑重提示:
                //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
@@ -518,6 +676,7 @@
      ap.tradePay({
        tradeNO: res.tradeNO
      }, (res) => {
        this.payLoading = false
        if (res.resultCode == 9000) {
          uni.navigateTo({
            url: `/pay/paySuccess?orderId=${this.orderId}&youHuiInfo=${JSON
@@ -536,11 +695,18 @@
      });
    },
    closeOrder() {
      uni.showLoading({
        title: '取消支付中',
        mask: true
      })
      closeOrder({
        params: {
          id: this.orderId,
        }
      }).then(res => {
        uni.hideLoading()
      }).catch(()=>{
        uni.hideLoading()
      })
    }
  }
@@ -569,7 +735,6 @@
.money {
  font-size: 40rpx;
  color: #333;
}
@@ -734,7 +899,10 @@
  position: relative;
  overflow: hidden;
}
.num-box{
  width: 200rpx;
  text-align: center;
}
.choose-coupon {
  margin: 32rpx 32rpx 0;
  border-radius: 10rpx;
@@ -746,7 +914,7 @@
.coupon-list {
  box-sizing: border-box;
  height: calc(80vh - 44px);
  height: calc(60vh - 44px);
}