pay1.vue 14 KB

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