extend.vue 15 KB

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