extend.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <view>
  3. <view class="top">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar title="我的订单" control="back" bgcolor="#9e97c3"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar title="我的订单" bgcolor="#9e97c3"></NavigateBar>
  9. <!-- #endif -->
  10. </view>
  11. <view v-if="roomTypePicPath">
  12. <view class="top-background">
  13. <view class="room-type-item">
  14. <view class="room-type-item-left">
  15. <u-image :src="roomTypePicPath" width="200rpx" height="200rpx" radius="10"></u-image>
  16. </view>
  17. <view class="room-type-item-middle">
  18. <view class="room-type-item-middle-text">
  19. <u-text :text="roomInfo" color="#333333" size="32rpx" bold></u-text>
  20. </view>
  21. <!-- <view class="room-type-item-middle-bottom">
  22. <u-text :text="roomArea" color="#666666"></u-text>
  23. </view> -->
  24. </view>
  25. <view class="room-type-item-right">
  26. <view class="room-type-item-right-text">
  27. <u-text :text="'¥'+unitPrice" color="#FF5C58" align="right" size="24px" bold></u-text>
  28. </view>
  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. <view>
  51. <u-text :text="dayNumText" color="#333333" size="15" bold></u-text>
  52. </view>
  53. <view>
  54. <u-text :text="breakfastNumText" color="#333333" size="15" bold></u-text>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="guest-info">
  59. <u-form v-for="info in guestInfos" :key="info.name" labelPosition="left" labelWidth="240rpx"
  60. labelAlign="left">
  61. <u-form-item label="住客姓名" prop="name">
  62. <u-text :text="info.name" color="#333333" bold size="16"></u-text>
  63. </u-form-item>
  64. <u-form-item label="联系电话" prop="phone">
  65. <u-text :text="info.phone" color="#333333" bold size="16"></u-text>
  66. </u-form-item>
  67. <u-form-item label="离店时间">
  68. <u-text :text="endTime" color="#333333" bold size="16"></u-text>
  69. </u-form-item>
  70. </u-form>
  71. </view>
  72. <view class="end-time-tip">
  73. <u-text :text="endTimeTip" align="center"></u-text>
  74. </view>
  75. <view class="btn-area">
  76. <button v-if="fromExtend == true" class="btn" hover-class="btn-hover" @click="showCalendar">续住</button>
  77. <button v-else class="btn" hover-class="btn-hover" @click="confirmCheckout">退房</button>
  78. </view>
  79. <view>
  80. <u-calendar :show="calendarShow" mode="single" title="选择离店日期" @confirm="confirmEndTime"
  81. @close="calendarShow=false" :minDate="minDate" :defaultDate="minDate" color="#9e97c3"></u-calendar>
  82. </view>
  83. </view>
  84. <view v-else>
  85. <view class="not-reservation">
  86. <u-text class="tip" text="您还未入住!" align="center"></u-text>
  87. <!-- <u-text v-if="fromExtend" class="tip" text="若已退房或房间到期,请至前台办理" align="center"></u-text> -->
  88. <u-text class="tip" text="若已退房或房间到期,请至前台办理" align="center"></u-text>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import {
  95. getDay
  96. } from '../../utils/commonUtils.js'
  97. import {
  98. IMG_BASE_URL
  99. } from "../../config.js"
  100. import moment from 'moment'
  101. import {
  102. mapState,
  103. mapMutations
  104. } from 'vuex'
  105. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  106. export default {
  107. components: {
  108. NavigateBar
  109. },
  110. data() {
  111. return {
  112. roomTypePicPath: '',
  113. roomInfo: '',
  114. unitPrice: '',
  115. roomArea: '',
  116. start: {},
  117. end: {},
  118. dayNumText: '',
  119. guestInfos: [],
  120. calendarShow: false,
  121. minDate: '',
  122. order: {},
  123. dayNum: '',
  124. newOrderId: '',
  125. fromExtend: true,
  126. newEndTime: '',
  127. checkinInfo: {},
  128. extendButtonLoading: false,
  129. extendButtonLoadingText: '办理中',
  130. endTimePickerShow: false,
  131. maxDate: 0,
  132. oldEndTime: '',
  133. needAuthPay: false,
  134. breakfastNum: 0,
  135. orderId: '',
  136. endTime: '',
  137. canExtend: false,
  138. checkinInfoId: '',
  139. };
  140. },
  141. computed: {
  142. ...mapState('m_user', ['userInfo']),
  143. ...mapState('m_business', ['currentHotel']),
  144. breakfastNumText() {
  145. return this.breakfastNum ? `含${this.breakfastNum}早` : '不含早'
  146. },
  147. endTimeTip() {
  148. let text
  149. if (this.fromExtend) {
  150. text = '续住'
  151. } else {
  152. text = '退房'
  153. }
  154. return '请在 ' + this.currentHotel.checkoutTime + ' 前办理' + text + ',逾期请至前台办理'
  155. }
  156. },
  157. methods: {
  158. ...mapMutations('m_business', ['updateCheckinInfo']),
  159. confirmCheckout() {
  160. uni.showModal({
  161. title: '您确定退房吗?',
  162. success: (res) => {
  163. if (res.confirm) {
  164. this.checkout()
  165. }
  166. }
  167. })
  168. },
  169. async checkout() {
  170. let res = await uni.$http.post(`/scm/checkout/${this.checkinInfoId}`);
  171. if (res.data.success === true) {
  172. this.updateCheckinInfo({})
  173. uni.$showMsg('退房办理成功!')
  174. setTimeout(() => {
  175. uni.switchTab({
  176. url: '/pages/home/home'
  177. })
  178. }, 1000)
  179. } else {
  180. uni.$showMsg('退房失败,请至前台办理')
  181. }
  182. },
  183. async queryCanExtend() {
  184. let res = await uni.$http.get(`/scm/canExtend/${this.orderId}`)
  185. if (res.data.data == true) {
  186. this.canExtend = true
  187. } else {
  188. this.canExtend = false
  189. }
  190. },
  191. showCalendar() {
  192. if (!this.canExtend) {
  193. uni.$showMsg('不满足续住条件,请至前台办理')
  194. return
  195. }
  196. this.calendarShow = true
  197. },
  198. async extend() {
  199. let res = await uni.$http.post(`/scm/extend/${this.newOrderId}`);
  200. if (res.data.success === true) {
  201. this.updateCheckinInfo({})
  202. uni.$showMsg('续住办理成功!')
  203. setTimeout(() => {
  204. uni.switchTab({
  205. url: '/pages/home/home'
  206. })
  207. }, 2000)
  208. } else {
  209. uni.$showMsg('续住办理失败')
  210. }
  211. },
  212. async confirmEndTime(e) {
  213. this.newEndTime = e[0]
  214. this.dayNum = (new Date(e[0]).getTime() - new Date(this.minDate).getTime()) / (24 * 60 * 60 * 1000) + 1
  215. uni.showModal({
  216. title: '确认续住' + this.dayNum + '天吗?',
  217. success: (res) => {
  218. if (res.confirm) {
  219. this.calendarShow = false
  220. this.createExtendOrder()
  221. }
  222. }
  223. })
  224. },
  225. async createExtendOrder() {
  226. let info = {
  227. id: this.checkinInfoId,
  228. dayNum: this.dayNum
  229. }
  230. let createRes = await uni.$http.post('/scm/extend/orderId', info)
  231. if (createRes.data.code === 200) {
  232. let resData = createRes.data.data
  233. this.newOrderId = resData.orderId
  234. this.needAuthPay = resData.needAuthPay
  235. this.pay(this.newOrderId)
  236. } else {
  237. uni.$showMsg('订单不满足续住条件,请至前台办理')
  238. }
  239. },
  240. async pay(orderId) {
  241. console.log("pay start");
  242. // #ifdef MP-WEIXIN
  243. if (this.currentHotel.paymentChannel === "YST") {
  244. await this.ystPayment(orderId)
  245. } else {
  246. let res = await uni.$http.post('/order/payment/weChat', {
  247. openid: this.userInfo.openid,
  248. orderId: orderId,
  249. })
  250. res.data.data.package = res.data.data.packageStr
  251. let paymentResult = await wx.requestPayment(res.data.data)
  252. console.log("payment result:", paymentResult)
  253. if (paymentResult.errMsg === 'requestPayment:ok') {
  254. uni.$showMsg("支付成功")
  255. this.extend()
  256. }
  257. }
  258. // #endif
  259. // #ifdef MP-ALIPAY
  260. if (!this.needAuthPay) {
  261. await this.aliPaymentNormal(orderId)
  262. } else {
  263. await this.aliPaymentFreeze(orderId)
  264. }
  265. // #endif
  266. },
  267. async ystPayment(orderId) {
  268. const {miniProgram: {appId}} = uni.getAccountInfoSync();
  269. // console.log("小程序信息", appId);
  270. const {data: submitRes} = await uni.$http.post('/order/payment/ystPay', {
  271. openid: this.userInfo.openid,
  272. orderId: orderId,
  273. appId: appId
  274. })
  275. // console.log("订单提交结果", submitRes)
  276. const payData = JSON.parse(submitRes.data)
  277. // console.log("支付数据", payData);
  278. const paymentResult = await wx.requestPayment(payData)
  279. // console.log("payment result:", paymentResult)
  280. // 调用支付成功,查询下订单支付情况
  281. const {data: paymentRes} = await uni.$http.post('/order/payment/queryYstPay', {
  282. openid: this.userInfo.openid,
  283. orderId: orderId,
  284. appId: appId
  285. })
  286. console.log("订单支付结果", paymentRes)
  287. if (paymentRes.success && paymentRes.data === "S") {
  288. uni.$showMsg("支付成功")
  289. this.extend()
  290. }
  291. },
  292. async getCheckinInfo() {
  293. let res = await uni.$http.get(`/user/checkinInfo/${this.currentHotel.hotelId}`);
  294. if (res.data.code == 200) {
  295. let checkinInfo = res.data.data
  296. // console.log(checkinInfo)
  297. if (checkinInfo) {
  298. this.roomTypePicPath = IMG_BASE_URL + '/' + checkinInfo.roomPicPath
  299. this.roomInfo = checkinInfo.roomTypeName + checkinInfo.room
  300. this.unitPrice = checkinInfo.unitPrice
  301. this.breakfastNum = checkinInfo.breakfastNum
  302. this.endTime = moment(checkinInfo.endTime).format('M月DD日 HH:mm')
  303. this.orderId = checkinInfo.orderId
  304. this.checkinInfoId = checkinInfo.id
  305. let guest = {
  306. name: checkinInfo.name,
  307. phone: checkinInfo.phone
  308. }
  309. // if (order) {
  310. // this.order = order
  311. // this.roomTypePicPath = IMG_BASE_URL + '/' + order.roomPicPath
  312. // this.roomInfo = order.roomTypeName + order.room
  313. // this.unitPrice = '¥' + order.unitPrice
  314. // } else {
  315. // let roomInfoRes = await uni.$http.post('/roomInfo', {
  316. // hotelId: this.checkinInfo.hotelId,
  317. // room: this.checkinInfo.room,
  318. // pageNo: 1,
  319. // pageSize: 1
  320. // })
  321. // console.log('roominfo', roomInfoRes)
  322. // let roomTypeRes = await uni.$http.post('/roomType', {
  323. // roomType: roomInfoRes.data.data.records[0].roomType,
  324. // pageNo: 1,
  325. // pageSize: 1
  326. // })
  327. // let roomType = roomTypeRes.data.data.records[0]
  328. // this.roomTypePicPath = IMG_BASE_URL + '/' + roomType.roomPicPath
  329. // this.roomInfo = roomType.roomTypeName + this.checkinInfo.room
  330. // this.unitPrice = '¥' + roomType.unitPrice
  331. // }
  332. this.guestInfos.push(guest)
  333. let originEndTime = new Date(checkinInfo.endTime);
  334. this.newEndTime = new Date(originEndTime.valueOf() + 24 * 60 * 60 * 1000)
  335. this.oldEndTime = checkinInfo.endTime
  336. this.start.date = moment(checkinInfo.startTime).format('MM月DD日')
  337. this.start.day = getDay(new Date(checkinInfo.startTime).getDay())
  338. this.end.date = moment(checkinInfo.endTime).format('MM月DD日')
  339. this.end.day = getDay(new Date(checkinInfo.endTime).getDay())
  340. this.dayNumText = '共' + checkinInfo.dayNum + '晚'
  341. //设置日历
  342. let endDate = new Date(checkinInfo.endTime)
  343. endDate.setDate(endDate.getDate() + 1)
  344. this.minDate = moment(new Date(endDate)).format('YYYY-MM-DD')
  345. } else {
  346. this.checkinInfo = {}
  347. }
  348. } else {
  349. // #ifdef MP-WEIXIN
  350. uni.$showMsg('查询失败!')
  351. // #endif
  352. }
  353. },
  354. // #ifdef MP-ALIPAY
  355. async aliPaymentNormal(orderId) {
  356. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  357. openid: this.userInfo.openid,
  358. orderId: orderId,
  359. platform: 'ALIPAY',
  360. hotelId: this.currentHotel.hotelId
  361. })
  362. // console.log("获取预付号",alipayRes.data.data)
  363. let tradeNo = alipayRes.data.data.tradeNo
  364. let tradeRes = await my.tradePay({
  365. tradeNO: tradeNo
  366. })
  367. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  368. if (tradeRes.resultCode === "6002") {
  369. // 网络连接出错
  370. uni.showModal({
  371. title: "网络连接出错",
  372. content: "网络连接出错,请检查网络连接后重试。",
  373. });
  374. }
  375. // 顾客支付后,查询支付状态
  376. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  377. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  378. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  379. tradeNo: tradeNo,
  380. hotelId: this.currentHotel.hotelId
  381. })
  382. // console.log("tradeStatus", tradeStatus);
  383. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  384. uni.$showMsg("支付成功")
  385. this.extend()
  386. }
  387. }
  388. },
  389. async aliPaymentFreeze(orderId) {
  390. // 申请获取签名字符串
  391. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  392. orderId: orderId,
  393. hotelId: this.currentHotel.hotelId
  394. })
  395. // console.log("签名字符串", alipayRes.data)
  396. if (!alipayRes.data.success) {
  397. console.log("获取签名字符串");
  398. uni.showModal({
  399. title: "网络连接出错。",
  400. content: "网络连接出错,请检查网络连接后重试。",
  401. });
  402. return
  403. }
  404. // 根据签名字符串发起授权
  405. let orderString = alipayRes.data.data
  406. let tradeRes = await my.tradePay({
  407. orderStr: orderString
  408. })
  409. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  410. if (tradeRes.resultCode === "6002") {
  411. // 网络连接出错
  412. uni.showModal({
  413. title: "网络连接出错",
  414. content: "网络连接出错,请检查网络连接后重试。",
  415. });
  416. }
  417. // 顾客授权后,查询授权状态
  418. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  419. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  420. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  421. orderId: orderId,
  422. hotelId: this.currentHotel.hotelId
  423. })
  424. // console.log("tradeStatus", tradeStatus);
  425. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  426. uni.$showMsg("支付成功")
  427. this.extend()
  428. }
  429. }
  430. }
  431. // #endif
  432. },
  433. async onLoad(options) {
  434. await this.getCheckinInfo()
  435. if (!this.roomTypePicPath) {
  436. return
  437. }
  438. this.fromExtend = options.fromExtend == 'true'
  439. if (this.fromExtend) {
  440. await this.queryCanExtend()
  441. }
  442. },
  443. // #ifdef MP-WEIXIN
  444. onShareAppMessage(info) {
  445. return {
  446. title: '源享住',
  447. path: 'pages/login/login',
  448. imageUrl: "/static/logo.png"
  449. }
  450. }
  451. // #endif
  452. }
  453. </script>
  454. <style lang="scss">
  455. page {
  456. background-color: #FFFFFF;
  457. .top-background {
  458. background-color: #9e97c3;
  459. overflow: hidden;
  460. .room-type-item {
  461. border-radius: 30rpx;
  462. background-color: #FFFFFF;
  463. margin: 120rpx 20rpx;
  464. padding: 20rpx;
  465. display: flex;
  466. border-radius: 10rpx;
  467. .room-type-item-middle {
  468. margin-top: 40rpx;
  469. margin-left: 30rpx;
  470. display: flex;
  471. flex-direction: column;
  472. width: 280rpx;
  473. .room-type-item-middle-text {
  474. font-size: 40rpx;
  475. font-weight: bold;
  476. color: #333333;
  477. }
  478. .room-type-item-middle-bottom {
  479. margin-top: 40rpx;
  480. font-size: 25rpx;
  481. text {
  482. margin-right: 20rpx;
  483. color: #666666
  484. }
  485. }
  486. }
  487. .room-type-item-right {
  488. width: 25%;
  489. margin-right: 20rpx;
  490. .room-type-item-right-text {
  491. margin-left: 60rpx;
  492. margin-top: 70rpx;
  493. }
  494. text {
  495. font-size: 40rpx;
  496. font-weight: bold;
  497. color: #FF5C58
  498. }
  499. }
  500. }
  501. }
  502. }
  503. .checkin-date-info {
  504. transform: translateY(-100rpx);
  505. border-radius: 30rpx;
  506. background-color: #FFFFFF;
  507. margin: 20rpx;
  508. padding: 20rpx;
  509. display: flex;
  510. background: #FFFFFF;
  511. border-radius: 10rpx;
  512. box-shadow: 0rpx 8rpx 11rpx 2rpx rgba(79, 121, 225, 0.19);
  513. .date-selector {
  514. margin: 20rpx;
  515. display: flex;
  516. width: 70vw;
  517. .date-item {
  518. width: 35vw;
  519. .date-info {
  520. display: flex;
  521. }
  522. }
  523. }
  524. .day-num {
  525. display: flex;
  526. flex-direction: column;
  527. align-items: center;
  528. justify-content: space-around;
  529. }
  530. }
  531. .u-form {
  532. transform: translateY(-100rpx);
  533. background-color: #FFFFFF;
  534. .u-form-item {
  535. line-height: 70rpx;
  536. .u-form-item__body {
  537. margin-left: 32rpx;
  538. margin-right: 32rpx;
  539. border-bottom: 2rpx solid #E5E5E5;
  540. }
  541. .u-form-item__body__left__content__label {
  542. font-size: 36rpx;
  543. color: #666666;
  544. }
  545. }
  546. }
  547. .btn-area {
  548. transform: translateY(-60rpx);
  549. display: flex;
  550. justify-content: space-evenly;
  551. .btn {
  552. color: #9e97c3;
  553. border: 1rpx solid #9e97c3;
  554. background-color: #FFFFFF;
  555. font-weight: bold;
  556. font-size: 33rpx;
  557. width: 250rpx;
  558. }
  559. .btn-hover {
  560. color: #FFFFFF;
  561. background-color: #9e97c3;
  562. }
  563. }
  564. .not-reservation {
  565. margin-top: 40%;
  566. }
  567. .end-time-tip {
  568. transform: translateY(-100rpx);
  569. }
  570. </style>