| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <template>
- <view class="">
- <!-- #ifdef MP-WEIXIN-->
- <view class="">
- <u-navbar title="收银台"></u-navbar>
- </view>
- <!-- #endif -->
- <view class="shopInfo">
- <image :src="shopDetail.cover" mode=""></image>
- <text>{{shopDetail.name}}</text>
- </view>
- <view class="data">
- <text style="color: #000;">付款金额</text>
- <view class="price">
- <view class="input-bar center" @tap="show">
- <view class="icon center">¥</view>
- <view class="input" style="display: flex; align-items: center;">
- <view style="font-size: 80rpx;">{{filterMoney(orderAmount)}}</view>
- <view class="cusor"></view>
- </view>
- </view>
- </view>
- </view>
- <amountInput ref="amountInput" confirmText="付款" btnColor="#ff9900" placeholder="请输入交易金额" @change="change"
- @confirm="debouncePay"></amountInput>
- <u-modal v-model="payModalShow" confirmText="确认支付" cancelText="暂不支付" @confirm="toWXPay(pointPayType)" @cancel="$back()" :showCancelButton="true" confirm-color="#FF9447">
- <view class="center flex-direction text-df" style="padding: 30rpx 40rpx;">
- <view>您的积分可足额抵扣支付</view>
- <view class="padding-top-10">本次支付不会扣除您的现金</view>
- </view>
- </u-modal>
- <u-modal v-model="modalShow" :mask-close-able="true" :showCancelButton="true" @cancel="payOfh5"
- @confirm="jumpLDT" cancel-text="直接付款" confirm-color="#FF9447" confirmText="去联兑通支付"
- content="去联兑通小程序付款会有更多优惠哟~"></u-modal>
- </view>
- </template>
- <script>
- import amountInput from '@/components/amountInput/amountInput.vue';
- export default {
- components: {
- amountInput
- },
- data() {
- return {
- isFirstPay: true,
- orderAmount: '',
- payModalShow: false,
- modalShow: false,
- shopId: '',
- shopDetail: {},
- pointPayType:''
- }
- },
- async onLoad(options) {
- if (!this.$isEmpty(options.query)) {
- //h5跳转回小程序后重新赋值
- let params = options.query.split(";")
- this.shopId = params[0]
- this.orderAmount = params[1]
- } else {
- this.shopId = options.id
- }
- // #ifdef MP-WEIXIN
- //如果是新用户通过微信支付扫码进入此页面,跳回首页
- if (this.$isEmpty(this.vuex_userId)) {
- uni.reLaunch({
- url: "/pages/mine/mine?query=" + this.shopId + ";" + this.orderAmount
- })
- return
- }
- //如果用户信息为空,阻断
- let flag=await this.fetchUserDetail()
- if (!flag) {
- this.$dialog.showModal('用户信息获取失败',false).then(()=>{
- uni.reLaunch({
- url:"/pages/mine/mine"
- })
- })
- return
- }
- // #endif
- if (this.$isEmpty(this.shopId)) {
- this.$dialog.showModal('商户id不能为空', false).then(() => {
- uni.navigateBack()
- })
- return
- }
- this.fetchShopDetail()
- },
- methods: {
- //防抖支付
- debouncePay() {
- if (this.isFirstPay) {
- this.pay()
- this.isFirstPay = false
- } else {
- this.$u.debounce(this.pay, 500)
- }
- },
- //获取商户信息
- fetchShopDetail() {
- this.$api.shop.detail({
- id: this.shopId
- }).then(res => {
- if (this.$isEmpty(res.data)) {
- this.$dialog.showModal('获取不到商户信息', false).then(() => {
- uni.navigateBack({
- delta: 1
- })
- })
- } else {
- this.shopDetail = res.data
- }
- }).catch(err => {
- this.$dialog.showModal('获取不到商户信息', false).then(() => {
- uni.navigateBack({
- delta: 1
- })
- })
- })
- },
- //获取用户信息
- async fetchUserDetail(){
- let res=await this.$api.loginUser.detail({id:this.vuex_userId})
- if (this.$isEmpty(res.data)) {
- return false
- }else{
- return true
- }
- },
- show() {
- this.$refs.amountInput.show()
- },
- change(e) {
- if (!e) {
- this.orderAmount = 0
- } else {
- this.orderAmount = e
- }
- },
- filterMoney(value) {
- if (!value) {
- return ''
- } else {
- value = value.replace(/\$\s?|(,*)/g, '')
- return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
- }
- },
- async jumpLDT() {
- this.$dialog.showLoading('打开中..')
- let params = {
- path: "/pages/checkstand/index",
- query: "query=" + this.shopId + ";" + this.orderAmount
- }
- let res = await this.$api.wxApp.getGenerateScheme(params)
- if (!this.$isEmpty(res.data.openlink)) {
- location.href = res.data.openlink
- } else {
- location.href = "weixin://dl/business/?t=X2CyIQDbgtm"
- }
- uni.hideLoading()
- },
- async payOfh5() {
- let expireTime = this.$dateTime.getExpireTime(5)
- let params = {
- money: this.orderAmount,
- shopId: this.shopId,
- billsTitle: '用户微信扫码支付',
- expireTime
- }
- let resp = await this.$api.loginUser.payBeforeForNormal(params)
- let payObj = {
- orderType: this.$global.orderType.USER_PAY,
- orderId: resp.data.id
- }
- let res = await this.$api.pay.payOrderOfscanCode(payObj)
- if (!this.$isEmpty(res.data.qrCodeUrl)) {
- location.href = res.data.qrCodeUrl
- } else {
- this.$u.toast('支付失败')
- }
- },
- async pay() {
- if (!this.orderAmount.length || this.orderAmount == 0) {
- this.$u.toast('请输入交易金额')
- return
- }
- // #ifdef H5
- this.modalShow = true
- // #endif
- // #ifdef MP-WEIXIN
- let res= await this.getPointPayType()
- this.pointPayType=res.data
- if (this.pointPayType==this.$global.pointPayType.CHANNEL_ENOUGN
- || this.pointPayType==this.$global.pointPayType.CHANNEL_ZERO_RARE_ENOUGH
- || this.pointPayType==this.$global.pointPayType.CHANNEL_NOENOUGH_RARE_ENOUGH) {
- //可以足额支付
- this.payModalShow = true
- }else{
- this.toWXPay()
- }
- // #endif
- },
- //获取积分策略
- async getPointPayType(){
- let params={
- shopId: this.shopId,
- loginUserId: this.vuex_userId,
- money: this.orderAmount
- }
- let res=await this.$api.pay.getPointPayType(params)
- return res
- },
- async toWXPay() {
- let expireTime = this.$dateTime.getExpireTime(5)
- let params = {
- shopId: this.shopId,
- loginUserId: this.vuex_userId,
- money: this.orderAmount,
- billsTitle: '用户支付',
- expireTime,
- appId: this.$global.wxParams.APPID,
- openId: this.$cache.get('userInfo').openId,
- type: 1 ,//type: 1-用户扫商户收款码支付 2-商户扫用户付款码支付
- pointPayType:this.pointPayType
- }
- let resp = await this.$api.loginUser.payBefore(params)
- if (!resp.success) {
- this.$u.toast(resp.msg)
- return
- }
- if (resp.data.payAmount == 0) {
- this.$dialog.showModal('已使用积分抵扣成功', false).then(() => {
- uni.navigateBack({
- delta: 1
- })
- })
- return
- }
- let obj = {
- orderType: this.$global.orderType.USER_PAY,
- orderId: resp.data.id,
- payStatus: this.$global.payStatus.IS_WAIT
- }
- let res = await this.$api.pay.payOrder(obj)
- let prePayTn = JSON.parse(res.data.prePayTn)
- await this.$mpi.requestPayment(prePayTn)
- uni.navigateTo({
- url: "/pages/checkstand/order-res?orderId=" + resp.data.id
- })
- }
- }
- }
- </script>
- <style>
- page {
- background-color: #ffff;
- }
- </style>
- <style lang="scss" scoped>
- .shopInfo {
- margin: 60rpx 0 20rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- image {
- border-radius: 50%;
- width: 140rpx;
- height: 140rpx;
- }
- text {
- margin-top: 30rpx;
- font-size: 32rpx;
- }
- }
- .data {
- padding: 50rpx;
- display: flex;
- justify-content: flex-start;
- flex-direction: column;
- .price {
- &-icon {
- font-size: 40rpx;
- font-weight: 800;
- }
- }
- }
- .center {
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .input-bar {
- height: 150rpx;
- border-bottom: 1rpx solid #DDDDDD;
- .icon {
- width: 15%;
- font-size: 70rpx;
- font-weight: 900;
- height: 100%;
- }
- .input {
- width: 85%;
- height: 100%;
- overflow: hidden;
- font-size: 70rpx;
- }
- .cusor {
- margin-left: 10rpx;
- width: 6rpx;
- border-radius: 20rpx;
- height: 60%;
- background-color: #ff9900;
- animation: blink 1200ms infinite ease-in-out;
- }
- }
- @keyframes blink {
- from {
- opacity: 0;
- }
- }
- </style>
|