pay.vue 13 KB

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