confirmOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <view>
  3. <view class="top">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar :title="title" control="home" bgcolor="#a09cc4"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar :title="title" bgcolor="#a09cc4"></NavigateBar>
  9. <!-- #endif -->
  10. </view>
  11. <view class="room-type-item">
  12. <view class="room-type-item-left">
  13. <u-image :src="roomPicPath" width="200rpx" height="200rpx" radius="10"></u-image>
  14. </view>
  15. <view class="room-type-item-middle">
  16. <view class="room-type-item-middle-text">
  17. <text>{{roomTypeName ? roomTypeName : ""}}</text>
  18. </view>
  19. <view class="room-type-item-middle-text">
  20. <text>{{order.room ? order.room : ""}}</text>
  21. </view>
  22. </view>
  23. <view class="room-type-item-right">
  24. <view class="room-type-item-right-text">
  25. <text>¥{{unitPrice ? unitPrice : 0}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="checkin-date-info">
  30. <view class="date-selector">
  31. <view class="date-item">
  32. <u-text text="入住" color="#666666" size="15"></u-text>
  33. <view class="date-info">
  34. <u-text :text="startDate" color="#333333" size="14" bold></u-text>
  35. <u-text :text="startDay" color="#333333" size="14" bold></u-text>
  36. </view>
  37. </view>
  38. <view class="date-item">
  39. <u-text text="离店" color="#666666" size="15"></u-text>
  40. <view class="date-info">
  41. <u-text :text="endDate" color="#333333" size="14" bold></u-text>
  42. <u-text :text="endDay" color="#333333" size="14" bold></u-text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="day-num">
  47. <u-text :text="'共' + order.dayNum + '晚'" color="#333333" size="15" bold></u-text>
  48. </view>
  49. </view>
  50. <!-- #ifdef MP-WEIXIN -->
  51. <u-swipe-action>
  52. <u-swipe-action-item :options="options" v-for="(info,index) in checkinInfo" @click="deleteGuest"
  53. :name="index" :disabled="index ===0">
  54. <u-form labelPosition="left" labelWidth="180rpx" labelAlign="center">
  55. <u-form-item label="姓名" prop="name">
  56. <u-text :text="info.name" border="none" clearable fontSize="36rpx"></u-text>
  57. </u-form-item>
  58. <u-form-item label="身份证" prop="idNumber">
  59. <u-text :text="info.idNumber" border="none" clearable fontSize="36rpx"></u-text>
  60. </u-form-item>
  61. </u-form>
  62. </u-swipe-action-item>
  63. </u-swipe-action>
  64. <!-- #endif -->
  65. <!-- #ifdef MP-ALIPAY -->
  66. <view v-for="(info,index) in checkinInfo" :key="index" class="guest-info">
  67. <ant-swipe-action :rightButtons="rightBtns" @swipeStart="onSwipeStart" @swipeEnd="onSwipeEnd"
  68. @buttonTap="deleteGuestAli" :swiped="swipeIndex === index" :data-item="index" :disabled="index ===0">
  69. <view class="swipe-item">
  70. <u-form labelPosition="left" labelWidth="180rpx" labelAlign="center">
  71. <u-form-item label="姓名" prop="name">
  72. <u-text :text="info.name" border="none" clearable fontSize="36rpx"></u-text>
  73. </u-form-item>
  74. <u-form-item label="身份证" prop="idNumber">
  75. <u-text :text="info.idNumber" border="none" clearable fontSize="36rpx"></u-text>
  76. </u-form-item>
  77. </u-form>
  78. </view>
  79. </ant-swipe-action>
  80. </view>
  81. <!-- #endif -->
  82. <view class="add-guest-btn-container">
  83. <u-button text="添加同住人" @click="gotoAddGuest"></u-button>
  84. </view>
  85. <view class="paymentArea" v-if="confirmDone">
  86. <view class="paymentArea--left">
  87. <view class="price">
  88. <text>合计:</text>
  89. <text>¥{{order.price ? order.price : ""}}</text>
  90. </view>
  91. <view class="deposit">
  92. <text text="" align="right" size="20">(注:需付押金{{order.deposit ? order.deposit : ""}}元)</text>
  93. </view>
  94. </view>
  95. <view class="completeBtn">
  96. <button class="u-button" @click="pay">支付</button>
  97. </view>
  98. </view>
  99. <view class="confirm-btn-container" v-else>
  100. <u-button text="确认" color="#9e97c3" @click="confirmOrder"></u-button>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. import {
  106. getDay
  107. } from '../../utils/commonUtils.js'
  108. import {
  109. IMG_BASE_URL
  110. } from "../../config.js"
  111. import {
  112. mapState,
  113. mapMutations
  114. } from 'vuex'
  115. import moment from "moment";
  116. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  117. export default {
  118. components: {
  119. NavigateBar
  120. },
  121. data() {
  122. return {
  123. roomPicPath: '',
  124. roomTypeName: '',
  125. unitPrice: '',
  126. startDate: this.startDate,
  127. startDay: this.startDay,
  128. endDate: this.endDate,
  129. endDay: this.endDay,
  130. arrowPicPath: '/static/arrow.png',
  131. confirmDone: false,
  132. options: [{
  133. text: '删除',
  134. style: {
  135. backgroundColor: '#FF0000'
  136. }
  137. }],
  138. title: "",
  139. // #ifdef MP-ALIPAY
  140. rightBtns: [{
  141. text: "删除",
  142. bgColor: "#FF0000",
  143. color: '#fff',
  144. }],
  145. swipeIndex: -1,
  146. // #endif
  147. };
  148. },
  149. computed: {
  150. ...mapState('m_user', ['userInfo']),
  151. ...mapState('m_business', ['order', 'currentHotel', 'checkinInfo']),
  152. },
  153. methods: {
  154. ...mapMutations('m_business', ['updateCheckinInfo', 'updateOrder']),
  155. gotoAddGuest() {
  156. uni.navigateTo({
  157. url: '/subpkg_checkin/addGuest/addGuest'
  158. })
  159. },
  160. // #ifdef MP-WEIXIN
  161. deleteGuest(info) {
  162. if (info.name === 0) {
  163. return
  164. }
  165. this.checkinInfo.splice(info.name, 1)
  166. this.updateCheckinInfo(this.checkinInfo)
  167. },
  168. // #endif
  169. async confirmOrder() {
  170. //小程序创建的订单,先在后台创建订单,创建成功后跳转至支付页面
  171. if (this.order.orderSource === 'MINI_APP') {
  172. if (!this.order.orderId) {
  173. let createOrderRes = await uni.$http.post('/hotelOrder', this.order)
  174. if (createOrderRes.data.code !== 200) {
  175. uni.$showMsg('订单创建失败,请重试')
  176. return
  177. }
  178. this.updateOrder(createOrderRes.data.data)
  179. }
  180. this.confirmDone = true
  181. this.title = '订单支付'
  182. } else {
  183. //pms预定订单,若未支付跳转至支付页面,若已支付跳转至入住页面
  184. if (this.order.paymentStatus !== 'PAID') {
  185. this.confirmDone = true
  186. this.title = '订单支付'
  187. } else {
  188. uni.navigateTo({
  189. url: '/subpkg_checkin/checkin/checkin'
  190. })
  191. }
  192. }
  193. },
  194. async pay() {
  195. console.log("pay start");
  196. // #ifdef MP-WEIXIN
  197. let res = await uni.$http.post('/hotelOrder/payment', {
  198. openid: this.userInfo.openid,
  199. orderId: this.order.orderId,
  200. platform: 'WECHAT',
  201. hotelId: this.currentHotel.hotelId
  202. })
  203. if (res.data.code == 200) {
  204. res.data.data.package = res.data.data.packageStr
  205. try {
  206. let paymentResult = await wx.requestPayment(res.data.data)
  207. console.log("payment result:", paymentResult)
  208. if (paymentResult.errMsg === 'requestPayment:ok') {
  209. uni.$showMsg("支付成功")
  210. uni.redirectTo({
  211. url: '/subpkg_checkin/checkin/checkin'
  212. })
  213. }
  214. } catch {
  215. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  216. }
  217. } else {
  218. //小程序创建的订单跳转至选择房间,pms预订单跳转至查询订单
  219. if (this.order.orderSource === 'MINI_APP') {
  220. uni.showModal({
  221. content: '房间已被占用,请重新选房',
  222. showCancel: false,
  223. success: (res) => {
  224. if (res.confirm) {
  225. uni.navigateTo({
  226. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  227. this.order.roomType
  228. })
  229. }
  230. }
  231. })
  232. } else {
  233. uni.showModal({
  234. content: '订单不可用,请重新选择订单',
  235. showCancel: false,
  236. success: (res) => {
  237. if (res.confirm) {
  238. uni.navigateTo({
  239. url: '/subpkg_checkin/queryOrder/queryOrder?'
  240. })
  241. }
  242. }
  243. })
  244. }
  245. }
  246. // #endif
  247. // #ifdef MP-ALIPAY
  248. if (Number(this.order.deposit) === 0) {
  249. await this.aliPaymentNormal()
  250. } else {
  251. await this.aliPaymentFreeze()
  252. }
  253. // #endif
  254. },
  255. // #ifdef MP-ALIPAY
  256. onSwipeStart() {
  257. this.swipeIndex = ""
  258. },
  259. onSwipeEnd(arg1, arg2) {
  260. console.log(arg1, arg2);
  261. let index = arg2.target.dataset.item
  262. if (arg1.swiped) {
  263. this.swipeIndex = index
  264. }
  265. },
  266. deleteGuestAli() {
  267. this.checkinInfo.splice(this.swipeIndex, 1)
  268. this.updateCheckinInfo(this.checkinInfo)
  269. },
  270. async aliPaymentNormal() {
  271. // 申请获取预付号
  272. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  273. openid: this.userInfo.openid,
  274. orderId: this.order.orderId,
  275. platform: 'ALIPAY',
  276. hotelId: this.currentHotel.hotelId
  277. })
  278. // console.log("获取预付号",alipayRes.data)
  279. if (!alipayRes.data.success) {
  280. console.log("获取预付号失败");
  281. uni.showModal({
  282. content: '房间已被占用,请重新选房',
  283. showCancel: false,
  284. success: (res) => {
  285. if (res.confirm) {
  286. uni.navigateTo({
  287. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  288. this.order.roomType
  289. })
  290. }
  291. }
  292. })
  293. return
  294. }
  295. // 根据预付号发起支付
  296. let tradeNo = alipayRes.data.data.tradeNo
  297. let tradeRes = await my.tradePay({
  298. tradeNO: tradeNo
  299. })
  300. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  301. if (tradeRes.resultCode === "6001") {
  302. console.log("支付未完成。");
  303. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  304. }
  305. if (tradeRes.resultCode === "6002") {
  306. // 网络连接出错
  307. uni.showModal({
  308. title: "网络连接出错",
  309. content: "网络连接出错,请检查网络连接后重试。",
  310. });
  311. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  312. }
  313. // 顾客支付后,查询支付状态
  314. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  315. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  316. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  317. tradeNo: tradeNo,
  318. hotelId: this.currentHotel.hotelId
  319. })
  320. // console.log("tradeStatus", tradeStatus);
  321. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  322. uni.$showMsg("支付成功")
  323. uni.navigateTo({
  324. url: '/subpkg_checkin/checkin/checkin'
  325. })
  326. } else {
  327. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  328. }
  329. }
  330. },
  331. async aliPaymentFreeze() {
  332. // 申请获取签名字符串
  333. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  334. orderId: this.order.orderId,
  335. hotelId: this.currentHotel.hotelId
  336. })
  337. console.log("签名字符串", alipayRes.data)
  338. if (!alipayRes.data.success) {
  339. console.log("获取签名字符串失败");
  340. uni.showModal({
  341. content: '房间已被占用,请重新选房',
  342. showCancel: false,
  343. success: (res) => {
  344. if (res.confirm) {
  345. uni.navigateTo({
  346. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  347. this.order.roomType
  348. })
  349. }
  350. }
  351. })
  352. return
  353. }
  354. // 根据签名字符串发起授权
  355. let orderString = alipayRes.data.data
  356. let tradeRes = await my.tradePay({
  357. orderStr: orderString
  358. })
  359. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  360. if (tradeRes.resultCode === "6001") {
  361. console.log("支付未完成。");
  362. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  363. }
  364. if (tradeRes.resultCode === "6002") {
  365. // 网络连接出错
  366. uni.showModal({
  367. title: "网络连接出错",
  368. content: "网络连接出错,请检查网络连接后重试。",
  369. });
  370. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  371. }
  372. // 顾客授权后,查询授权状态
  373. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  374. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  375. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  376. orderId: this.order.orderId,
  377. hotelId: this.currentHotel.hotelId
  378. })
  379. // console.log("tradeStatus", tradeStatus);
  380. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  381. uni.$showMsg("支付成功")
  382. uni.navigateTo({
  383. url: '/subpkg_checkin/checkin/checkin'
  384. })
  385. } else {
  386. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  387. }
  388. }
  389. }
  390. // #endif
  391. },
  392. async onLoad() {
  393. let res = await uni.$http.post('/roomType', {
  394. roomType: this.order.roomType,
  395. hotelId: this.currentHotel.hotelId,
  396. pageNo: 1,
  397. pageSize: 999
  398. })
  399. this.roomPicPath = IMG_BASE_URL + '/' + res.data.data.records[0].roomPicPath
  400. this.roomTypeName = res.data.data.records[0].roomTypeName
  401. this.unitPrice = res.data.data.records[0].unitPrice
  402. this.startDate = moment(new Date(this.order.startTime)).format('MM月DD日')
  403. this.startDay = getDay(new Date(this.order.startTime).getDay())
  404. this.endDate = moment(new Date(this.order.endTime)).format('MM月DD日')
  405. this.endDay = getDay(new Date(this.order.endTime).getDay())
  406. },
  407. // #ifdef MP-WEIXIN
  408. onShareAppMessage(info) {
  409. return {
  410. title: '源享住',
  411. path: 'pages/login/login',
  412. imageUrl: "/static/logo.png"
  413. }
  414. }
  415. // #endif
  416. }
  417. </script>
  418. <style lang="scss">
  419. page {
  420. background-color: #EFEFF4;
  421. }
  422. .room-type-item {
  423. border-radius: 30rpx;
  424. background-color: #FFFFFF;
  425. margin: 20rpx;
  426. padding: 40rpx 20rpx;
  427. display: flex;
  428. background: #FFFFFF;
  429. border-radius: 10rpx;
  430. .room-type-item-middle {
  431. margin-left: 30rpx;
  432. display: flex;
  433. flex-direction: column;
  434. width: 200rpx;
  435. .room-type-item-middle-text {
  436. font-size: 40rpx;
  437. font-weight: bold;
  438. color: #333333;
  439. }
  440. .room-type-item-middle-bottom {
  441. margin-top: 40rpx;
  442. font-size: 25rpx;
  443. text {
  444. margin-right: 20rpx;
  445. color: #666666
  446. }
  447. }
  448. }
  449. .room-type-item-right {
  450. width: 25%;
  451. margin-left: 20rpx;
  452. .room-type-item-right-text {
  453. margin-left: 60rpx;
  454. margin-top: 40rpx;
  455. }
  456. text {
  457. font-size: 40rpx;
  458. font-weight: bold;
  459. color: #FF5C58
  460. }
  461. }
  462. }
  463. .checkin-date-info {
  464. border-radius: 30rpx;
  465. background-color: #FFFFFF;
  466. margin: 20rpx 20rpx;
  467. padding: 20rpx;
  468. display: flex;
  469. background: #FFFFFF;
  470. border-radius: 10rpx;
  471. .date-selector {
  472. margin: 20rpx;
  473. display: flex;
  474. width: 70vw;
  475. .date-item {
  476. width: 35vw;
  477. .date-info {
  478. display: flex;
  479. }
  480. }
  481. }
  482. .day-num {
  483. display: flex;
  484. align-items: center;
  485. justify-content: space-between;
  486. }
  487. }
  488. .guest-info {
  489. display: flex;
  490. flex-direction: column;
  491. align-items: center;
  492. height: 220rpx;
  493. width: 100%;
  494. margin-top: 40rpx;
  495. .swipe-item {
  496. background-color: #ffffff;
  497. text-indent: 1em;
  498. position: relative;
  499. height: 100%;
  500. color: #333333;
  501. }
  502. .swipe-item::after {
  503. content: "";
  504. position: absolute;
  505. bottom: 0;
  506. left: 0;
  507. width: 100%;
  508. height: 1px;
  509. max-height: 1px;
  510. min-height: 1px;
  511. transform: scaleY(0.5);
  512. background-color: #eeeeee;
  513. }
  514. .u-form {
  515. background-color: #FFFFFF;
  516. .u-form-item {
  517. line-height: 70rpx;
  518. .u-form-item__body {
  519. margin-left: 32rpx;
  520. border-bottom: 2rpx solid #E5E5E5;
  521. }
  522. .u-form-item__body__left__content__label {
  523. font-size: 36rpx;
  524. color: #666666;
  525. }
  526. }
  527. }
  528. }
  529. .u-swipe-action {
  530. .u-swipe-action-item {
  531. margin-top: 40rpx;
  532. .u-form {
  533. background-color: #FFFFFF;
  534. .u-form-item {
  535. line-height: 70rpx;
  536. .u-form-item__body {
  537. margin-left: 32rpx;
  538. border-bottom: 2rpx solid #E5E5E5;
  539. }
  540. .u-form-item__body__left__content__label {
  541. font-size: 36rpx;
  542. color: #666666;
  543. }
  544. }
  545. }
  546. }
  547. }
  548. .add-guest-btn-container {
  549. margin: 30rpx;
  550. padding-bottom: 160rpx;
  551. }
  552. .confirm-btn-container {
  553. margin: 30rpx;
  554. padding-bottom: 100rpx;
  555. transform: translateY(-160rpx);
  556. .u-button__text {
  557. font-size: 30rpx !important;
  558. }
  559. }
  560. .paymentArea {
  561. position: fixed;
  562. bottom: 30rpx;
  563. height: 110rpx;
  564. display: flex;
  565. background-color: #EFEFF4;
  566. z-index: 99;
  567. .completeBtn {
  568. width: 50vw;
  569. .u-button {
  570. height: 110rpx;
  571. color: #ffffff;
  572. background-color: #F78203;
  573. display: flex;
  574. align-items: center;
  575. justify-content: center;
  576. font-size: 35rpx !important;
  577. }
  578. }
  579. .paymentArea--left {
  580. .price {
  581. display: block;
  582. margin-left: 20rpx;
  583. width: 50vw;
  584. line-height: 60rpx;
  585. font-size: 36rpx;
  586. font-weight: bold;
  587. text {
  588. &:nth-child(2) {
  589. color: #FF5C58;
  590. }
  591. }
  592. }
  593. .deposit {
  594. display: block;
  595. margin-left: 20rpx;
  596. width: 50vw;
  597. line-height: 40rpx;
  598. font-size: 24rpx;
  599. color: #666666;
  600. }
  601. }
  602. .deposit {
  603. display: block;
  604. }
  605. }
  606. </style>