pay1.vue 12 KB

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