extend.vue 16 KB

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