confirmOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. uni.showModal({
  219. content: '房间已被占用,请重新选房',
  220. showCancel: false,
  221. success: (res) => {
  222. if (res.confirm) {
  223. uni.navigateTo({
  224. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  225. this.order.roomType
  226. })
  227. }
  228. }
  229. })
  230. }
  231. // #endif
  232. // #ifdef MP-ALIPAY
  233. if (Number(this.order.deposit) === 0) {
  234. await this.aliPaymentNormal()
  235. } else {
  236. await this.aliPaymentFreeze()
  237. }
  238. // #endif
  239. },
  240. // #ifdef MP-ALIPAY
  241. onSwipeStart() {
  242. this.swipeIndex = ""
  243. },
  244. onSwipeEnd(arg1, arg2) {
  245. console.log(arg1, arg2);
  246. let index = arg2.target.dataset.item
  247. if (arg1.swiped) {
  248. this.swipeIndex = index
  249. }
  250. },
  251. deleteGuestAli() {
  252. this.checkinInfo.splice(this.swipeIndex, 1)
  253. this.updateCheckinInfo(this.checkinInfo)
  254. },
  255. async aliPaymentNormal() {
  256. // 申请获取预付号
  257. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  258. openid: this.userInfo.openid,
  259. orderId: this.order.orderId,
  260. platform: 'ALIPAY',
  261. hotelId: this.currentHotel.hotelId
  262. })
  263. // console.log("获取预付号",alipayRes.data)
  264. if (!alipayRes.data.success) {
  265. console.log("获取预付号失败");
  266. uni.showModal({
  267. content: '房间已被占用,请重新选房',
  268. showCancel: false,
  269. success: (res) => {
  270. if (res.confirm) {
  271. uni.navigateTo({
  272. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  273. this.order.roomType
  274. })
  275. }
  276. }
  277. })
  278. return
  279. }
  280. // 根据预付号发起支付
  281. let tradeNo = alipayRes.data.data.tradeNo
  282. let tradeRes = await my.tradePay({
  283. tradeNO: tradeNo
  284. })
  285. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  286. if (tradeRes.resultCode === "6001") {
  287. console.log("支付未完成。");
  288. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  289. }
  290. if (tradeRes.resultCode === "6002") {
  291. // 网络连接出错
  292. uni.showModal({
  293. title: "网络连接出错",
  294. content: "网络连接出错,请检查网络连接后重试。",
  295. });
  296. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  297. }
  298. // 顾客支付后,查询支付状态
  299. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  300. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  301. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  302. tradeNo: tradeNo,
  303. hotelId: this.currentHotel.hotelId
  304. })
  305. // console.log("tradeStatus", tradeStatus);
  306. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  307. uni.$showMsg("支付成功")
  308. uni.navigateTo({
  309. url: '/subpkg_checkin/checkin/checkin'
  310. })
  311. } else {
  312. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  313. }
  314. }
  315. },
  316. async aliPaymentFreeze() {
  317. // 申请获取签名字符串
  318. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  319. orderId: this.order.orderId,
  320. hotelId: this.currentHotel.hotelId
  321. })
  322. console.log("签名字符串", alipayRes.data)
  323. if (!alipayRes.data.success) {
  324. console.log("获取签名字符串失败");
  325. uni.showModal({
  326. content: '房间已被占用,请重新选房',
  327. showCancel: false,
  328. success: (res) => {
  329. if (res.confirm) {
  330. uni.navigateTo({
  331. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  332. this.order.roomType
  333. })
  334. }
  335. }
  336. })
  337. return
  338. }
  339. // 根据签名字符串发起授权
  340. let orderString = alipayRes.data.data
  341. let tradeRes = await my.tradePay({
  342. orderStr: orderString
  343. })
  344. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  345. if (tradeRes.resultCode === "6001") {
  346. console.log("支付未完成。");
  347. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  348. }
  349. if (tradeRes.resultCode === "6002") {
  350. // 网络连接出错
  351. uni.showModal({
  352. title: "网络连接出错",
  353. content: "网络连接出错,请检查网络连接后重试。",
  354. });
  355. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  356. }
  357. // 顾客授权后,查询授权状态
  358. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  359. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  360. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  361. orderId: this.order.orderId,
  362. hotelId: this.currentHotel.hotelId
  363. })
  364. // console.log("tradeStatus", tradeStatus);
  365. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  366. uni.$showMsg("支付成功")
  367. uni.navigateTo({
  368. url: '/subpkg_checkin/checkin/checkin'
  369. })
  370. } else {
  371. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  372. }
  373. }
  374. }
  375. // #endif
  376. },
  377. async onLoad() {
  378. let res = await uni.$http.post('/roomType', {
  379. roomType: this.order.roomType,
  380. hotelId: this.currentHotel.hotelId,
  381. pageNo: 1,
  382. pageSize: 999
  383. })
  384. this.roomPicPath = IMG_BASE_URL + '/' + res.data.data.records[0].roomPicPath
  385. this.roomTypeName = res.data.data.records[0].roomTypeName
  386. this.unitPrice = res.data.data.records[0].unitPrice
  387. this.startDate = moment(new Date(this.order.startTime)).format('MM月DD日')
  388. this.startDay = getDay(new Date(this.order.startTime).getDay())
  389. this.endDate = moment(new Date(this.order.endTime)).format('MM月DD日')
  390. this.endDay = getDay(new Date(this.order.endTime).getDay())
  391. },
  392. // #ifdef MP-WEIXIN
  393. onShareAppMessage(info) {
  394. return {
  395. title: '源享住',
  396. path: 'pages/login/login',
  397. imageUrl: "/static/logo.png"
  398. }
  399. }
  400. // #endif
  401. }
  402. </script>
  403. <style lang="scss">
  404. page {
  405. background-color: #EFEFF4;
  406. }
  407. .room-type-item {
  408. border-radius: 30rpx;
  409. background-color: #FFFFFF;
  410. margin: 20rpx;
  411. padding: 40rpx 20rpx;
  412. display: flex;
  413. background: #FFFFFF;
  414. border-radius: 10rpx;
  415. .room-type-item-middle {
  416. margin-left: 30rpx;
  417. display: flex;
  418. flex-direction: column;
  419. width: 200rpx;
  420. .room-type-item-middle-text {
  421. font-size: 40rpx;
  422. font-weight: bold;
  423. color: #333333;
  424. }
  425. .room-type-item-middle-bottom {
  426. margin-top: 40rpx;
  427. font-size: 25rpx;
  428. text {
  429. margin-right: 20rpx;
  430. color: #666666
  431. }
  432. }
  433. }
  434. .room-type-item-right {
  435. width: 25%;
  436. margin-left: 20rpx;
  437. .room-type-item-right-text {
  438. margin-left: 60rpx;
  439. margin-top: 40rpx;
  440. }
  441. text {
  442. font-size: 40rpx;
  443. font-weight: bold;
  444. color: #FF5C58
  445. }
  446. }
  447. }
  448. .checkin-date-info {
  449. border-radius: 30rpx;
  450. background-color: #FFFFFF;
  451. margin: 20rpx 20rpx;
  452. padding: 20rpx;
  453. display: flex;
  454. background: #FFFFFF;
  455. border-radius: 10rpx;
  456. .date-selector {
  457. margin: 20rpx;
  458. display: flex;
  459. width: 70vw;
  460. .date-item {
  461. width: 35vw;
  462. .date-info {
  463. display: flex;
  464. }
  465. }
  466. }
  467. .day-num {
  468. display: flex;
  469. align-items: center;
  470. justify-content: space-between;
  471. }
  472. }
  473. .guest-info {
  474. display: flex;
  475. flex-direction: column;
  476. align-items: center;
  477. height: 220rpx;
  478. width: 100%;
  479. margin-top: 40rpx;
  480. .swipe-item {
  481. background-color: #ffffff;
  482. text-indent: 1em;
  483. position: relative;
  484. height: 100%;
  485. color: #333333;
  486. }
  487. .swipe-item::after {
  488. content: "";
  489. position: absolute;
  490. bottom: 0;
  491. left: 0;
  492. width: 100%;
  493. height: 1px;
  494. max-height: 1px;
  495. min-height: 1px;
  496. transform: scaleY(0.5);
  497. background-color: #eeeeee;
  498. }
  499. .u-form {
  500. background-color: #FFFFFF;
  501. .u-form-item {
  502. line-height: 70rpx;
  503. .u-form-item__body {
  504. margin-left: 32rpx;
  505. border-bottom: 2rpx solid #E5E5E5;
  506. }
  507. .u-form-item__body__left__content__label {
  508. font-size: 36rpx;
  509. color: #666666;
  510. }
  511. }
  512. }
  513. }
  514. .u-swipe-action {
  515. .u-swipe-action-item {
  516. margin-top: 40rpx;
  517. .u-form {
  518. background-color: #FFFFFF;
  519. .u-form-item {
  520. line-height: 70rpx;
  521. .u-form-item__body {
  522. margin-left: 32rpx;
  523. border-bottom: 2rpx solid #E5E5E5;
  524. }
  525. .u-form-item__body__left__content__label {
  526. font-size: 36rpx;
  527. color: #666666;
  528. }
  529. }
  530. }
  531. }
  532. }
  533. .add-guest-btn-container {
  534. margin: 30rpx;
  535. padding-bottom: 160rpx;
  536. }
  537. .confirm-btn-container {
  538. margin: 30rpx;
  539. padding-bottom: 100rpx;
  540. transform: translateY(-160rpx);
  541. .u-button__text {
  542. font-size: 30rpx !important;
  543. }
  544. }
  545. .paymentArea {
  546. position: fixed;
  547. bottom: 30rpx;
  548. height: 110rpx;
  549. display: flex;
  550. background-color: #EFEFF4;
  551. z-index: 99;
  552. .completeBtn {
  553. width: 50vw;
  554. .u-button {
  555. height: 110rpx;
  556. color: #ffffff;
  557. background-color: #F78203;
  558. display: flex;
  559. align-items: center;
  560. justify-content: center;
  561. font-size: 35rpx !important;
  562. }
  563. }
  564. .paymentArea--left {
  565. .price {
  566. display: block;
  567. margin-left: 20rpx;
  568. width: 50vw;
  569. line-height: 60rpx;
  570. font-size: 36rpx;
  571. font-weight: bold;
  572. text {
  573. &:nth-child(2) {
  574. color: #FF5C58;
  575. }
  576. }
  577. }
  578. .deposit {
  579. display: block;
  580. margin-left: 20rpx;
  581. width: 50vw;
  582. line-height: 40rpx;
  583. font-size: 24rpx;
  584. color: #666666;
  585. }
  586. }
  587. .deposit {
  588. display: block;
  589. }
  590. }
  591. </style>