extend.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. let res = await uni.$http.post('/checkinInfo/queryByCondition', {
  244. userIdNumber: this.userInfo.idNumber,
  245. status: 1,
  246. hotelId: this.currentHotel.hotelId,
  247. pageNo: 1,
  248. pageSize: 1
  249. });
  250. if (res.data.code == 200) {
  251. if (res.data.data.records.length > 0) {
  252. console.log(res.data.data.records[0].endTime)
  253. let originEndTime = new Date(res.data.data.records[0].endTime);
  254. this.newEndTime = new Date(originEndTime.valueOf() + 24 * 60 * 60 * 1000)
  255. this.oldEndTime = res.data.data.records[0].endTime
  256. this.checkinInfo = res.data.data.records[0];
  257. //根据订单号查询订单信息
  258. let orderRes = await uni.$http.post('/hotelOrder/queryByCondition', {
  259. orderId: this.checkinInfo.orderId,
  260. hotelId: this.currentHotel.hotelId,
  261. pageNo: 1,
  262. pageSize: 1
  263. });
  264. let guest = {}
  265. guest.name = this.checkinInfo.customerName
  266. let order = orderRes.data.data.records[0]
  267. //查询到订单则直接按订单内容显示,否则
  268. if (order) {
  269. this.order = order
  270. this.roomTypePicPath = IMG_BASE_URL + '/' + order.roomPicPath
  271. this.roomInfo = order.roomTypeName + order.room
  272. this.unitPrice = '¥' + order.unitPrice
  273. guest.phone = order.checkinPhone
  274. } else {
  275. let roomInfoRes = await uni.$http.post('/roomInfo', {
  276. hotelId: this.checkinInfo.hotelId,
  277. room: this.checkinInfo.room,
  278. pageNo: 1,
  279. pageSize: 1
  280. })
  281. console.log('roominfo', roomInfoRes)
  282. let roomTypeRes = await uni.$http.post('/roomType', {
  283. roomType: roomInfoRes.data.data.records[0].roomType,
  284. pageNo: 1,
  285. pageSize: 1
  286. })
  287. let roomType = roomTypeRes.data.data.records[0]
  288. this.roomTypePicPath = IMG_BASE_URL + '/' + roomType.roomPicPath
  289. this.roomInfo = roomType.roomTypeName + this.checkinInfo.room
  290. this.unitPrice = '¥' + roomType.unitPrice
  291. }
  292. this.guestInfos.push(guest)
  293. this.start.date = moment(this.checkinInfo.startTime).format('MM月DD日')
  294. this.start.day = getDay(new Date(this.checkinInfo.startTime).getDay())
  295. this.end.date = moment(this.checkinInfo.endTime).format('MM月DD日')
  296. this.end.day = getDay(new Date(this.checkinInfo.endTime).getDay())
  297. let start = new Date(moment(this.checkinInfo.startTime).format('YYYY/MM/DD'))
  298. let end = new Date(moment(this.checkinInfo.endTime).format('YYYY/MM/DD'))
  299. // console.log(start.getTime())
  300. // console.log(end)
  301. let dayNum = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000)
  302. dayNum = dayNum < 1 ? 1 : dayNum
  303. this.dayNumText = '共' + dayNum + '晚'
  304. //设置日历
  305. let endDate = new Date(this.checkinInfo.endTime)
  306. endDate.setDate(endDate.getDate() + 1)
  307. this.minDate = moment(new Date(endDate)).format('YYYY-MM-DD')
  308. // this.defaultDate = moment(new Date(endDate)).format('YYYY-MM-DD')
  309. this.checkinInfo.startTime = moment(this.checkinInfo.startTime).format('YYYY/MM/DD HH:mm')
  310. this.checkinInfo.endTime = moment(this.checkinInfo.endTime).format('YYYY/MM/DD HH:mm')
  311. } else {
  312. this.checkinInfo = {}
  313. }
  314. } else {
  315. // #ifdef MP-WEIXIN
  316. uni.$showMsg('查询失败!')
  317. // #endif
  318. }
  319. },
  320. // #ifdef MP-ALIPAY
  321. async aliPaymentNormal(orderId) {
  322. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  323. openid: this.userInfo.openid,
  324. orderId: orderId,
  325. platform: 'ALIPAY',
  326. hotelId: this.currentHotel.hotelId
  327. })
  328. // console.log("获取预付号",alipayRes.data.data)
  329. let tradeNo = alipayRes.data.data.tradeNo
  330. let tradeRes = await my.tradePay({
  331. tradeNO: tradeNo
  332. })
  333. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  334. if (tradeRes.resultCode === "6002") {
  335. // 网络连接出错
  336. uni.showModal({
  337. title: "网络连接出错",
  338. content: "网络连接出错,请检查网络连接后重试。",
  339. });
  340. }
  341. // 顾客支付后,查询支付状态
  342. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  343. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  344. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  345. tradeNo: tradeNo,
  346. hotelId: this.currentHotel.hotelId
  347. })
  348. // console.log("tradeStatus", tradeStatus);
  349. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  350. uni.$showMsg("支付成功")
  351. this.extend()
  352. }
  353. }
  354. },
  355. async aliPaymentFreeze(orderId) {
  356. // 申请获取签名字符串
  357. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  358. orderId: orderId,
  359. hotelId: this.currentHotel.hotelId
  360. })
  361. // console.log("签名字符串", alipayRes.data)
  362. if (!alipayRes.data.success) {
  363. console.log("获取签名字符串");
  364. uni.showModal({
  365. title: "网络连接出错。",
  366. content: "网络连接出错,请检查网络连接后重试。",
  367. });
  368. return
  369. }
  370. // 根据签名字符串发起授权
  371. let orderString = alipayRes.data.data
  372. let tradeRes = await my.tradePay({
  373. orderStr: orderString
  374. })
  375. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  376. if (tradeRes.resultCode === "6002") {
  377. // 网络连接出错
  378. uni.showModal({
  379. title: "网络连接出错",
  380. content: "网络连接出错,请检查网络连接后重试。",
  381. });
  382. }
  383. // 顾客授权后,查询授权状态
  384. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  385. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  386. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  387. orderId: orderId,
  388. hotelId: this.currentHotel.hotelId
  389. })
  390. // console.log("tradeStatus", tradeStatus);
  391. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  392. uni.$showMsg("支付成功")
  393. this.extend()
  394. }
  395. }
  396. }
  397. // #endif
  398. },
  399. async onLoad(options) {
  400. await this.getCheckinInfo()
  401. this.fromExtend = options.fromExtend == 'true'
  402. },
  403. onShow() {
  404. this.extendTip = '请在 ' + this.currentHotel.checkoutTime + ' 前办理续住,逾期请至前台办理'
  405. },
  406. // #ifdef MP-WEIXIN
  407. onShareAppMessage(info) {
  408. return {
  409. title: '源享住',
  410. path: 'pages/login/login',
  411. imageUrl: "/static/logo.png"
  412. }
  413. }
  414. // #endif
  415. }
  416. </script>
  417. <style lang="scss">
  418. page {
  419. background-color: #FFFFFF;
  420. .top-background {
  421. background-color: #9e97c3;
  422. overflow: hidden;
  423. .room-type-item {
  424. border-radius: 30rpx;
  425. background-color: #FFFFFF;
  426. margin: 120rpx 20rpx;
  427. padding: 20rpx;
  428. display: flex;
  429. border-radius: 10rpx;
  430. .room-type-item-middle {
  431. margin-top: 40rpx;
  432. margin-left: 30rpx;
  433. display: flex;
  434. flex-direction: column;
  435. width: 280rpx;
  436. .room-type-item-middle-text {
  437. font-size: 40rpx;
  438. font-weight: bold;
  439. color: #333333;
  440. }
  441. .room-type-item-middle-bottom {
  442. margin-top: 40rpx;
  443. font-size: 25rpx;
  444. text {
  445. margin-right: 20rpx;
  446. color: #666666
  447. }
  448. }
  449. }
  450. .room-type-item-right {
  451. width: 25%;
  452. margin-right: 20rpx;
  453. .room-type-item-right-text {
  454. margin-left: 60rpx;
  455. margin-top: 70rpx;
  456. }
  457. text {
  458. font-size: 40rpx;
  459. font-weight: bold;
  460. color: #FF5C58
  461. }
  462. }
  463. }
  464. }
  465. }
  466. .checkin-date-info {
  467. transform: translateY(-100rpx);
  468. border-radius: 30rpx;
  469. background-color: #FFFFFF;
  470. margin: 20rpx;
  471. padding: 20rpx;
  472. display: flex;
  473. background: #FFFFFF;
  474. border-radius: 10rpx;
  475. box-shadow: 0rpx 8rpx 11rpx 2rpx rgba(79, 121, 225, 0.19);
  476. .date-selector {
  477. margin: 20rpx;
  478. display: flex;
  479. width: 70vw;
  480. .date-item {
  481. width: 35vw;
  482. .date-info {
  483. display: flex;
  484. }
  485. }
  486. }
  487. .day-num {
  488. display: flex;
  489. align-items: center;
  490. justify-content: space-between;
  491. }
  492. }
  493. .u-form {
  494. transform: translateY(-100rpx);
  495. background-color: #FFFFFF;
  496. .u-form-item {
  497. line-height: 70rpx;
  498. .u-form-item__body {
  499. margin-left: 32rpx;
  500. margin-right: 32rpx;
  501. border-bottom: 2rpx solid #E5E5E5;
  502. }
  503. .u-form-item__body__left__content__label {
  504. font-size: 36rpx;
  505. color: #666666;
  506. }
  507. }
  508. }
  509. .btn-area {
  510. transform: translateY(-60rpx);
  511. display: flex;
  512. justify-content: space-evenly;
  513. .btn {
  514. color: #9e97c3;
  515. border: 1rpx solid #9e97c3;
  516. background-color: #FFFFFF;
  517. font-weight: bold;
  518. font-size: 33rpx;
  519. width: 250rpx;
  520. }
  521. .btn-hover {
  522. color: #FFFFFF;
  523. background-color: #9e97c3;
  524. }
  525. }
  526. .not-reservation {
  527. margin-top: 40%;
  528. }
  529. .extend-tip {
  530. transform: translateY(-100rpx);
  531. }
  532. </style>