confirmOrder.vue 16 KB

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