order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <template>
  2. <view class="pay">
  3. <view class="pay-info">
  4. <view class="goods-info">
  5. <image class="goods-img" :src="info.goodsPath" 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="priceColumn">
  14. <view class="price">
  15. <text class="unit">¥</text>{{ info.realPrice }}
  16. </view>
  17. <view class="goodsNum">
  18. x{{ realPay.reservePersons.length }}
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="setoff">
  24. <view class="text">
  25. 出发时间
  26. </view>
  27. <view class="date">
  28. {{ reserveTimeFmt }}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="appointment">
  33. <view class="title">
  34. 预定人信息
  35. </view>
  36. <view class="name">
  37. <view class="label">
  38. 姓名
  39. </view>
  40. <view class="value">
  41. {{ userInfo.name }}
  42. </view>
  43. </view>
  44. <view class="phone">
  45. <view class="label">
  46. 手机号
  47. </view>
  48. <view class="value">
  49. <text class="zone">+86</text>{{ userInfo.phoneNum }}
  50. </view>
  51. </view>
  52. <view class="desc">
  53. 预定人信息用于接受验证信息
  54. </view>
  55. </view>
  56. <view class="tour">
  57. <view class="title-top">
  58. <view class="title-text">
  59. 出游人信息
  60. </view>
  61. <view @click="addNewTourPerson" class="add">
  62. +添加
  63. </view>
  64. </view>
  65. <view v-for="(item, index) in realPay.reservePersons" :key="index" class="info-card">
  66. <view class="user-name">
  67. {{ item.userName }}
  68. <view class="tag">
  69. 出行人{{ index + 1 }}
  70. </view>
  71. </view>
  72. <view class="card-info">
  73. 身份证:{{ item.idCard }}
  74. </view>
  75. </view>
  76. </view>
  77. <view class="btn-box">
  78. <view class="total-price">
  79. <view class="label">
  80. 合计:
  81. </view>
  82. <view class="price">
  83. ¥ {{ payInfo.price }}
  84. </view>
  85. </view>
  86. <button class="btn" type="default" :loading="loading" @click="creat">提交订单</button>
  87. </view>
  88. <uni-calendar ref="calendar" :lunar="true" :showMonth="true" style="z-index: 999;" :insert="false"
  89. @confirm="confirm" />
  90. </view>
  91. </template>
  92. <script>
  93. import {
  94. studyCalculate, saveReserve
  95. } from '@/api/order.js';
  96. import {
  97. creat
  98. } from '@/api/goods.js'
  99. import {
  100. creatPayOrder,
  101. queryPayOrder,
  102. payDetails
  103. } from '@/api/payment.js'
  104. import guid from '@/utils/guid.js'
  105. export default {
  106. data() {
  107. return {
  108. isVisual: false,//是否是虚拟商品
  109. loading: false,
  110. info: {},
  111. realPay: {
  112. goodsCouponName: '', //优惠券名
  113. couponGoodsLogId: '', //优惠券id
  114. goodsId: '', //商品id
  115. price: '', //支付价格
  116. offset: '', //实际抵扣值
  117. discount: '', //优惠券值
  118. condition: '', //优惠条件
  119. originalPrice: '', //原价
  120. reserveName: '',//预定人
  121. reservePhone: '',//预定人手机
  122. reserveTime: '',//预定时间
  123. reservePersons: [],//出游人
  124. },
  125. form: {
  126. account: ''
  127. },
  128. rules: {
  129. 'account': {
  130. type: 'string',
  131. required: true,
  132. message: '请输入充值账号',
  133. trigger: ['blur', 'change']
  134. },
  135. },
  136. query: {
  137. "msgType": "wx.unifiedOrder",
  138. "orderDesc": "测试",
  139. "orderNo": "",
  140. "channel": 'ZhongShu',
  141. "subOpenId": "",
  142. "userId": ""
  143. },
  144. // 支付信息
  145. payData: {
  146. },
  147. userInfo: {}
  148. }
  149. },
  150. computed: {
  151. // 正式支付时的信息
  152. payInfo() {
  153. return {
  154. goodsCouponName: this.realPay.goodsCouponName || '', //优惠券名
  155. couponGoodsLogId: this.info.couponId, //优惠券id
  156. goodsId: this.realPay.goodsId || this.info.goodsId, //商品id
  157. price: this.realPay.price, //支付价格
  158. offset: this.realPay.offset, //实际抵扣值
  159. discount: this.realPay.discount || 0, //优惠券值
  160. condition: this.realPay.condition || '', //优惠条件
  161. originalPrice: this.realPay.originalPrice, //原价
  162. }
  163. },
  164. reserveTimeFmt() {
  165. const date = new Date(this.info.reserveTime)
  166. // const year = date.getFullYear()
  167. const month = date.getMonth() + 1
  168. const day = date.getDate()
  169. return `${month}月${day}日`
  170. }
  171. },
  172. methods: {
  173. // 增加新的出游人
  174. addNewTourPerson() {
  175. uni.navigateTo({
  176. url: '/study/tourList/list'
  177. })
  178. },
  179. openCalendar() {
  180. this.$refs.calendar.open();
  181. },
  182. confirm(e) {
  183. console.log(e);
  184. },
  185. calculate(goodsId, shopId) {
  186. uni.showLoading({
  187. title: '计算中'
  188. })
  189. return new Promise((resolve, reject) => {
  190. studyCalculate({
  191. couponId: this.info.couponId,
  192. "goodsId": goodsId,
  193. "shopId": shopId,
  194. "userId": JSON.parse(uni.getStorageSync('userInfo')).userId,
  195. "number": this.realPay.reservePersons.length
  196. }).then(res => {
  197. uni.hideLoading()
  198. if (res.state == 'Success') {
  199. const reservePersons = this.realPay.reservePersons
  200. this.realPay = res.content
  201. this.realPay.reservePersons = reservePersons
  202. this.info.couponId = res.content.couponId
  203. }
  204. })
  205. })
  206. },
  207. choose() {
  208. let that = this
  209. uni.navigateTo({
  210. url: './coupon?couponId=' + this.realPay.couponLogId,
  211. success: function (res) {
  212. // 通过eventChannel向被打开页面传送数据
  213. res.eventChannel.emit('pay', that.info)
  214. }
  215. })
  216. },
  217. tempCreate() {
  218. uni.reLaunch({
  219. url: '/study/pay/orderPay'
  220. })
  221. },
  222. //创建订单
  223. creat() {
  224. if (this.loading) return
  225. if (this.realPay.reservePersons.length == 0) {
  226. uni.showToast({
  227. title: '请添加出游人',
  228. icon: 'none'
  229. })
  230. return
  231. }
  232. const user = JSON.parse(uni.getStorageSync('userInfo'))
  233. this.realPay.reserveName = user.name
  234. this.realPay.reservePhone = user.phoneNum
  235. this.realPay.reserveTime = this.info.reserveTime
  236. this.loading = true
  237. uni.showLoading({
  238. title: '支付中'
  239. })
  240. let that = this
  241. if (!this.payData.timeStamp) {
  242. // 处理扩展字段 暂时只有研学商品和视频会员 视频会员是字符串的JSON 研学是字符串
  243. let extend
  244. try {
  245. if (JSON.parse(this.info.extend)) {
  246. extend = this.info.extend
  247. }
  248. } catch (e) {
  249. extend = this.info.reservationTime || ''
  250. }
  251. creat({
  252. discountId: (this.payInfo.couponGoodsLogId || this.payInfo.couponGoodsLogId == -1) ? [this
  253. .payInfo.couponGoodsLogId
  254. ] : [],
  255. extend,
  256. channel: 'ZhongShu',
  257. goodsList: this.info.goodsId ? [this.info.goodsId] : [],
  258. idempotent: guid(),
  259. shopId: this.info.shopId
  260. }).then(res => {
  261. this.loading = false
  262. if (res.state == 'Success') {
  263. if (!this.payInfo.price) { //价格为0
  264. uni.hideLoading()
  265. uni.reLaunch({
  266. url: '/my/order/index'
  267. })
  268. } else {
  269. this.query.orderNo = res.content.orderNo
  270. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  271. this.query.orderDesc = this.info.goodsName
  272. creatPayOrder(this.query).then(data => {
  273. that.payData = JSON.parse(data.content.miniPayRequest)
  274. if (data.content.miniPayRequest == null) return uni.hideLoading()
  275. saveReserve({
  276. ...this.realPay,
  277. orderNo: this.query.orderNo,
  278. goodsId: this.info.goodsId,
  279. }).then(res => {
  280. if (res.state == 'Success') {
  281. uni.requestPayment({
  282. "provider": "wxpay",
  283. "orderInfo": that.payData,
  284. "appid": that.payData
  285. .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  286. "paySign": that.payData.paySign,
  287. "nonceStr": that.payData.nonceStr, // 随机字符串
  288. "package": that.payData.package, // 固定值
  289. // "prepayid": that.payData.package, // 统一下单订单号
  290. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  291. "signType": that.payData.signType, //签名算法
  292. success(msg) {
  293. console.log('msg', that.query.orderNo);
  294. queryPayOrder(that.query.orderNo).then(res1 => {
  295. if (res1.state == 'Success') {
  296. uni.hideLoading()
  297. uni.reLaunch({
  298. url: '/my/order/index'
  299. })
  300. }
  301. })
  302. },
  303. fail(e) {
  304. console.log('err', e);
  305. that.loading = false
  306. uni.hideLoading()
  307. uni.showToast({
  308. title: '取消支付',
  309. icon: 'fail'
  310. })
  311. // 取消支付后,获取支付信息以备再次支付
  312. payDetails(that.query.orderNo).then(r => {
  313. if (r.state == 'Success') {
  314. that.payData = JSON.parse(r.content.miniPayRequest)
  315. }
  316. })
  317. }
  318. })
  319. } else {
  320. uni.showToast({
  321. title: res.msg,
  322. icon: 'none'
  323. })
  324. that.loading = false
  325. }
  326. })
  327. })
  328. }
  329. }
  330. })
  331. } else { // 取消支付后再次支付
  332. uni.requestPayment({
  333. "provider": "wxpay",
  334. "orderInfo": that.payData,
  335. "appid": that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  336. "paySign": that.payData.paySign,
  337. "nonceStr": that.payData.nonceStr, // 随机字符串
  338. "package": that.payData.package, // 固定值
  339. // "prepayid": that.payData.package, // 统一下单订单号
  340. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  341. "signType": that.payData.signType, //签名算法
  342. success(msg) {
  343. console.log('msg', msg);
  344. queryPayOrder(that.query.orderNo).then(res1 => {
  345. if (res1.state == 'Success') {
  346. uni.hideLoading()
  347. uni.reLaunch({
  348. url: '/my/order/index'
  349. })
  350. }
  351. })
  352. },
  353. fail(e) {
  354. that.loading = false
  355. uni.hideLoading()
  356. uni.showToast({
  357. title: '取消支付',
  358. icon: 'fail'
  359. })
  360. // 取消支付后,获取支付信息以备再次支付
  361. payDetails(that.query.orderNo).then(r => {
  362. if (r.state == 'Success') {
  363. that.payData = JSON.parse(r.content.miniPayRequest)
  364. }
  365. })
  366. console.log('err', e);
  367. }
  368. })
  369. }
  370. }
  371. },
  372. onReady() {
  373. },
  374. onLoad() {
  375. let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
  376. this.query.userId = userInfo.userId
  377. this.userInfo = userInfo
  378. let that = this
  379. const eventChannel = this.getOpenerEventChannel();
  380. eventChannel.on('pay', function (data) {
  381. that.info = data
  382. try {
  383. let extend = JSON.parse(that.info.extend)
  384. if (extend.account) {
  385. that.isVisual = true
  386. that.form.account = extend.account
  387. }
  388. } catch (e) {
  389. //TODO handle the exception
  390. }
  391. console.log('data', data);
  392. // that.calculate(that.info.goodsId, that.info.shopId)
  393. })
  394. uni.$on("updateData", (data) => {
  395. this.realPay.reservePersons = data
  396. that.calculate(that.info.goodsId, that.info.shopId)
  397. this.$forceUpdate()
  398. })
  399. },
  400. destoryed() {
  401. uni.$off("updateData")
  402. }
  403. }
  404. </script>
  405. <style lang="scss">
  406. .pay {
  407. background: #F9F9F9;
  408. min-height: 100vh;
  409. padding-top: 20rpx;
  410. .shop-info {
  411. margin: 0 30rpx 20rpx;
  412. width: 690rpx;
  413. padding: 24rpx;
  414. box-sizing: border-box;
  415. background: #FFFFFF;
  416. border-radius: 16rpx 16rpx 16rpx 16rpx;
  417. .shop-name {
  418. color: #181818;
  419. font-size: 32rpx;
  420. }
  421. .address {
  422. color: #999999;
  423. font-size: 24rpx;
  424. margin-top: 12rpx;
  425. }
  426. }
  427. .pay-info {
  428. margin: 0 30rpx;
  429. background: #FFFFFF;
  430. border-radius: 16rpx 16rpx 16rpx 16rpx;
  431. padding: 24rpx;
  432. .goods-info {
  433. display: flex;
  434. margin-bottom: 26rpx;
  435. .goods-img {
  436. width: 164rpx;
  437. height: 164rpx;
  438. border-radius: 16rpx;
  439. }
  440. .info {
  441. margin-left: 28rpx;
  442. flex: 1;
  443. .goods-name {
  444. font-weight: bold;
  445. color: #181818;
  446. font-size: 32rpx;
  447. width: 100%;
  448. word-break: break-all;
  449. text-overflow: ellipsis;
  450. overflow: hidden;
  451. display: -webkit-box;
  452. -webkit-box-orient: vertical;
  453. -webkit-line-clamp: 2;
  454. /* 这里是超出几行省略 */
  455. }
  456. .num {
  457. color: #999999;
  458. font-size: 24rpx;
  459. margin-top: 16rpx;
  460. }
  461. .priceColumn {
  462. display: flex;
  463. justify-content: space-between;
  464. align-items: center;
  465. margin-top: 30rpx;
  466. .price {
  467. font-weight: bold;
  468. color: #FF4D3A;
  469. font-size: 32rpx;
  470. .unit {
  471. font-size: 20rpx;
  472. }
  473. }
  474. .goodsNum {
  475. font-size: 24rpx;
  476. color: #AAAAAA;
  477. }
  478. }
  479. }
  480. }
  481. .setoff {
  482. border-top: 1px solid #F0F0F0;
  483. display: flex;
  484. justify-content: space-between;
  485. align-items: center;
  486. font-size: 24rpx;
  487. padding-top: 24rpx;
  488. .text {
  489. color: #222222;
  490. }
  491. .date {
  492. color: #AAAAAA;
  493. }
  494. }
  495. }
  496. .appointment {
  497. padding: 24rpx;
  498. background: #FFFFFF;
  499. margin: 20rpx 30rpx;
  500. border-radius: 16rpx 16rpx 16rpx 16rpx;
  501. .title {
  502. font-size: 28rpx;
  503. color: #222222;
  504. font-weight: bold;
  505. margin-bottom: 24rpx;
  506. }
  507. .name {
  508. border-top: 1px solid #F0F0F0;
  509. padding: 24rpx 0;
  510. display: flex;
  511. .label {
  512. font: 24rpx;
  513. color: #222222;
  514. width: 152rpx;
  515. }
  516. .value {
  517. font-size: 28rpx;
  518. font-weight: bold;
  519. }
  520. }
  521. .phone {
  522. border-top: 1px solid #F0F0F0;
  523. padding: 24rpx 0;
  524. display: flex;
  525. .label {
  526. font: 24rpx;
  527. color: #222222;
  528. width: 152rpx;
  529. }
  530. .value {
  531. font-size: 28rpx;
  532. font-weight: bold;
  533. .zone {
  534. padding-right: 22rpx;
  535. margin-right: 20rpx;
  536. border-right: 1px solid #F0F0F0;
  537. }
  538. }
  539. }
  540. .desc {
  541. border-top: 1px solid #F0F0F0;
  542. padding-top: 24rpx;
  543. color: #AAAAAA;
  544. font-size: 24rpx;
  545. }
  546. }
  547. .tour {
  548. padding: 24rpx;
  549. background: #FFFFFF;
  550. margin: 0 30rpx;
  551. border-radius: 16rpx 16rpx 16rpx 16rpx;
  552. .title-top {
  553. display: flex;
  554. justify-content: space-between;
  555. align-items: center;
  556. .title-text {
  557. font-size: 28rpx;
  558. font-weight: bold;
  559. color: #222222;
  560. }
  561. .add {
  562. font-size: 24rpx;
  563. color: #3B83FF;
  564. }
  565. margin-bottom: 24rpx;
  566. }
  567. .info-card {
  568. border-top: 1px solid #F0F0F0;
  569. padding: 24rpx 0;
  570. .user-name {
  571. font-size: 28rpx;
  572. font-weight: bold;
  573. color: #222222;
  574. display: flex;
  575. align-items: center;
  576. .tag {
  577. margin-left: 20rpx;
  578. color: #222222;
  579. font-size: 20rpx;
  580. background-color: #F0F0F0;
  581. border-radius: 18rpx;
  582. line-height: 20rpx;
  583. padding: 2rpx 12rpx;
  584. }
  585. }
  586. .card-info {
  587. margin: 20rpx 0;
  588. font-size: 24rpx;
  589. color: #222222;
  590. }
  591. }
  592. }
  593. .btn-box {
  594. position: fixed;
  595. bottom: 0%;
  596. left: 0%;
  597. width: 100%;
  598. display: flex;
  599. align-items: center;
  600. justify-content: space-between;
  601. box-sizing: border-box;
  602. padding: 10rpx 30rpx env(safe-area-inset-bottom);
  603. border-top: 1rpx solid #EEEEEE;
  604. .total-price {
  605. display: flex;
  606. align-items: center;
  607. .label {
  608. color: #181818;
  609. font-size: 28rpx;
  610. }
  611. .price {
  612. font-size: 36rpx;
  613. font-weight: 800;
  614. color: #FF4848;
  615. margin-left: 10rpx;
  616. }
  617. }
  618. .btn {
  619. width: 280rpx;
  620. height: 80rpx;
  621. line-height: 80rpx;
  622. text-align: center;
  623. background: #3B83FF;
  624. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  625. border-radius: 46rpx 46rpx 46rpx 46rpx;
  626. font-weight: 800;
  627. color: #FFFFFF;
  628. font-size: 28rpx;
  629. margin: 0;
  630. }
  631. }
  632. }
  633. </style>