extend.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. uni.$showMsg('查询失败!')
  316. }
  317. },
  318. // #ifdef MP-ALIPAY
  319. async aliPaymentNormal(orderId) {
  320. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  321. openid: this.userInfo.openid,
  322. orderId: orderId,
  323. platform: 'ALIPAY',
  324. hotelId: this.currentHotel.hotelId
  325. })
  326. // console.log("获取预付号",alipayRes.data.data)
  327. let tradeNo = alipayRes.data.data.tradeNo
  328. let tradeRes = await my.tradePay({
  329. tradeNO: tradeNo
  330. })
  331. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  332. if (tradeRes.resultCode === "6002") {
  333. // 网络连接出错
  334. uni.showModal({
  335. title: "网络连接出错",
  336. content: "网络连接出错,请检查网络连接后重试。",
  337. });
  338. }
  339. // 顾客支付后,查询支付状态
  340. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  341. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  342. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  343. tradeNo: tradeNo,
  344. hotelId: this.currentHotel.hotelId
  345. })
  346. // console.log("tradeStatus", tradeStatus);
  347. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  348. uni.$showMsg("支付成功")
  349. this.extend()
  350. }
  351. }
  352. },
  353. async aliPaymentFreeze(orderId) {
  354. // 申请获取签名字符串
  355. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  356. orderId: orderId,
  357. hotelId: this.currentHotel.hotelId
  358. })
  359. // console.log("签名字符串", alipayRes.data)
  360. if (!alipayRes.data.success) {
  361. console.log("获取签名字符串");
  362. uni.showModal({
  363. title: "网络连接出错。",
  364. content: "网络连接出错,请检查网络连接后重试。",
  365. });
  366. return
  367. }
  368. // 根据签名字符串发起授权
  369. let orderString = alipayRes.data.data
  370. let tradeRes = await my.tradePay({
  371. orderStr: orderString
  372. })
  373. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  374. if (tradeRes.resultCode === "6002") {
  375. // 网络连接出错
  376. uni.showModal({
  377. title: "网络连接出错",
  378. content: "网络连接出错,请检查网络连接后重试。",
  379. });
  380. }
  381. // 顾客授权后,查询授权状态
  382. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  383. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  384. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  385. orderId: orderId,
  386. hotelId: this.currentHotel.hotelId
  387. })
  388. // console.log("tradeStatus", tradeStatus);
  389. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  390. uni.$showMsg("支付成功")
  391. this.extend()
  392. }
  393. }
  394. }
  395. // #endif
  396. },
  397. async onLoad(options) {
  398. await this.getCheckinInfo()
  399. this.fromExtend = options.fromExtend == 'true'
  400. },
  401. onShow() {
  402. this.extendTip = '请在 ' + this.currentHotel.checkoutTime + ' 前办理续住,逾期请至前台办理'
  403. },
  404. // #ifdef MP-WEIXIN
  405. onShareAppMessage(info) {
  406. return {
  407. title: '源享住',
  408. path: 'pages/login/login',
  409. imageUrl: "/static/logo.png"
  410. }
  411. }
  412. // #endif
  413. }
  414. </script>
  415. <style lang="scss">
  416. page {
  417. background-color: #FFFFFF;
  418. .top-background {
  419. background-color: #9e97c3;
  420. overflow: hidden;
  421. .room-type-item {
  422. border-radius: 30rpx;
  423. background-color: #FFFFFF;
  424. margin: 120rpx 20rpx;
  425. padding: 20rpx;
  426. display: flex;
  427. border-radius: 10rpx;
  428. .room-type-item-middle {
  429. margin-top: 40rpx;
  430. margin-left: 30rpx;
  431. display: flex;
  432. flex-direction: column;
  433. width: 280rpx;
  434. .room-type-item-middle-text {
  435. font-size: 40rpx;
  436. font-weight: bold;
  437. color: #333333;
  438. }
  439. .room-type-item-middle-bottom {
  440. margin-top: 40rpx;
  441. font-size: 25rpx;
  442. text {
  443. margin-right: 20rpx;
  444. color: #666666
  445. }
  446. }
  447. }
  448. .room-type-item-right {
  449. width: 25%;
  450. margin-right: 20rpx;
  451. .room-type-item-right-text {
  452. margin-left: 60rpx;
  453. margin-top: 70rpx;
  454. }
  455. text {
  456. font-size: 40rpx;
  457. font-weight: bold;
  458. color: #FF5C58
  459. }
  460. }
  461. }
  462. }
  463. }
  464. .checkin-date-info {
  465. transform: translateY(-100rpx);
  466. border-radius: 30rpx;
  467. background-color: #FFFFFF;
  468. margin: 20rpx;
  469. padding: 20rpx;
  470. display: flex;
  471. background: #FFFFFF;
  472. border-radius: 10rpx;
  473. box-shadow: 0rpx 8rpx 11rpx 2rpx rgba(79, 121, 225, 0.19);
  474. .date-selector {
  475. margin: 20rpx;
  476. display: flex;
  477. width: 70vw;
  478. .date-item {
  479. width: 35vw;
  480. .date-info {
  481. display: flex;
  482. }
  483. }
  484. }
  485. .day-num {
  486. display: flex;
  487. align-items: center;
  488. justify-content: space-between;
  489. }
  490. }
  491. .u-form {
  492. transform: translateY(-100rpx);
  493. background-color: #FFFFFF;
  494. .u-form-item {
  495. line-height: 70rpx;
  496. .u-form-item__body {
  497. margin-left: 32rpx;
  498. margin-right: 32rpx;
  499. border-bottom: 2rpx solid #E5E5E5;
  500. }
  501. .u-form-item__body__left__content__label {
  502. font-size: 36rpx;
  503. color: #666666;
  504. }
  505. }
  506. }
  507. .btn-area {
  508. transform: translateY(-60rpx);
  509. display: flex;
  510. justify-content: space-evenly;
  511. .btn {
  512. color: #9e97c3;
  513. border: 1rpx solid #9e97c3;
  514. background-color: #FFFFFF;
  515. font-weight: bold;
  516. font-size: 33rpx;
  517. width: 250rpx;
  518. }
  519. .btn-hover {
  520. color: #FFFFFF;
  521. background-color: #9e97c3;
  522. }
  523. }
  524. .not-reservation {
  525. margin-top: 40%;
  526. }
  527. .extend-tip {
  528. transform: translateY(-100rpx);
  529. }
  530. </style>