extend.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. useYst: true
  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.useYst) {
  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. })
  251. res.data.data.package = res.data.data.packageStr
  252. let paymentResult = await wx.requestPayment(res.data.data)
  253. console.log("payment result:", paymentResult)
  254. if (paymentResult.errMsg === 'requestPayment:ok') {
  255. uni.$showMsg("支付成功")
  256. this.extend()
  257. }
  258. }
  259. // #endif
  260. // #ifdef MP-ALIPAY
  261. if (!this.needAuthPay) {
  262. await this.aliPaymentNormal(orderId)
  263. } else {
  264. await this.aliPaymentFreeze(orderId)
  265. }
  266. // #endif
  267. },
  268. async ystPayment(orderId) {
  269. const {miniProgram: {appId}} = uni.getAccountInfoSync();
  270. // console.log("小程序信息", appId);
  271. const {data: submitRes} = await uni.$http.post('/order/payment/ystPay', {
  272. openid: this.userInfo.openid,
  273. orderId: orderId,
  274. appId: appId
  275. })
  276. // console.log("订单提交结果", submitRes)
  277. const payData = JSON.parse(submitRes.data)
  278. // console.log("支付数据", payData);
  279. const paymentResult = await wx.requestPayment(payData)
  280. // console.log("payment result:", paymentResult)
  281. // 调用支付成功,查询下订单支付情况
  282. const {data: paymentRes} = await uni.$http.post('/order/payment/queryYstPay', {
  283. openid: this.userInfo.openid,
  284. orderId: orderId,
  285. appId: appId
  286. })
  287. console.log("订单支付结果", paymentRes)
  288. if (paymentRes.success && paymentRes.data === "S") {
  289. uni.$showMsg("支付成功")
  290. this.extend()
  291. }
  292. },
  293. async getCheckinInfo() {
  294. let res = await uni.$http.get(`/user/checkinInfo/${this.currentHotel.hotelId}`);
  295. if (res.data.code == 200) {
  296. let checkinInfo = res.data.data
  297. // console.log(checkinInfo)
  298. if (checkinInfo) {
  299. this.roomTypePicPath = IMG_BASE_URL + '/' + checkinInfo.roomPicPath
  300. this.roomInfo = checkinInfo.roomTypeName + checkinInfo.room
  301. this.unitPrice = checkinInfo.unitPrice
  302. this.breakfastNum = checkinInfo.breakfastNum
  303. this.endTime = moment(checkinInfo.endTime).format('M月DD日 HH:mm')
  304. this.orderId = checkinInfo.orderId
  305. this.checkinInfoId = checkinInfo.id
  306. let guest = {
  307. name: checkinInfo.name,
  308. phone: checkinInfo.phone
  309. }
  310. // if (order) {
  311. // this.order = order
  312. // this.roomTypePicPath = IMG_BASE_URL + '/' + order.roomPicPath
  313. // this.roomInfo = order.roomTypeName + order.room
  314. // this.unitPrice = '¥' + order.unitPrice
  315. // } else {
  316. // let roomInfoRes = await uni.$http.post('/roomInfo', {
  317. // hotelId: this.checkinInfo.hotelId,
  318. // room: this.checkinInfo.room,
  319. // pageNo: 1,
  320. // pageSize: 1
  321. // })
  322. // console.log('roominfo', roomInfoRes)
  323. // let roomTypeRes = await uni.$http.post('/roomType', {
  324. // roomType: roomInfoRes.data.data.records[0].roomType,
  325. // pageNo: 1,
  326. // pageSize: 1
  327. // })
  328. // let roomType = roomTypeRes.data.data.records[0]
  329. // this.roomTypePicPath = IMG_BASE_URL + '/' + roomType.roomPicPath
  330. // this.roomInfo = roomType.roomTypeName + this.checkinInfo.room
  331. // this.unitPrice = '¥' + roomType.unitPrice
  332. // }
  333. this.guestInfos.push(guest)
  334. let originEndTime = new Date(checkinInfo.endTime);
  335. this.newEndTime = new Date(originEndTime.valueOf() + 24 * 60 * 60 * 1000)
  336. this.oldEndTime = checkinInfo.endTime
  337. this.start.date = moment(checkinInfo.startTime).format('MM月DD日')
  338. this.start.day = getDay(new Date(checkinInfo.startTime).getDay())
  339. this.end.date = moment(checkinInfo.endTime).format('MM月DD日')
  340. this.end.day = getDay(new Date(checkinInfo.endTime).getDay())
  341. this.dayNumText = '共' + checkinInfo.dayNum + '晚'
  342. //设置日历
  343. let endDate = new Date(checkinInfo.endTime)
  344. endDate.setDate(endDate.getDate() + 1)
  345. this.minDate = moment(new Date(endDate)).format('YYYY-MM-DD')
  346. } else {
  347. this.checkinInfo = {}
  348. }
  349. } else {
  350. // #ifdef MP-WEIXIN
  351. uni.$showMsg('查询失败!')
  352. // #endif
  353. }
  354. },
  355. // #ifdef MP-ALIPAY
  356. async aliPaymentNormal(orderId) {
  357. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  358. openid: this.userInfo.openid,
  359. orderId: orderId,
  360. platform: 'ALIPAY',
  361. hotelId: this.currentHotel.hotelId
  362. })
  363. // console.log("获取预付号",alipayRes.data.data)
  364. let tradeNo = alipayRes.data.data.tradeNo
  365. let tradeRes = await my.tradePay({
  366. tradeNO: tradeNo
  367. })
  368. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  369. if (tradeRes.resultCode === "6002") {
  370. // 网络连接出错
  371. uni.showModal({
  372. title: "网络连接出错",
  373. content: "网络连接出错,请检查网络连接后重试。",
  374. });
  375. }
  376. // 顾客支付后,查询支付状态
  377. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  378. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  379. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  380. tradeNo: tradeNo,
  381. hotelId: this.currentHotel.hotelId
  382. })
  383. // console.log("tradeStatus", tradeStatus);
  384. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  385. uni.$showMsg("支付成功")
  386. this.extend()
  387. }
  388. }
  389. },
  390. async aliPaymentFreeze(orderId) {
  391. // 申请获取签名字符串
  392. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  393. orderId: orderId,
  394. hotelId: this.currentHotel.hotelId
  395. })
  396. // console.log("签名字符串", alipayRes.data)
  397. if (!alipayRes.data.success) {
  398. console.log("获取签名字符串");
  399. uni.showModal({
  400. title: "网络连接出错。",
  401. content: "网络连接出错,请检查网络连接后重试。",
  402. });
  403. return
  404. }
  405. // 根据签名字符串发起授权
  406. let orderString = alipayRes.data.data
  407. let tradeRes = await my.tradePay({
  408. orderStr: orderString
  409. })
  410. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  411. if (tradeRes.resultCode === "6002") {
  412. // 网络连接出错
  413. uni.showModal({
  414. title: "网络连接出错",
  415. content: "网络连接出错,请检查网络连接后重试。",
  416. });
  417. }
  418. // 顾客授权后,查询授权状态
  419. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  420. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  421. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  422. orderId: orderId,
  423. hotelId: this.currentHotel.hotelId
  424. })
  425. // console.log("tradeStatus", tradeStatus);
  426. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  427. uni.$showMsg("支付成功")
  428. this.extend()
  429. }
  430. }
  431. }
  432. // #endif
  433. },
  434. async onLoad(options) {
  435. await this.getCheckinInfo()
  436. if (!this.roomTypePicPath) {
  437. return
  438. }
  439. this.fromExtend = options.fromExtend == 'true'
  440. if (this.fromExtend) {
  441. await this.queryCanExtend()
  442. }
  443. },
  444. // #ifdef MP-WEIXIN
  445. onShareAppMessage(info) {
  446. return {
  447. title: '源享住',
  448. path: 'pages/login/login',
  449. imageUrl: "/static/logo.png"
  450. }
  451. }
  452. // #endif
  453. }
  454. </script>
  455. <style lang="scss">
  456. page {
  457. background-color: #FFFFFF;
  458. .top-background {
  459. background-color: #9e97c3;
  460. overflow: hidden;
  461. .room-type-item {
  462. border-radius: 30rpx;
  463. background-color: #FFFFFF;
  464. margin: 120rpx 20rpx;
  465. padding: 20rpx;
  466. display: flex;
  467. border-radius: 10rpx;
  468. .room-type-item-middle {
  469. margin-top: 40rpx;
  470. margin-left: 30rpx;
  471. display: flex;
  472. flex-direction: column;
  473. width: 280rpx;
  474. .room-type-item-middle-text {
  475. font-size: 40rpx;
  476. font-weight: bold;
  477. color: #333333;
  478. }
  479. .room-type-item-middle-bottom {
  480. margin-top: 40rpx;
  481. font-size: 25rpx;
  482. text {
  483. margin-right: 20rpx;
  484. color: #666666
  485. }
  486. }
  487. }
  488. .room-type-item-right {
  489. width: 25%;
  490. margin-right: 20rpx;
  491. .room-type-item-right-text {
  492. margin-left: 60rpx;
  493. margin-top: 70rpx;
  494. }
  495. text {
  496. font-size: 40rpx;
  497. font-weight: bold;
  498. color: #FF5C58
  499. }
  500. }
  501. }
  502. }
  503. }
  504. .checkin-date-info {
  505. transform: translateY(-100rpx);
  506. border-radius: 30rpx;
  507. background-color: #FFFFFF;
  508. margin: 20rpx;
  509. padding: 20rpx;
  510. display: flex;
  511. background: #FFFFFF;
  512. border-radius: 10rpx;
  513. box-shadow: 0rpx 8rpx 11rpx 2rpx rgba(79, 121, 225, 0.19);
  514. .date-selector {
  515. margin: 20rpx;
  516. display: flex;
  517. width: 70vw;
  518. .date-item {
  519. width: 35vw;
  520. .date-info {
  521. display: flex;
  522. }
  523. }
  524. }
  525. .day-num {
  526. display: flex;
  527. flex-direction: column;
  528. align-items: center;
  529. justify-content: space-around;
  530. }
  531. }
  532. .u-form {
  533. transform: translateY(-100rpx);
  534. background-color: #FFFFFF;
  535. .u-form-item {
  536. line-height: 70rpx;
  537. .u-form-item__body {
  538. margin-left: 32rpx;
  539. margin-right: 32rpx;
  540. border-bottom: 2rpx solid #E5E5E5;
  541. }
  542. .u-form-item__body__left__content__label {
  543. font-size: 36rpx;
  544. color: #666666;
  545. }
  546. }
  547. }
  548. .btn-area {
  549. transform: translateY(-60rpx);
  550. display: flex;
  551. justify-content: space-evenly;
  552. .btn {
  553. color: #9e97c3;
  554. border: 1rpx solid #9e97c3;
  555. background-color: #FFFFFF;
  556. font-weight: bold;
  557. font-size: 33rpx;
  558. width: 250rpx;
  559. }
  560. .btn-hover {
  561. color: #FFFFFF;
  562. background-color: #9e97c3;
  563. }
  564. }
  565. .not-reservation {
  566. margin-top: 40%;
  567. }
  568. .end-time-tip {
  569. transform: translateY(-100rpx);
  570. }
  571. </style>