extend.vue 16 KB

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