extend.vue 16 KB

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