extend.vue 17 KB

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