pay.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <template>
  2. <view class="pay">
  3. <view class="pay-info">
  4. <view class="goods-info">
  5. <image class="goods-img" :src="info.goodsImg" mode=""></image>
  6. <view class="info">
  7. <view class="goods-name">
  8. {{info.goodsName}}
  9. </view>
  10. <view class="num">
  11. {{info.goodsDescribe}}
  12. </view>
  13. <view class="price">
  14. ¥{{info.price}}
  15. </view>
  16. </view>
  17. </view>
  18. <!-- <view class="coupon">
  19. <view class="label">
  20. 优惠券
  21. </view>
  22. <view class="choose-coupon none" @click="choose">
  23. 暂无可用
  24. <image class="icon" src="@/static/jiantou-icon.png" mode=""></image>
  25. </view>
  26. </view> -->
  27. </view>
  28. <view class="input-box">
  29. <view class="label">
  30. 充值账号
  31. </view>
  32. <view class="value">
  33. {{createQuery.rechargeAccount}}
  34. </view>
  35. </view>
  36. <view class="btn-box">
  37. <view class="total-price">
  38. <view class="label">
  39. 合计:
  40. </view>
  41. <view class="price">
  42. ¥ {{info.price}}
  43. </view>
  44. </view>
  45. <button class="btn" type="default" :loading="loading" @click="creat">提交订单</button>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. calculate
  52. } from '@/api/order.js';
  53. import {
  54. creatVirtualOrder
  55. } from '@/api/goods.js'
  56. import {
  57. creatPayOrder,
  58. queryPayOrder,
  59. payDetails
  60. } from '@/api/payment.js'
  61. import guid from '@/utils/guid.js'
  62. export default {
  63. data() {
  64. return {
  65. isVisual:false,//是否是虚拟商品
  66. loading: false,
  67. info: {},
  68. createQuery:{
  69. "accountType": 0,
  70. "extendParameter": "",
  71. "number": 1,
  72. "outTradeNo": "",
  73. "productId": 0,
  74. "rechargeAccount": ""
  75. },
  76. query: {
  77. "msgType": "wx.unifiedOrder",
  78. "orderDesc": "测试",
  79. "orderNo": "",
  80. "subOpenId": "",
  81. "userId": ""
  82. },
  83. // 支付信息
  84. payData: {
  85. }
  86. }
  87. },
  88. computed: {
  89. },
  90. methods: {
  91. choose() {
  92. let that = this
  93. uni.navigateTo({
  94. url: '/pay/coupon?couponId=' + this.info.couponId,
  95. success: function(res) {
  96. // 通过eventChannel向被打开页面传送数据
  97. res.eventChannel.emit('pay', that.info)
  98. }
  99. })
  100. },
  101. //创建订单
  102. creat() {
  103. if (this.loading) return
  104. this.loading = true
  105. uni.showLoading({
  106. title: '支付中'
  107. })
  108. let that = this
  109. if (!this.payData.timeStamp) {
  110. creatVirtualOrder(this.createQuery).then(res => {
  111. this.loading = false
  112. if (res.state == 'Success') {
  113. // if (!this.info.realPrice) { //价格为0
  114. // uni.hideLoading()
  115. // uni.reLaunch({
  116. // url: '/my/order/index'
  117. // })
  118. // } else {
  119. this.query.orderNo = res.content.orderNo
  120. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  121. this.query.orderDesc = this.info.goodsName
  122. creatPayOrder(this.query).then(data => {
  123. that.payData = JSON.parse(data.content.miniPayRequest)
  124. if (data.content.miniPayRequest == null) return uni.hideLoading()
  125. uni.requestPayment({
  126. "provider": "wxpay",
  127. "orderInfo": that.payData,
  128. "appid": that.payData
  129. .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  130. "paySign": that.payData.paySign,
  131. "nonceStr": that.payData.nonceStr, // 随机字符串
  132. "package": that.payData.package, // 固定值
  133. // "prepayid": that.payData.package, // 统一下单订单号
  134. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  135. "signType": that.payData.signType, //签名算法
  136. success(msg) {
  137. console.log('msg', msg, res);
  138. queryPayOrder(that.query.orderNo).then(res1 => {
  139. if (res1.state == 'Success') {
  140. uni.hideLoading()
  141. uni.reLaunch({
  142. url: '/my/order/index'
  143. })
  144. }
  145. })
  146. },
  147. fail(e) {
  148. console.log('err', e);
  149. that.loading = false
  150. uni.hideLoading()
  151. uni.showToast({
  152. title: '取消支付',
  153. icon: 'fail'
  154. })
  155. // 取消支付后
  156. uni.reLaunch({
  157. url:'/my/order/detail?id='+that.query.orderNo
  158. })
  159. // // 取消支付后,获取支付信息以备再次支付
  160. // payDetails(that.query.orderNo).then(r => {
  161. // if (r.state == 'Success') {
  162. // that.payData = JSON.parse(r.content.miniPayRequest)
  163. // }
  164. // })
  165. }
  166. })
  167. })
  168. // }
  169. }
  170. })
  171. } else { // 取消支付后再次支付
  172. uni.requestPayment({
  173. "provider": "wxpay",
  174. "orderInfo": that.payData,
  175. "appid": that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  176. "paySign": that.payData.paySign,
  177. "nonceStr": that.payData.nonceStr, // 随机字符串
  178. "package": that.payData.package, // 固定值
  179. // "prepayid": that.payData.package, // 统一下单订单号
  180. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  181. "signType": that.payData.signType, //签名算法
  182. success(msg) {
  183. console.log('msg', msg);
  184. queryPayOrder(that.query.orderNo).then(res1 => {
  185. if (res1.state == 'Success') {
  186. uni.hideLoading()
  187. uni.reLaunch({
  188. url: '/my/order/index'
  189. })
  190. }
  191. })
  192. },
  193. fail(e) {
  194. that.loading = false
  195. uni.hideLoading()
  196. uni.showToast({
  197. title: '取消支付',
  198. icon: 'fail'
  199. })
  200. // 取消支付后,获取支付信息以备再次支付
  201. payDetails(that.query.orderNo).then(r => {
  202. if (r.state == 'Success') {
  203. that.payData = JSON.parse(r.content.miniPayRequest)
  204. }
  205. })
  206. console.log('err', e);
  207. }
  208. })
  209. }
  210. }
  211. },
  212. onReady() {
  213. },
  214. onLoad() {
  215. let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  216. this.query.userId = userInfo.userId
  217. let that = this
  218. const eventChannel = this.getOpenerEventChannel();
  219. eventChannel.on('pay', function(data) {
  220. that.createQuery.rechargeAccount = data.rechargeAccount
  221. that.createQuery.accountType = data.accountType
  222. that.createQuery.productId = data.productId
  223. that.info.goodsName = data.goodsName
  224. that.info.price = data.price
  225. console.log('data', data);
  226. })
  227. }
  228. }
  229. </script>
  230. <style lang="scss">
  231. .pay {
  232. background: #F9F9F9;
  233. min-height: 100vh;
  234. padding-top: 20rpx;
  235. .shop-info {
  236. margin: 0 30rpx 20rpx;
  237. width: 690rpx;
  238. padding: 24rpx;
  239. box-sizing: border-box;
  240. background: #FFFFFF;
  241. border-radius: 16rpx 16rpx 16rpx 16rpx;
  242. .shop-name {
  243. color: #181818;
  244. font-size: 32rpx;
  245. }
  246. .address {
  247. color: #999999;
  248. font-size: 24rpx;
  249. margin-top: 12rpx;
  250. }
  251. }
  252. .pay-info {
  253. margin: 0 30rpx;
  254. background: #FFFFFF;
  255. border-radius: 16rpx 16rpx 16rpx 16rpx;
  256. padding: 28rpx 24rpx;
  257. .goods-info {
  258. display: flex;
  259. margin-bottom: 30rpx;
  260. .goods-img {
  261. width: 164rpx;
  262. height: 164rpx;
  263. border-radius: 16rpx;
  264. }
  265. .info {
  266. margin-left: 28rpx;
  267. flex: 1;
  268. .goods-name {
  269. font-weight: bold;
  270. color: #181818;
  271. font-size: 32rpx;
  272. width: 100%;
  273. word-break: break-all;
  274. text-overflow: ellipsis;
  275. overflow: hidden;
  276. display: -webkit-box;
  277. -webkit-box-orient: vertical;
  278. -webkit-line-clamp: 2;
  279. /* 这里是超出几行省略 */
  280. }
  281. .num {
  282. color: #999999;
  283. font-size: 24rpx;
  284. margin-top: 16rpx;
  285. }
  286. .price {
  287. font-weight: bold;
  288. color: #181818;
  289. font-size: 32rpx;
  290. margin-top: 26rpx;
  291. }
  292. }
  293. }
  294. .coupon {
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. border-bottom: 2rpx dashed #f3f3f3;
  299. padding: 28rpx 0;
  300. .label {
  301. color: #222222;
  302. font-size: 28rpx;
  303. }
  304. .choose-coupon.none{
  305. color: #AAAAAA;
  306. }
  307. .choose-coupon {
  308. color: #FF4848;
  309. font-size: 28rpx;
  310. display: flex;
  311. align-items: center;
  312. .icon {
  313. width: 28rpx;
  314. height: 28rpx;
  315. display: block;
  316. margin-left: 10rpx;
  317. }
  318. }
  319. }
  320. .explain {
  321. display: flex;
  322. align-items: center;
  323. justify-content: space-between;
  324. padding-top: 28rpx;
  325. .label {
  326. color: #AAAAAA;
  327. font-size: 28rpx;
  328. }
  329. .right {
  330. display: flex;
  331. align-items: center;
  332. font-size: 24rpx;
  333. .red {
  334. font-weight: 500;
  335. color: #FF4848;
  336. margin: 0 10rpx;
  337. }
  338. .fs28 {
  339. font-size: 28rpx !important;
  340. }
  341. }
  342. }
  343. }
  344. .input-box{
  345. margin: 20rpx 30rpx;
  346. padding: 28rpx 24rpx;
  347. background: #FFFFFF;
  348. border-radius: 16rpx 16rpx 16rpx 16rpx;
  349. display: flex;
  350. align-items: center;
  351. justify-content: space-between;
  352. .label {
  353. color: #222;
  354. font-size: 28rpx;
  355. }
  356. .value {
  357. font-size: 28rpx;
  358. color: #AAAAAA;
  359. }
  360. }
  361. .btn-box {
  362. position: fixed;
  363. bottom: 0%;
  364. left: 0%;
  365. width: 100%;
  366. height: 98rpx;
  367. display: flex;
  368. align-items: center;
  369. justify-content: space-between;
  370. box-sizing: border-box;
  371. padding: 0 30rpx;
  372. border-top: 1rpx solid #EEEEEE;
  373. .total-price {
  374. display: flex;
  375. align-items: center;
  376. .label {
  377. color: #181818;
  378. font-size: 28rpx;
  379. }
  380. .price {
  381. font-size: 36rpx;
  382. font-weight: 800;
  383. color: #FF4848;
  384. margin-left: 10rpx;
  385. }
  386. }
  387. .btn {
  388. width: 280rpx;
  389. height: 80rpx;
  390. line-height: 80rpx;
  391. text-align: center;
  392. background: $uni-color-primary;
  393. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  394. border-radius: 46rpx 46rpx 46rpx 46rpx;
  395. font-weight: 800;
  396. color: #FFFFFF;
  397. font-size: 28rpx;
  398. margin: 0;
  399. }
  400. }
  401. }
  402. </style>