orderPayment.vue 11 KB
Newer Older
1
<template>
潘永坪's avatar
潘永坪 committed
2 3 4 5
	<view>
		<view class="middle" v-show="orderList.length>0">
			<view class="middle-wrap">
				<view  v-for="item of orderList" :key="item.id" class="product">
6 7 8 9 10 11 12 13 14 15 16 17
					<view>
						<text> {{ item.merchantName }}{{ item.productName }}</text>

						<text>
							<text style="font-size:24rpx;">¥</text>{{ item.unitPrice }} <text>x</text> {{ item.orderNum }}
							<text style="margin-top:10rpx;font-size:22rpx;display:block;color:#f45803;" v-if="item.depositReceived"> 押金:{{ item.depositReceived }} </text>
						</text>
					</view>
					<view class="coupon" v-if="item.pdDiscountMoney">
						<text></text> <text> <text style="font-size:24rpx;"></text>{{ item.pdDiscountMoney }} </text>
					</view>
				</view>
潘永坪's avatar
潘永坪 committed
18 19 20 21 22 23
				<view class="middle-money">
					<view> 实际支付 </view>
					<view>
						<text style="font-size:28rpx;">¥</text>
						{{ pdOrderMoney }} 
					</view>
24
				</view>
潘永坪's avatar
潘永坪 committed
25
				<view class="middle-image">
26 27 28 29 30 31 32 33 34 35
					<!-- #ifdef MP-WEIXIN -->
					<image src="@/static/img/orderPayment/weixin.png" style="width:70rpx;height:62rpx;" /> <view> 微信支付 </view>
					<!-- #endif -->

					<!-- #ifdef MP-ALIPAY -->
					<image src="@/static/img/orderPayment/alipayLogo.png" style="width:70rpx;height:62rpx;" /> <view> 支付宝支付 </view>
					<!-- #endif -->
					<image src="@/static/img/orderPayment/input.png" style="width:32rpx;height: 32rpx;" />
				</view>
			</view>
潘永坪's avatar
潘永坪 committed
36
		</view>
潘永坪's avatar
潘永坪 committed
37 38 39 40
		<view v-show="errorMessage1||errorMessage2">
			错误1:{{errorMessage1}}
			错误2:{{errorMessage2}}
		</view>
潘永坪's avatar
潘永坪 committed
41
		<view class="bottom">
潘永坪's avatar
潘永坪 committed
42 43 44 45 46 47
			<view class="bottom-left">
				<text>实付款 </text>
				<text v-show="pdOrderMoney"> 
					<text style="font-size: 28rpx;">¥</text>
					{{pdOrderMoney}}
				</text>
48
			</view>
潘永坪's avatar
潘永坪 committed
49 50
			<view class="bottom-right">
				<u-icon name="chat" size="40" @click="makePhone()"></u-icon>
51 52
				<text @click="goPay()" :style="{ background: background }">去支付</text>
			</view>
潘永坪's avatar
潘永坪 committed
53
		</view>
54 55 56 57
	</view>
</template>

<script>
58 59 60
export default {
  data() {
    return {
61
      orderList:[], //订单列表
62 63
      pdOrderMoney: '', //实际总价
      totalMoney: '', //原价总价
潘永坪's avatar
潘永坪 committed
64 65
      errorMessage1: '', //错误信息1,接口成功返回的错误信息
      errorMessage2: '', //错误信息2,接口失败返回的错误信息
66
      payType: '', //支付类型
潘永坪's avatar
潘永坪 committed
67 68 69 70 71
      timeStamp: '', //微信支付参数
      nonceStr: '',//微信支付参数
      package: '',//微信支付参数
      signType: '',//微信支付参数
      paySign: '',//微信支付参数
72 73 74 75
      orderInfo: '', //支付宝订单号
      background: '', //去支付的背景颜色
      orderId: '', //订单Id
      openid: '', //用户Id
潘永坪's avatar
潘永坪 committed
76
      afterBuyUrl:'/pages/my/order/electronicTicket/electronicTicket', //支付成功后地址跳转,默认单票跳详情
潘永坪's avatar
潘永坪 committed
77 78
      ifyukuaiCode: '' ,//是否是渝快码跳入,渝快码跳入需要在H5端另外走流程
      albumOrderdetail:'',//是否跳影集订单详情
79 80 81 82 83 84 85 86 87 88
    }
  },
  onLoad(option) {
    //#ifdef MP-WEIXIN
    this.payType = 42
    //#endif

    //#ifdef MP-ALIPAY
    this.payType = 33
    //#endif
89
    this.orderId=this.$commonjs.getKey(option,'orderId')
90
    this.ifyukuaiCode = option.ifyukuaiCode||''
潘永坪's avatar
潘永坪 committed
91
    this.albumOrderdetail=option.albumOrderdetail||''
92 93 94 95 96 97 98 99 100 101 102 103
    this.openid = uni.getStorageSync('openid') || ''
    if (this.openid) {
      this.initDetail()
    } else {
      this.login() //极个别手机从公众号跳转回来没有openid,再次获取openid
    }
  },
  methods: {
    login() {
      //---登录
      uni.getProvider({
        service: 'oauth',
潘永坪's avatar
潘永坪 committed
104
        success:proRes=>{
105 106
          uni.login({
            provider: proRes.provider[0],
潘永坪's avatar
潘永坪 committed
107
            success: res=>{
108 109 110 111 112 113 114 115 116
              if (res.code) {
                let source = ''
                if (proRes.provider[0] == 'weixin') {
                  source = 3
                } else if (proRes.provider[0] == 'alipay') {
                  source = 4
                }
                let data = {
                  code: res.code,
潘永坪's avatar
潘永坪 committed
117
                  source, //微信小程序3,支付宝小程序4
潘永坪's avatar
潘永坪 committed
118 119 120 121
                  appid:uni.getStorageSync('appid')||''
                }
                if(uni.getStorageSync('enterOptions').query){
								  data.companyId=uni.getStorageSync('enterOptions').query.companyId||''
122
                }
潘永坪's avatar
潘永坪 committed
123 124 125 126 127 128
                this.$request('wechat/wx/getUserInfoByCode', data).then(res => {
                  if (res.code == '00') {
                    this.openid = res.data.openid
                    uni.setStorageSync('openid', this.openid)
                    this.initDetail()
                  } else {
129
                    uni.showToast({
潘永坪's avatar
潘永坪 committed
130
                      title: res.message+uni.getStorageSync('appid'),
131 132
                      icon: 'none'
                    })
潘永坪's avatar
潘永坪 committed
133 134 135 136 137
                  }
                }).catch(err => {
                  uni.showToast({
                    title: '登录失败',
                    icon: 'none'
138
                  })
潘永坪's avatar
潘永坪 committed
139
                })
140 141 142 143 144 145
              }
            }
          })
        }
      })
    },
潘永坪's avatar
潘永坪 committed
146 147 148 149 150 151 152
    //---拨打电话
    makePhone() {
		  uni.makePhoneCall({
		    phoneNumber:'400-072-0368'
		  })
    },
    //---初始化产品信息,以及获取支付需要的参数
153 154 155 156 157 158
    initDetail() {
      let data = {
        orderId: this.orderId, //订单Id
        userId: this.openid, //用户Id
        payType: this.payType //支付类型
      }
潘永坪's avatar
潘永坪 committed
159 160 161
      uni.showLoading({
        mask:true
      })
162 163
      this.$request('orderc/order/findOrderInfo', data).then(res => {
        if (res.code == '00') {
潘永坪's avatar
潘永坪 committed
164
          if(this.albumOrderdetail==1){
潘永坪's avatar
潘永坪 committed
165 166
            //主要跳转影集订单详情,暂时是前端写死
            this.afterBuyUrl='/pages/album/albumOrderdetail/albumOrderdetail'
潘永坪's avatar
潘永坪 committed
167
          }else{
潘永坪's avatar
潘永坪 committed
168 169 170 171
            if(res.data.orderType=='10'){
						  //组合票和联票跳订单列表
						  this.afterBuyUrl='/pages/my/order/orderList/orderList'
            }
潘永坪's avatar
潘永坪 committed
172
          }
173 174 175 176 177 178 179 180 181 182
          //支付参数开始
          this.timeStamp = res.data.timestamp
          this.nonceStr = res.data.noncestr
          this.package = res.data.package
          this.signType = res.data.signType
          this.paySign = res.data.sign
          //支付宝入参
          this.orderInfo = res.data.payInfo || ''
          //支付参数结束
          this.pdOrderMoney = res.data.pdOrderMoney
潘永坪's avatar
潘永坪 committed
183
          if (this.pdOrderMoney == 0 && res.data.subOrderType == -1){
184
            uni.navigateTo({
潘永坪's avatar
潘永坪 committed
185
              url: '/pages/payment/paySuccess/paySuccess?orderId=' + this.orderId+'&afterBuyUrl=' + this.afterBuyUrl + '&ifyukuaiCode=' + this.ifyukuaiCode
186 187
            })
          }
潘永坪's avatar
潘永坪 committed
188
          this.errorMessage1 = res.data.errorMessage
189
          this.totalMoney = res.data.totalMoney
190
          this.orderList = res.data.orderList||[]
潘永坪's avatar
潘永坪 committed
191 192
          if (this.orderList.length==0||res.data.orderPageShowFlag==0) {
            this.orderList=[]
193 194 195 196 197 198 199 200 201
            this.orderList.push({
              merchantName:res.data.merchantName,
              productName:res.data.productName,
              unitPrice:res.data.unitPrice,
              orderNum:res.data.orderNum,
              depositReceived:res.data.depositReceived,
              pdDiscountMoney:res.data.pdDiscountMoney,
              endPlayDate:res.data.endPlayDate
            })
202 203 204 205 206 207
          }
        } else {
          uni.showToast({
            title: res.message,
            icon: 'none'
          })
潘永坪's avatar
潘永坪 committed
208
          this.errorMessage2=res.message
209 210 211
        }
      })
    },
潘永坪's avatar
潘永坪 committed
212
    //----去支付
213
    goPay() {
潘永坪's avatar
潘永坪 committed
214
      if (this.errorMessage1) {
215
        uni.showToast({
潘永坪's avatar
潘永坪 committed
216
          title: this.errorMessage1,
217 218 219 220 221 222
          icon: 'none'
        })
        return
      }
      this.background = '#E6E6E6'
      setTimeout(() => {
潘永坪's avatar
潘永坪 committed
223
        this.background = '#3688FF'
224 225
      }, 1000)
      // #ifdef MP-WEIXIN
潘永坪's avatar
潘永坪 committed
226 227 228 229 230 231 232
      if(!this.timeStamp||!this.nonceStr||!this.package||!this.signType||!this.paySign){
        uni.showToast({
				  title: '缺少支付参数',
				  icon: 'none'
        })
        return
      }
233 234 235 236 237 238 239
      uni.requestPayment({
        provider: 'wxpay',
        timeStamp: this.timeStamp,
        nonceStr: this.nonceStr,
        package: this.package,
        signType: this.signType,
        paySign: this.paySign,
潘永坪's avatar
潘永坪 committed
240
        success:res=>{
241
          uni.navigateTo({
潘永坪's avatar
潘永坪 committed
242
            url: '/pages/payment/paySuccess/paySuccess?orderId=' + this.orderId+'&afterBuyUrl=' + this.afterBuyUrl + '&ifyukuaiCode=' + this.ifyukuaiCode
243 244 245 246 247 248 249 250 251 252 253 254
          })
        },
        fail: function(err) {
          uni.showToast({
            title: err.errMsg,
            icon: 'none'
          })
        }
      })
      //#endif

      // #ifdef MP-ALIPAY
潘永坪's avatar
潘永坪 committed
255 256 257 258 259 260 261
      if(!this.orderInfo){
			  uni.showToast({
				  title: '缺少支付参数',
				  icon: 'none'
			  })
			  return
      }
262 263 264
      uni.requestPayment({
        provider: 'alipay', // 服务提供商 支付宝支付: alipay   微信支付: wxpay
        orderInfo: this.orderInfo, // 支付宝订单号
潘永坪's avatar
潘永坪 committed
265
        success: res=> {
266
          uni.navigateTo({
潘永坪's avatar
潘永坪 committed
267
            url: '/pages/payment/paySuccess/paySuccess?orderId=' + this.orderId+'&afterBuyUrl=' + this.afterBuyUrl + '&ifyukuaiCode=' + this.ifyukuaiCode
268 269 270 271 272 273 274 275 276 277 278 279 280
          })
        },
        fail: function(err) {
          uni.showToast({
            title: err.errMsg,
            icon: 'none'
          })
        }
      })
      // #endif
    }
  }
}
281 282 283
</script>

<style>
284 285 286 287 288 289 290
.bigBox {
	height: 100%;
	background: #fafafc;
}
.middle {
	padding: 30rpx 24rpx 0 24rpx;
}
潘永坪's avatar
潘永坪 committed
291
.middle-wrap {
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	padding: 10rpx 24rpx 20rpx 24rpx;
	background: #ffffff;
	border-radius: 20rpx;
	box-shadow: 0 0 15rpx #e6e6e8;
}
.product {
	border-bottom: 1px solid #e5e5e5;
	padding: 25rpx 0;
}
.product view {
	color: #000000;
	padding-left: 10rpx;
	display: flex;
	align-items: center;
	box-sizing: border-box;
}
.product view text:first-child {
	flex: 1;
}
.product view text:nth-child(2) {
	color: #666666;
	font-size: 28rpx;
	text-align: right;
}
.product view.coupon {
	color: #f9690e;
	margin-top: 10rpx;
}
.product view.coupon text {
	font-size: 30rpx;
}
潘永坪's avatar
潘永坪 committed
323
.middle-money {
324 325 326 327 328 329 330 331 332
	height: 120rpx;
	color: #000000;
	border-bottom: 1px solid #e5e5e5;
	padding: 25rpx 0 25rpx 10rpx;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	justify-content: space-between;
}
潘永坪's avatar
潘永坪 committed
333
.middle-money view:nth-child(2) {
334 335 336
	font-size: 24rpx;
	color: #666666;
}
潘永坪's avatar
潘永坪 committed
337
.middle-money view:nth-child(2) {
338 339 340 341
	font-size: 36rpx;
	color: #f9690e;
	font-weight: bold;
}
潘永坪's avatar
潘永坪 committed
342
.middle-image {
343 344 345 346
	margin-top: 50rpx;
	display: flex;
	align-items: center;
}
潘永坪's avatar
潘永坪 committed
347
.middle-image > image:first-child {
348 349
	margin: 0 20rpx 0 10rpx;
}
潘永坪's avatar
潘永坪 committed
350
.middle-image > view {
351 352 353 354 355 356 357 358 359 360 361 362
	flex: 1;
}
.bottom {
	position: fixed;
	bottom: 0;
	height: 100rpx;
	background: #ffffff;
	border-top: 1px solid #e5e5e5;
	width: 100%;
	display: flex;
	align-items: center;
}
潘永坪's avatar
潘永坪 committed
363
.bottom-left {
364 365 366 367
	border-right: 1px solid #cccccc;
	padding-left: 40rpx;
	width: 40%;
}
潘永坪's avatar
潘永坪 committed
368
.bottom-left text:nth-child(2) {
369 370 371 372 373
	font-size: 40rpx;
	color: #f9690e;
	margin-left: 10rpx;
	font-weight: bold;
}
潘永坪's avatar
潘永坪 committed
374 375
.bottom-right {
	padding-left:30rpx;
376 377
	display: flex;
	width: 60%;
潘永坪's avatar
潘永坪 committed
378
	padding-right:30rpx;
379 380
	align-items: center;
}
潘永坪's avatar
潘永坪 committed
381
.bottom-right text:nth-child(2) {
382 383 384 385 386
	flex: 1;
	height: 70rpx;
	display: inline-block;
	text-align: center;
	line-height: 70rpx;
潘永坪's avatar
潘永坪 committed
387
	background: #3688FF;
388 389 390 391
	color: #ffffff;
	margin-left: 30rpx;
	border-radius: 20rpx;
	font-size: 32rpx;
潘永坪's avatar
潘永坪 committed
392
	font-weight: bold;
393
}
394
</style>