extend.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. let res = await uni.$http.post('/order/payment/weChat', {
  244. openid: this.userInfo.openid,
  245. orderId: orderId,
  246. })
  247. res.data.data.package = res.data.data.packageStr
  248. let paymentResult = await wx.requestPayment(res.data.data)
  249. console.log("payment result:", paymentResult)
  250. if (paymentResult.errMsg === 'requestPayment:ok') {
  251. uni.$showMsg("支付成功")
  252. this.extend()
  253. }
  254. // #endif
  255. // #ifdef MP-ALIPAY
  256. if (!this.needAuthPay) {
  257. await this.aliPaymentNormal(orderId)
  258. } else {
  259. await this.aliPaymentFreeze(orderId)
  260. }
  261. // #endif
  262. },
  263. async getCheckinInfo() {
  264. let res = await uni.$http.get(`/user/checkinInfo/${this.currentHotel.hotelId}`);
  265. if (res.data.code == 200) {
  266. let checkinInfo = res.data.data
  267. console.log(checkinInfo)
  268. if (checkinInfo) {
  269. this.roomTypePicPath = IMG_BASE_URL + '/' + checkinInfo.roomPicPath
  270. this.roomInfo = checkinInfo.roomTypeName + checkinInfo.room
  271. this.unitPrice = checkinInfo.unitPrice
  272. this.breakfastNum = checkinInfo.breakfastNum
  273. this.endTime = moment(checkinInfo.endTime).format('M月DD日 HH:mm')
  274. this.orderId = checkinInfo.orderId
  275. this.checkinInfoId = checkinInfo.id
  276. let guest = {
  277. name: checkinInfo.name,
  278. phone: checkinInfo.phone
  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. // } else {
  286. // let roomInfoRes = await uni.$http.post('/roomInfo', {
  287. // hotelId: this.checkinInfo.hotelId,
  288. // room: this.checkinInfo.room,
  289. // pageNo: 1,
  290. // pageSize: 1
  291. // })
  292. // console.log('roominfo', roomInfoRes)
  293. // let roomTypeRes = await uni.$http.post('/roomType', {
  294. // roomType: roomInfoRes.data.data.records[0].roomType,
  295. // pageNo: 1,
  296. // pageSize: 1
  297. // })
  298. // let roomType = roomTypeRes.data.data.records[0]
  299. // this.roomTypePicPath = IMG_BASE_URL + '/' + roomType.roomPicPath
  300. // this.roomInfo = roomType.roomTypeName + this.checkinInfo.room
  301. // this.unitPrice = '¥' + roomType.unitPrice
  302. // }
  303. this.guestInfos.push(guest)
  304. let originEndTime = new Date(checkinInfo.endTime);
  305. this.newEndTime = new Date(originEndTime.valueOf() + 24 * 60 * 60 * 1000)
  306. this.oldEndTime = checkinInfo.endTime
  307. this.start.date = moment(checkinInfo.startTime).format('MM月DD日')
  308. this.start.day = getDay(new Date(checkinInfo.startTime).getDay())
  309. this.end.date = moment(checkinInfo.endTime).format('MM月DD日')
  310. this.end.day = getDay(new Date(checkinInfo.endTime).getDay())
  311. this.dayNumText = '共' + checkinInfo.dayNum + '晚'
  312. //设置日历
  313. let endDate = new Date(checkinInfo.endTime)
  314. endDate.setDate(endDate.getDate() + 1)
  315. this.minDate = moment(new Date(endDate)).format('YYYY-MM-DD')
  316. } else {
  317. this.checkinInfo = {}
  318. }
  319. } else {
  320. // #ifdef MP-WEIXIN
  321. uni.$showMsg('查询失败!')
  322. // #endif
  323. }
  324. },
  325. // #ifdef MP-ALIPAY
  326. async aliPaymentNormal(orderId) {
  327. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  328. openid: this.userInfo.openid,
  329. orderId: orderId,
  330. platform: 'ALIPAY',
  331. hotelId: this.currentHotel.hotelId
  332. })
  333. // console.log("获取预付号",alipayRes.data.data)
  334. let tradeNo = alipayRes.data.data.tradeNo
  335. let tradeRes = await my.tradePay({
  336. tradeNO: tradeNo
  337. })
  338. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  339. if (tradeRes.resultCode === "6002") {
  340. // 网络连接出错
  341. uni.showModal({
  342. title: "网络连接出错",
  343. content: "网络连接出错,请检查网络连接后重试。",
  344. });
  345. }
  346. // 顾客支付后,查询支付状态
  347. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  348. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  349. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  350. tradeNo: tradeNo,
  351. hotelId: this.currentHotel.hotelId
  352. })
  353. // console.log("tradeStatus", tradeStatus);
  354. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  355. uni.$showMsg("支付成功")
  356. this.extend()
  357. }
  358. }
  359. },
  360. async aliPaymentFreeze(orderId) {
  361. // 申请获取签名字符串
  362. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  363. orderId: orderId,
  364. hotelId: this.currentHotel.hotelId
  365. })
  366. // console.log("签名字符串", alipayRes.data)
  367. if (!alipayRes.data.success) {
  368. console.log("获取签名字符串");
  369. uni.showModal({
  370. title: "网络连接出错。",
  371. content: "网络连接出错,请检查网络连接后重试。",
  372. });
  373. return
  374. }
  375. // 根据签名字符串发起授权
  376. let orderString = alipayRes.data.data
  377. let tradeRes = await my.tradePay({
  378. orderStr: orderString
  379. })
  380. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  381. if (tradeRes.resultCode === "6002") {
  382. // 网络连接出错
  383. uni.showModal({
  384. title: "网络连接出错",
  385. content: "网络连接出错,请检查网络连接后重试。",
  386. });
  387. }
  388. // 顾客授权后,查询授权状态
  389. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  390. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  391. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  392. orderId: orderId,
  393. hotelId: this.currentHotel.hotelId
  394. })
  395. // console.log("tradeStatus", tradeStatus);
  396. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  397. uni.$showMsg("支付成功")
  398. this.extend()
  399. }
  400. }
  401. }
  402. // #endif
  403. },
  404. async onLoad(options) {
  405. await this.getCheckinInfo()
  406. if (Object.keys(this.checkinInfo).length <= 0) {
  407. return
  408. }
  409. this.fromExtend = options.fromExtend == 'true'
  410. if (this.fromExtend) {
  411. await this.queryCanExtend()
  412. }
  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. .end-time-tip {
  539. transform: translateY(-100rpx);
  540. }
  541. </style>