confirmOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <view>
  3. <view class="top">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar :title="title" control="home" bgcolor="#a09cc4"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar :title="title" bgcolor="#a09cc4"></NavigateBar>
  9. <!-- #endif -->
  10. </view>
  11. <view class="room-type-item">
  12. <view class="room-type-item-left">
  13. <u-image :src="roomPicPath" width="200rpx" height="200rpx" radius="10"></u-image>
  14. </view>
  15. <view class="room-type-item-middle">
  16. <view class="room-type-item-middle-text">
  17. <text>{{roomTypeName ? roomTypeName : ""}}</text>
  18. </view>
  19. <view class="room-type-item-middle-text">
  20. <text>{{order.room ? order.room : ""}}</text>
  21. </view>
  22. </view>
  23. <view class="room-type-item-right">
  24. <view class="room-type-item-right-text">
  25. <text>¥{{unitPrice ? unitPrice : 0}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="checkin-date-info">
  30. <view class="date-selector">
  31. <view class="date-item">
  32. <u-text text="入住" color="#666666" size="15"></u-text>
  33. <view class="date-info">
  34. <u-text :text="startDate" color="#333333" size="14" bold></u-text>
  35. <u-text :text="startDay" color="#333333" size="14" bold></u-text>
  36. </view>
  37. </view>
  38. <view class="date-item">
  39. <u-text text="离店" color="#666666" size="15"></u-text>
  40. <view class="date-info">
  41. <u-text :text="endDate" color="#333333" size="14" bold></u-text>
  42. <u-text :text="endDay" color="#333333" size="14" bold></u-text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="day-num">
  47. <u-text :text="'共' + order.dayNum + '晚'" color="#333333" size="15" bold></u-text>
  48. </view>
  49. </view>
  50. <!-- #ifdef MP-WEIXIN -->
  51. <u-swipe-action>
  52. <u-swipe-action-item :options="options" v-for="(info,index) in checkinInfo" @click="deleteGuest"
  53. :name="index" :disabled="index ===0">
  54. <u-form labelPosition="left" labelWidth="180rpx" labelAlign="center">
  55. <u-form-item label="姓名" prop="name">
  56. <u-text :text="info.name" border="none" clearable fontSize="36rpx"></u-text>
  57. </u-form-item>
  58. <u-form-item label="身份证" prop="idNumber">
  59. <u-text :text="info.idNumber" border="none" clearable fontSize="36rpx"></u-text>
  60. </u-form-item>
  61. </u-form>
  62. </u-swipe-action-item>
  63. </u-swipe-action>
  64. <!-- #endif -->
  65. <!-- #ifdef MP-ALIPAY -->
  66. <view v-for="(info,index) in checkinInfo" :key="index" class="guest-info">
  67. <ant-swipe-action :rightButtons="rightBtns" @swipeStart="onSwipeStart" @swipeEnd="onSwipeEnd"
  68. @buttonTap="deleteGuestAli" :swiped="swipeIndex === index" :data-item="index" :disabled="index ===0">
  69. <view class="swipe-item">
  70. <u-form labelPosition="left" labelWidth="180rpx" labelAlign="center">
  71. <u-form-item label="姓名" prop="name">
  72. <u-text :text="info.name" border="none" clearable fontSize="36rpx"></u-text>
  73. </u-form-item>
  74. <u-form-item label="身份证" prop="idNumber">
  75. <u-text :text="info.idNumber" border="none" clearable fontSize="36rpx"></u-text>
  76. </u-form-item>
  77. </u-form>
  78. </view>
  79. </ant-swipe-action>
  80. </view>
  81. <!-- #endif -->
  82. <view class="add-guest-btn-container">
  83. <u-button text="添加同住人" @click="gotoAddGuest"></u-button>
  84. </view>
  85. <view class="paymentArea" v-if="confirmDone">
  86. <view class="paymentArea--left">
  87. <view class="price">
  88. <text>合计:</text>
  89. <text>¥{{order.price ? order.price : ""}}</text>
  90. </view>
  91. <view class="deposit">
  92. <text text="" align="right" size="20">(注:需付押金{{order.deposit ? order.deposit : ""}}元)</text>
  93. </view>
  94. </view>
  95. <view class="completeBtn">
  96. <button class="u-button" @click="pay">支付</button>
  97. </view>
  98. </view>
  99. <view class="confirm-btn-container" v-else>
  100. <u-button text="确认" color="#9e97c3" @click="confirmOrder"></u-button>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. import {
  106. getDay
  107. } from '../../utils/commonUtils.js'
  108. import {
  109. IMG_BASE_URL
  110. } from "../../config.js"
  111. import {
  112. mapState,
  113. mapMutations
  114. } from 'vuex'
  115. import moment from "moment";
  116. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  117. export default {
  118. components: {
  119. NavigateBar
  120. },
  121. data() {
  122. return {
  123. roomPicPath: '',
  124. roomTypeName: '',
  125. unitPrice: '',
  126. startDate: this.startDate,
  127. startDay: this.startDay,
  128. endDate: this.endDate,
  129. endDay: this.endDay,
  130. arrowPicPath: '/static/arrow.png',
  131. confirmDone: false,
  132. options: [{
  133. text: '删除',
  134. style: {
  135. backgroundColor: '#FF0000'
  136. }
  137. }],
  138. title: "",
  139. // #ifdef MP-ALIPAY
  140. rightBtns: [{
  141. text: "删除",
  142. bgColor: "#FF0000",
  143. color: '#fff',
  144. }],
  145. swipeIndex: -1,
  146. // #endif
  147. };
  148. },
  149. computed: {
  150. ...mapState('m_user', ['userInfo']),
  151. ...mapState('m_business', ['order', 'currentHotel', 'checkinInfo']),
  152. },
  153. methods: {
  154. ...mapMutations('m_business', ['updateCheckinInfo', 'updateOrder']),
  155. gotoAddGuest() {
  156. uni.navigateTo({
  157. url: '/subpkg_checkin/addGuest/addGuest'
  158. })
  159. },
  160. // #ifdef MP-WEIXIN
  161. deleteGuest(info) {
  162. if (info.name === 0) {
  163. return
  164. }
  165. this.checkinInfo.splice(info.name, 1)
  166. this.updateCheckinInfo(this.checkinInfo)
  167. },
  168. // #endif
  169. async confirmOrder() {
  170. //小程序创建的订单,先在后台创建订单,创建成功后跳转至支付页面
  171. if (this.order.orderSource === 'MINI_APP') {
  172. if (!this.order.orderId) {
  173. let createOrderRes = await uni.$http.post('/hotelOrder', this.order)
  174. if (createOrderRes.data.code !== 200) {
  175. uni.$showMsg('订单创建失败,请重试')
  176. return
  177. }
  178. this.updateOrder(createOrderRes.data.data)
  179. }
  180. this.confirmDone = true
  181. this.title = '订单支付'
  182. } else {
  183. //pms预定订单,若未支付跳转至支付页面,若已支付跳转至入住页面
  184. if (this.order.paymentStatus !== 'PAID') {
  185. this.confirmDone = true
  186. this.title = '订单支付'
  187. } else {
  188. uni.navigateTo({
  189. url: '/subpkg_checkin/checkin/checkin'
  190. })
  191. }
  192. }
  193. },
  194. async pay() {
  195. console.log("pay start");
  196. // #ifdef MP-WEIXIN
  197. let res = await uni.$http.post('/hotelOrder/payment', {
  198. openid: this.userInfo.openid,
  199. orderId: this.order.orderId,
  200. platform: 'WECHAT',
  201. hotelId: this.currentHotel.hotelId
  202. })
  203. if (res.data.code == 200) {
  204. res.data.data.package = res.data.data.packageStr
  205. try {
  206. let paymentResult = await wx.requestPayment(res.data.data)
  207. console.log("payment result:", paymentResult)
  208. if (paymentResult.errMsg === 'requestPayment:ok') {
  209. uni.$showMsg("支付成功")
  210. uni.redirectTo({
  211. url: '/subpkg_checkin/checkin/checkin'
  212. })
  213. }
  214. } catch {
  215. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  216. }
  217. } else {
  218. uni.showModal({
  219. content: '房间已被占用,请重新选房',
  220. showCancel: false,
  221. success: (res) => {
  222. if (res.confirm) {
  223. uni.navigateTo({
  224. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  225. this.order.roomType
  226. })
  227. }
  228. }
  229. })
  230. }
  231. // #endif
  232. // #ifdef MP-ALIPAY
  233. if (Number(this.order.deposit) === 0) {
  234. await this.aliPaymentNormal()
  235. } else {
  236. await this.aliPaymentFreeze()
  237. }
  238. // #endif
  239. },
  240. // #ifdef MP-ALIPAY
  241. onSwipeStart() {
  242. this.swipeIndex = ""
  243. },
  244. onSwipeEnd(arg1, arg2) {
  245. console.log(arg1, arg2);
  246. let index = arg2.target.dataset.item
  247. if (arg1.swiped) {
  248. this.swipeIndex = index
  249. }
  250. },
  251. deleteGuestAli() {
  252. this.checkinInfo.splice(this.swipeIndex, 1)
  253. this.updateCheckinInfo(this.checkinInfo)
  254. },
  255. async aliPaymentNormal() {
  256. // 申请获取预付号
  257. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  258. openid: this.userInfo.openid,
  259. orderId: this.order.orderId,
  260. platform: 'ALIPAY',
  261. hotelId: this.currentHotel.hotelId
  262. })
  263. // console.log("获取预付号",alipayRes.data)
  264. if (!alipayRes.data.success) {
  265. console.log("获取预付号失败");
  266. uni.showModal({
  267. title: "网络连接出错。",
  268. content: "网络连接出错,请检查网络连接后重试。",
  269. });
  270. return
  271. }
  272. // 根据预付号发起支付
  273. let tradeNo = alipayRes.data.data.tradeNo
  274. let tradeRes = await my.tradePay({
  275. tradeNO: tradeNo
  276. })
  277. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  278. if (tradeRes.resultCode === "6002") {
  279. // 网络连接出错
  280. uni.showModal({
  281. title: "网络连接出错",
  282. content: "网络连接出错,请检查网络连接后重试。",
  283. });
  284. }
  285. // 顾客支付后,查询支付状态
  286. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  287. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  288. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  289. tradeNo: tradeNo,
  290. hotelId: this.currentHotel.hotelId
  291. })
  292. // console.log("tradeStatus", tradeStatus);
  293. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  294. uni.$showMsg("支付成功")
  295. uni.navigateTo({
  296. url: '/subpkg_checkin/checkin/checkin'
  297. })
  298. }
  299. }
  300. },
  301. async aliPaymentFreeze() {
  302. // 申请获取签名字符串
  303. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  304. orderId: this.order.orderId,
  305. hotelId: this.currentHotel.hotelId
  306. })
  307. console.log("签名字符串", alipayRes.data)
  308. if (!alipayRes.data.success) {
  309. console.log("获取签名字符串");
  310. uni.showModal({
  311. title: "网络连接出错。",
  312. content: "网络连接出错,请检查网络连接后重试。",
  313. });
  314. return
  315. }
  316. // 根据签名字符串发起授权
  317. let orderString = alipayRes.data.data
  318. let tradeRes = await my.tradePay({
  319. orderStr: orderString
  320. })
  321. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  322. if (tradeRes.resultCode === "6002") {
  323. // 网络连接出错
  324. uni.showModal({
  325. title: "网络连接出错",
  326. content: "网络连接出错,请检查网络连接后重试。",
  327. });
  328. }
  329. // 顾客授权后,查询授权状态
  330. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  331. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  332. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  333. orderId: this.order.orderId,
  334. hotelId: this.currentHotel.hotelId
  335. })
  336. // console.log("tradeStatus", tradeStatus);
  337. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  338. uni.$showMsg("支付成功")
  339. uni.navigateTo({
  340. url: '/subpkg_checkin/checkin/checkin'
  341. })
  342. }
  343. }
  344. }
  345. // #endif
  346. },
  347. async onLoad() {
  348. let res = await uni.$http.post('/roomType', {
  349. roomType: this.order.roomType,
  350. hotelId: this.currentHotel.hotelId,
  351. pageNo: 1,
  352. pageSize: 999
  353. })
  354. this.roomPicPath = IMG_BASE_URL + '/' + res.data.data.records[0].roomPicPath
  355. this.roomTypeName = res.data.data.records[0].roomTypeName
  356. this.unitPrice = res.data.data.records[0].unitPrice
  357. this.startDate = moment(new Date(this.order.startTime)).format('MM月DD日')
  358. this.startDay = getDay(new Date(this.order.startTime).getDay())
  359. this.endDate = moment(new Date(this.order.endTime)).format('MM月DD日')
  360. this.endDay = getDay(new Date(this.order.endTime).getDay())
  361. },
  362. // #ifdef MP-WEIXIN
  363. onShareAppMessage(info) {
  364. return {
  365. title: '源享住',
  366. path: 'pages/login/login',
  367. imageUrl: "/static/logo.png"
  368. }
  369. }
  370. // #endif
  371. }
  372. </script>
  373. <style lang="scss">
  374. page {
  375. background-color: #EFEFF4;
  376. }
  377. .room-type-item {
  378. border-radius: 30rpx;
  379. background-color: #FFFFFF;
  380. margin: 20rpx;
  381. padding: 40rpx 20rpx;
  382. display: flex;
  383. background: #FFFFFF;
  384. border-radius: 10rpx;
  385. .room-type-item-middle {
  386. margin-left: 30rpx;
  387. display: flex;
  388. flex-direction: column;
  389. width: 200rpx;
  390. .room-type-item-middle-text {
  391. font-size: 40rpx;
  392. font-weight: bold;
  393. color: #333333;
  394. }
  395. .room-type-item-middle-bottom {
  396. margin-top: 40rpx;
  397. font-size: 25rpx;
  398. text {
  399. margin-right: 20rpx;
  400. color: #666666
  401. }
  402. }
  403. }
  404. .room-type-item-right {
  405. width: 25%;
  406. margin-left: 20rpx;
  407. .room-type-item-right-text {
  408. margin-left: 60rpx;
  409. margin-top: 40rpx;
  410. }
  411. text {
  412. font-size: 40rpx;
  413. font-weight: bold;
  414. color: #FF5C58
  415. }
  416. }
  417. }
  418. .checkin-date-info {
  419. border-radius: 30rpx;
  420. background-color: #FFFFFF;
  421. margin: 20rpx 20rpx;
  422. padding: 20rpx;
  423. display: flex;
  424. background: #FFFFFF;
  425. border-radius: 10rpx;
  426. .date-selector {
  427. margin: 20rpx;
  428. display: flex;
  429. width: 70vw;
  430. .date-item {
  431. width: 35vw;
  432. .date-info {
  433. display: flex;
  434. }
  435. }
  436. }
  437. .day-num {
  438. display: flex;
  439. align-items: center;
  440. justify-content: space-between;
  441. }
  442. }
  443. .guest-info {
  444. display: flex;
  445. flex-direction: column;
  446. align-items: center;
  447. height: 220rpx;
  448. width: 100%;
  449. margin-top: 40rpx;
  450. .swipe-item {
  451. background-color: #ffffff;
  452. text-indent: 1em;
  453. position: relative;
  454. height: 100%;
  455. color: #333333;
  456. }
  457. .swipe-item::after {
  458. content: "";
  459. position: absolute;
  460. bottom: 0;
  461. left: 0;
  462. width: 100%;
  463. height: 1px;
  464. max-height: 1px;
  465. min-height: 1px;
  466. transform: scaleY(0.5);
  467. background-color: #eeeeee;
  468. }
  469. .u-form {
  470. background-color: #FFFFFF;
  471. .u-form-item {
  472. line-height: 70rpx;
  473. .u-form-item__body {
  474. margin-left: 32rpx;
  475. border-bottom: 2rpx solid #E5E5E5;
  476. }
  477. .u-form-item__body__left__content__label {
  478. font-size: 36rpx;
  479. color: #666666;
  480. }
  481. }
  482. }
  483. }
  484. .u-swipe-action {
  485. .u-swipe-action-item {
  486. margin-top: 40rpx;
  487. .u-form {
  488. background-color: #FFFFFF;
  489. .u-form-item {
  490. line-height: 70rpx;
  491. .u-form-item__body {
  492. margin-left: 32rpx;
  493. border-bottom: 2rpx solid #E5E5E5;
  494. }
  495. .u-form-item__body__left__content__label {
  496. font-size: 36rpx;
  497. color: #666666;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. .add-guest-btn-container {
  504. margin: 30rpx;
  505. padding-bottom: 160rpx;
  506. }
  507. .confirm-btn-container {
  508. margin: 30rpx;
  509. padding-bottom: 100rpx;
  510. transform: translateY(-160rpx);
  511. .u-button__text {
  512. font-size: 30rpx !important;
  513. }
  514. }
  515. .paymentArea {
  516. position: fixed;
  517. bottom: 30rpx;
  518. height: 110rpx;
  519. display: flex;
  520. background-color: #EFEFF4;
  521. z-index: 99;
  522. .completeBtn {
  523. width: 50vw;
  524. .u-button {
  525. height: 110rpx;
  526. color: #ffffff;
  527. background-color: #F78203;
  528. display: flex;
  529. align-items: center;
  530. justify-content: center;
  531. font-size: 35rpx !important;
  532. }
  533. }
  534. .paymentArea--left {
  535. .price {
  536. display: block;
  537. margin-left: 20rpx;
  538. width: 50vw;
  539. line-height: 60rpx;
  540. font-size: 36rpx;
  541. font-weight: bold;
  542. text {
  543. &:nth-child(2) {
  544. color: #FF5C58;
  545. }
  546. }
  547. }
  548. .deposit {
  549. display: block;
  550. margin-left: 20rpx;
  551. width: 50vw;
  552. line-height: 40rpx;
  553. font-size: 24rpx;
  554. color: #666666;
  555. }
  556. }
  557. .deposit {
  558. display: block;
  559. }
  560. }
  561. </style>