order.vue 15 KB

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