pay1.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <view class="pay">
  3. <view class="pay-info">
  4. <view class="goods-info">
  5. <image class="goods-img" :src="createQuery.postImageUrl" mode=""></image>
  6. <view class="info">
  7. <view class="goods-name">
  8. {{createQuery.movieName}}
  9. </view>
  10. <view class="time">
  11. {{$u.timeFormat(createQuery.sessionBeginTime,'yyyy-mm-dd hh:MM')}}
  12. </view>
  13. <view class="desc">
  14. {{createQuery.seatNames}}
  15. </view>
  16. <view class="price">
  17. ¥{{totalPrice}} <view class="include">
  18. ({{createQuery.seatNames.split(',').length}}张电影票)
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="coupon">
  24. <view class="label">
  25. 优惠券
  26. </view>
  27. <view class="choose-coupon" :class="[payInfo.offset?'':'none']" @click="choose">
  28. <!-- {{payInfo.goodsCouponName}}-¥{{payInfo.offset}} -->
  29. {{payInfo.offset?('-¥' + payInfo.offset):'暂无可用'}}
  30. <image class="icon" src="../static/jiantou-icon.png" mode=""></image>
  31. </view>
  32. </view>
  33. <!-- <view class="explain">
  34. <view class="label">
  35. 优惠说明
  36. </view>
  37. <view class="right">
  38. 已优惠: <view class="red">¥{{payInfo.offset}} </view> 合计: <view class="red fs28">¥{{payInfo.price}}
  39. </view>
  40. </view>
  41. </view> -->
  42. </view>
  43. <view class="notice">
  44. 购买须知:取票码10-30分钟左右出票,请提前购票
  45. </view>
  46. <view class="btn-box">
  47. <view class="total-price">
  48. <view class="label">
  49. 合计:
  50. </view>
  51. <view class="price">
  52. ¥ {{totalPrice}}
  53. </view>
  54. <view class="originPrice">
  55. 原价¥ {{totalOriginPrice}}
  56. </view>
  57. </view>
  58. <button class="btn" type="default" :loading="loading" @click="creat">提交订单</button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import {
  64. calculate
  65. } from '@/api/order.js';
  66. import {create_order} from '@/api/movie.js'
  67. import {
  68. creatPayOrder,
  69. queryPayOrder,
  70. payDetails
  71. } from '@/api/payment.js'
  72. import guid from '@/utils/guid.js'
  73. export default {
  74. data() {
  75. return {
  76. isVisual:false,//是否是虚拟商品
  77. loading: false,
  78. info: {},
  79. realPay: {
  80. goodsCouponName: '', //优惠券名
  81. couponGoodsLogId: '', //优惠券id
  82. goodsId: '', //商品id
  83. price: '', //支付价格
  84. offset: '', //实际抵扣值
  85. discount: '', //优惠券值
  86. condition: '', //优惠条件
  87. originalPrice: '', //原价
  88. },
  89. price:0,//显示价格
  90. form:{
  91. account:''
  92. },
  93. rules: {
  94. 'account': {
  95. type: 'string',
  96. required: true,
  97. message: '请输入充值账号',
  98. trigger: ['blur', 'change']
  99. },
  100. },
  101. query: {
  102. "msgType": "wx.unifiedOrder",
  103. "orderDesc": "测试",
  104. "orderNo": "",
  105. "subOpenId": "",
  106. "userId": ""
  107. },
  108. createQuery:{
  109. "channel":"ZhongShu",
  110. "sessionId": "",//场次ID
  111. "cityId": "",//城市ID
  112. "cinemaId": "",//影院ID
  113. "movieId": "",//电影ID
  114. "cinemaCode": "",
  115. "movieCode": "",
  116. "cityName": "",//城市名称
  117. "cinemaName": "",//影院名称
  118. "hallName": "",//影厅名称
  119. "movieName": "",//电影名称
  120. "seatNames": "",//座位名称(多个用逗号分隔)
  121. "postImageUrl": "",
  122. "cinemaAddress": "",//影院地址
  123. "sessionBeginTime": "",//开场时间
  124. "sessionEndTime": "",
  125. "movieVersion": "",
  126. "userMobile": "",
  127. // "cinemaLat": 0,
  128. // "cinemaLng": 0,
  129. // "audience": "",
  130. // "entPara": "",
  131. originPrice:[],
  132. "buyModel": 0,
  133. "originalSeatIds": "",//座位id,多个座位用逗号分隔
  134. "sourceId": ""
  135. },
  136. // 支付信息
  137. payData: {
  138. }
  139. }
  140. },
  141. computed: {
  142. // 正式支付时的信息
  143. payInfo() {
  144. return {
  145. goodsCouponName: this.realPay.goodsCouponName || '', //优惠券名
  146. couponGoodsLogId: this.info.couponId, //优惠券id
  147. goodsId: this.realPay.goodsId || this.info.goodsId, //商品id
  148. price: this.realPay.price, //支付价格
  149. offset: this.realPay.offset, //实际抵扣值
  150. discount: this.realPay.discount || 0, //优惠券值
  151. condition: this.realPay.condition || '', //优惠条件
  152. originalPrice: this.realPay.originalPrice, //原价
  153. }
  154. },
  155. totalPrice(){
  156. let total = 0
  157. if(this.price.length){
  158. this.price.map(item=>{
  159. total+=item*10000
  160. })
  161. }
  162. return total/10000
  163. },
  164. totalOriginPrice(){
  165. let total = 0
  166. if(this.createQuery.originPrice.length){
  167. this.createQuery.originPrice.map(item=>{
  168. total+=item*10000
  169. })
  170. }
  171. return total/10000
  172. },
  173. },
  174. methods: {
  175. calculate(goodsId, shopId) {
  176. return new Promise((resolve, reject) => {
  177. calculate({
  178. couponId: this.info.couponId,
  179. "goodsId": goodsId,
  180. "shopId": shopId,
  181. "userId": JSON.parse(uni.getStorageSync('userInfo')).userId
  182. }).then(res => {
  183. if (res.state == 'Success') {
  184. this.realPay = res.content
  185. }
  186. })
  187. })
  188. },
  189. choose() {
  190. let that = this
  191. uni.navigateTo({
  192. url: './coupon?couponId=' + this.realPay.couponGoodsLogId,
  193. success: function(res) {
  194. // 通过eventChannel向被打开页面传送数据
  195. res.eventChannel.emit('pay', that.info)
  196. }
  197. })
  198. },
  199. //创建订单
  200. creat() {
  201. if (this.loading) return
  202. this.loading = true
  203. uni.showLoading({
  204. title: '支付中'
  205. })
  206. let that = this
  207. if (!this.payData.timeStamp) {
  208. let createQuery = JSON.parse(JSON.stringify(this.createQuery))
  209. createQuery.originPrice = Math.max.apply(null,createQuery.originPrice)
  210. create_order(createQuery).then(res => {
  211. this.loading = false
  212. if (res.state == 'Success') {
  213. // if (!this.payInfo.price) { //价格为0
  214. // uni.hideLoading()
  215. // uni.reLaunch({
  216. // url: '/my/order/index'
  217. // })
  218. // } else {
  219. this.query.orderNo = res.content.orderNo
  220. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  221. this.query.orderDesc = this.createQuery.movieName +'电影票'
  222. creatPayOrder(this.query).then(data => {
  223. that.payData = JSON.parse(data.content.miniPayRequest)
  224. if (data.content.miniPayRequest == null) return uni.hideLoading()
  225. uni.requestPayment({
  226. "provider": "wxpay",
  227. "orderInfo": that.payData,
  228. "appid": that.payData
  229. .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  230. "paySign": that.payData.paySign,
  231. "nonceStr": that.payData.nonceStr, // 随机字符串
  232. "package": that.payData.package, // 固定值
  233. // "prepayid": that.payData.package, // 统一下单订单号
  234. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  235. "signType": that.payData.signType, //签名算法
  236. success(msg) {
  237. console.log('msg', msg, res);
  238. queryPayOrder(that.query.orderNo).then(res1 => {
  239. if (res1.state == 'Success') {
  240. uni.hideLoading()
  241. uni.reLaunch({
  242. url: '/my/order/index'
  243. })
  244. }
  245. })
  246. },
  247. fail(e) {
  248. console.log('err', e);
  249. that.loading = false
  250. uni.hideLoading()
  251. uni.showToast({
  252. title: '取消支付',
  253. icon: 'fail'
  254. })
  255. // 取消支付后
  256. uni.reLaunch({
  257. url:'/my/order/movie/detail?id='+that.query.orderNo
  258. })
  259. // // 取消支付后,获取支付信息以备再次支付
  260. // payDetails(that.query.orderNo).then(r => {
  261. // if (r.state == 'Success') {
  262. // }
  263. // })
  264. }
  265. })
  266. })
  267. // }
  268. }
  269. })
  270. } else { // 取消支付后再次支付
  271. uni.requestPayment({
  272. "provider": "wxpay",
  273. "orderInfo": that.payData,
  274. "appid": that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  275. "paySign": that.payData.paySign,
  276. "nonceStr": that.payData.nonceStr, // 随机字符串
  277. "package": that.payData.package, // 固定值
  278. // "prepayid": that.payData.package, // 统一下单订单号
  279. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  280. "signType": that.payData.signType, //签名算法
  281. success(msg) {
  282. console.log('msg', msg);
  283. queryPayOrder(that.query.orderNo).then(res1 => {
  284. if (res1.state == 'Success') {
  285. uni.hideLoading()
  286. uni.reLaunch({
  287. url: '/my/order/index'
  288. })
  289. }
  290. })
  291. },
  292. fail(e) {
  293. that.loading = false
  294. uni.hideLoading()
  295. uni.showToast({
  296. title: '取消支付',
  297. icon: 'fail'
  298. })
  299. // 取消支付后,获取支付信息以备再次支付
  300. payDetails(that.query.orderNo).then(r => {
  301. if (r.state == 'Success') {
  302. that.payData = JSON.parse(r.content.miniPayRequest)
  303. }
  304. })
  305. console.log('err', e);
  306. }
  307. })
  308. }
  309. }
  310. },
  311. onReady() {
  312. },
  313. onLoad() {
  314. let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  315. this.query.userId = userInfo.userId
  316. let that = this
  317. const eventChannel = this.getOpenerEventChannel();
  318. eventChannel.on('pay', function(data) {
  319. that.createQuery.sessionId = data.sessionId
  320. that.createQuery.cityId = data.cityId
  321. that.createQuery.cinemaId = data.cinemaId
  322. that.createQuery.movieId = data.movieId
  323. that.createQuery.movieCode = data.movieCode
  324. that.createQuery.cityName = data.cityName
  325. that.createQuery.cinemaName = data.cinemaName
  326. that.createQuery.hallName = data.hallName
  327. that.createQuery.movieName = data.movieName
  328. that.createQuery.seatNames = data.seatNames
  329. that.createQuery.cinemaAddress = data.cinemaAddress
  330. that.createQuery.sessionBeginTime = data.sessionBeginTime
  331. that.createQuery.sessionEndTime = data.sessionEndTime
  332. that.createQuery.originalSeatIds = data.originalSeatIds
  333. that.createQuery.cinemaCode = data.cinemaCode
  334. that.createQuery.postImageUrl = data.postImageUrl
  335. that.createQuery.originPrice = data.originPrice
  336. that.price = data.price
  337. console.log('data', data);
  338. // that.calculate(that.info.goodsId, that.info.shopId)
  339. })
  340. }
  341. }
  342. </script>
  343. <style lang="scss">
  344. .pay {
  345. background: #F9F9F9;
  346. min-height: 100vh;
  347. padding-top: 20rpx;
  348. .shop-info {
  349. margin: 0 30rpx 20rpx;
  350. width: 690rpx;
  351. padding: 24rpx;
  352. box-sizing: border-box;
  353. background: #FFFFFF;
  354. border-radius: 16rpx 16rpx 16rpx 16rpx;
  355. .shop-name {
  356. color: #181818;
  357. font-size: 32rpx;
  358. }
  359. .address {
  360. color: #999999;
  361. font-size: 24rpx;
  362. margin-top: 12rpx;
  363. }
  364. }
  365. .notice{
  366. padding: 28rpx 30rpx;
  367. font-size: 24rpx;
  368. color: #FF4D3A;
  369. }
  370. .pay-info {
  371. margin: 0 30rpx;
  372. background: #FFFFFF;
  373. border-radius: 16rpx 16rpx 16rpx 16rpx;
  374. padding: 28rpx 24rpx;
  375. .goods-info {
  376. display: flex;
  377. margin-bottom: 30rpx;
  378. .goods-img {
  379. width: 160rpx;
  380. height: 200rpx;
  381. border-radius: 16rpx;
  382. }
  383. .info {
  384. margin-left: 20rpx;
  385. flex: 1;
  386. display: flex;
  387. flex-direction: column;
  388. justify-content: space-between;
  389. .goods-name {
  390. font-weight: 600;
  391. font-size: 28rpx;
  392. color: #222222;
  393. width: 400rpx;
  394. white-space: nowrap;
  395. overflow: hidden;
  396. text-overflow: ellipsis;
  397. }
  398. .time{
  399. font-weight: 300;
  400. font-size: 24rpx;
  401. color: #AAAAAA;
  402. }
  403. .desc{
  404. font-weight: 300;
  405. font-size: 24rpx;
  406. color: #AAAAAA;
  407. }
  408. .price{
  409. display: flex;
  410. font-size: 24rpx;
  411. color: rgba(255, 77, 58, 1);
  412. .include{
  413. color: #AAAAAA;
  414. margin-left: 10rpx;
  415. }
  416. }
  417. }
  418. }
  419. .coupon {
  420. display: flex;
  421. align-items: center;
  422. justify-content: space-between;
  423. border-top: 1rpx solid #F0F0F0;
  424. padding: 28rpx 0 0;
  425. .label {
  426. color: #222222;
  427. font-size: 28rpx;
  428. }
  429. .choose-coupon.none{
  430. color: #AAAAAA;
  431. }
  432. .choose-coupon {
  433. color: #FF4848;
  434. font-size: 28rpx;
  435. display: flex;
  436. align-items: center;
  437. .icon {
  438. width: 28rpx;
  439. height: 28rpx;
  440. display: block;
  441. margin-left: 10rpx;
  442. }
  443. }
  444. }
  445. .explain {
  446. display: flex;
  447. align-items: center;
  448. justify-content: space-between;
  449. padding-top: 28rpx;
  450. .label {
  451. color: #AAAAAA;
  452. font-size: 28rpx;
  453. }
  454. .right {
  455. display: flex;
  456. align-items: center;
  457. font-size: 24rpx;
  458. .red {
  459. font-weight: 500;
  460. color: #FF4848;
  461. margin: 0 10rpx;
  462. }
  463. .fs28 {
  464. font-size: 28rpx !important;
  465. }
  466. }
  467. }
  468. }
  469. .input-box{
  470. margin: 20rpx 30rpx;
  471. padding: 28rpx 24rpx;
  472. background: #FFFFFF;
  473. border-radius: 16rpx 16rpx 16rpx 16rpx;
  474. display: flex;
  475. align-items: center;
  476. justify-content: space-between;
  477. .label {
  478. color: #222;
  479. font-size: 28rpx;
  480. }
  481. .value {
  482. font-size: 28rpx;
  483. color: #AAAAAA;
  484. }
  485. }
  486. .btn-box {
  487. position: fixed;
  488. bottom: 0%;
  489. left: 0%;
  490. width: 100%;
  491. display: flex;
  492. align-items: center;
  493. justify-content: space-between;
  494. box-sizing: border-box;
  495. padding: 10rpx 30rpx env(safe-area-inset-bottom);
  496. border-top: 1rpx solid #EEEEEE;
  497. .total-price {
  498. display: flex;
  499. align-items: center;
  500. .label {
  501. color: #181818;
  502. font-size: 28rpx;
  503. }
  504. .price {
  505. font-size: 36rpx;
  506. font-weight: 800;
  507. color: #FF4848;
  508. margin-left: 10rpx;
  509. }
  510. .originPrice{
  511. font-size: 20rpx;
  512. color: #AAAAAA;
  513. margin-left: 10rpx;
  514. text-decoration: line-through;
  515. }
  516. }
  517. .btn {
  518. width: 280rpx;
  519. height: 80rpx;
  520. line-height: 80rpx;
  521. text-align: center;
  522. background: $uni-color-primary;
  523. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  524. border-radius: 46rpx 46rpx 46rpx 46rpx;
  525. font-weight: 800;
  526. color: #FFFFFF;
  527. font-size: 28rpx;
  528. margin: 0;
  529. }
  530. }
  531. }
  532. </style>