confirmOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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" :key=index @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('/order', 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('/order/payment/weChat', {
  198. openid: this.userInfo.openid,
  199. orderId: this.order.orderId,
  200. })
  201. if (res.data.code == 200) {
  202. res.data.data.package = res.data.data.packageStr
  203. try {
  204. let paymentResult = await wx.requestPayment(res.data.data)
  205. console.log("payment result:", paymentResult)
  206. if (paymentResult.errMsg === 'requestPayment:ok') {
  207. uni.$showMsg("支付成功")
  208. uni.redirectTo({
  209. url: '/subpkg_checkin/checkin/checkin'
  210. })
  211. }
  212. } catch {
  213. uni.$http.post(`/order/cancelPayment/${this.order.id}`)
  214. }
  215. } else {
  216. //小程序创建的订单跳转至选择房间,pms预订单跳转至查询订单
  217. if (this.order.orderSource === 'MINI_APP') {
  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. } else {
  231. uni.showModal({
  232. content: '订单不可用,请重新选择订单',
  233. showCancel: false,
  234. success: (res) => {
  235. if (res.confirm) {
  236. uni.navigateTo({
  237. url: '/subpkg_checkin/queryOrder/queryOrder?'
  238. })
  239. }
  240. }
  241. })
  242. }
  243. }
  244. // #endif
  245. // #ifdef MP-ALIPAY
  246. if (Number(this.order.deposit) === 0) {
  247. await this.aliPaymentNormal()
  248. } else {
  249. await this.aliPaymentFreeze()
  250. }
  251. // #endif
  252. },
  253. // #ifdef MP-ALIPAY
  254. onSwipeStart() {
  255. this.swipeIndex = ""
  256. },
  257. onSwipeEnd(arg1, arg2) {
  258. console.log(arg1, arg2);
  259. let index = arg2.target.dataset.item
  260. if (arg1.swiped) {
  261. this.swipeIndex = index
  262. }
  263. },
  264. deleteGuestAli() {
  265. this.checkinInfo.splice(this.swipeIndex, 1)
  266. this.updateCheckinInfo(this.checkinInfo)
  267. },
  268. async aliPaymentNormal() {
  269. // 申请获取预付号
  270. let alipayRes = await uni.$http.post('/hotelOrder/alipayPrepay', {
  271. openid: this.userInfo.openid,
  272. orderId: this.order.orderId
  273. })
  274. // console.log("获取预付号",alipayRes.data)
  275. if (!alipayRes.data.success) {
  276. console.log("获取预付号失败");
  277. //小程序创建的订单跳转至选择房间,pms预订单跳转至查询订单
  278. if (this.order.orderSource === 'MINI_APP') {
  279. uni.showModal({
  280. content: '房间已被占用,请重新选房',
  281. showCancel: false,
  282. success: (res) => {
  283. if (res.confirm) {
  284. uni.navigateTo({
  285. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  286. this.order.roomType
  287. })
  288. }
  289. }
  290. })
  291. } else {
  292. uni.showModal({
  293. content: '订单不可用,请重新选择订单',
  294. showCancel: false,
  295. success: (res) => {
  296. if (res.confirm) {
  297. uni.navigateTo({
  298. url: '/subpkg_checkin/queryOrder/queryOrder?'
  299. })
  300. }
  301. }
  302. })
  303. }
  304. return
  305. }
  306. // 根据预付号发起支付
  307. let tradeNo = alipayRes.data.data.tradeNo
  308. let tradeRes = await my.tradePay({
  309. tradeNO: tradeNo
  310. })
  311. // console.log("tradeRes 交易支付结果",tradeRes.resultCode);
  312. if (tradeRes.resultCode === "6001") {
  313. console.log("支付未完成。");
  314. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  315. }
  316. if (tradeRes.resultCode === "6002") {
  317. // 网络连接出错
  318. uni.showModal({
  319. title: "网络连接出错",
  320. content: "网络连接出错,请检查网络连接后重试。",
  321. });
  322. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  323. }
  324. // 顾客支付后,查询支付状态
  325. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  326. // 顾客支付订单后,查询支付宝侧的订单支付状态,只有TRADE_SUCCESS才为支付成功
  327. let tradeStatus = await uni.$http.post('/hotelOrder/queryAlipayTradeStatus', {
  328. tradeNo: tradeNo,
  329. hotelId: this.currentHotel.hotelId
  330. })
  331. // console.log("tradeStatus", tradeStatus);
  332. if (tradeStatus.data.success && tradeStatus.data.data.tradeStatus === "TRADE_SUCCESS") {
  333. uni.$showMsg("支付成功")
  334. uni.navigateTo({
  335. url: '/subpkg_checkin/checkin/checkin'
  336. })
  337. } else {
  338. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  339. }
  340. }
  341. },
  342. async aliPaymentFreeze() {
  343. // 申请获取签名字符串
  344. let alipayRes = await uni.$http.post('/hotelOrder/alipayFreezeFund', {
  345. orderId: this.order.orderId,
  346. hotelId: this.currentHotel.hotelId
  347. })
  348. console.log("签名字符串", alipayRes.data)
  349. if (!alipayRes.data.success) {
  350. console.log("获取签名字符串失败");
  351. //小程序创建的订单跳转至选择房间,pms预订单跳转至查询订单
  352. if (this.order.orderSource === 'MINI_APP') {
  353. uni.showModal({
  354. content: '房间已被占用,请重新选房',
  355. showCancel: false,
  356. success: (res) => {
  357. if (res.confirm) {
  358. uni.navigateTo({
  359. url: '/subpkg_checkin/selectRoom/selectRoom?roomType=' +
  360. this.order.roomType
  361. })
  362. }
  363. }
  364. })
  365. } else {
  366. uni.showModal({
  367. content: '订单不可用,请重新选择订单',
  368. showCancel: false,
  369. success: (res) => {
  370. if (res.confirm) {
  371. uni.navigateTo({
  372. url: '/subpkg_checkin/queryOrder/queryOrder?'
  373. })
  374. }
  375. }
  376. })
  377. }
  378. return
  379. }
  380. // 根据签名字符串发起授权
  381. let orderString = alipayRes.data.data
  382. let tradeRes = await my.tradePay({
  383. orderStr: orderString
  384. })
  385. // console.log("tradeRes 授权结果",tradeRes.resultCode);
  386. if (tradeRes.resultCode === "6001") {
  387. console.log("支付未完成。");
  388. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  389. }
  390. if (tradeRes.resultCode === "6002") {
  391. // 网络连接出错
  392. uni.showModal({
  393. title: "网络连接出错",
  394. content: "网络连接出错,请检查网络连接后重试。",
  395. });
  396. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  397. }
  398. // 顾客授权后,查询授权状态
  399. if (["9000", "6004", "8000"].includes(tradeRes.resultCode)) {
  400. // 顾客授权后,查询授权状态,只有AUTHORIZED(已授权状态:授权成功,可以进行转支付或解冻操作)才算成功
  401. let tradeStatus = await uni.$http.post('/hotelOrder/queryFreezeStatus', {
  402. orderId: this.order.orderId,
  403. hotelId: this.currentHotel.hotelId
  404. })
  405. // console.log("tradeStatus", tradeStatus);
  406. if (tradeStatus.data.success && tradeStatus.data.data === "AUTHORIZED") {
  407. uni.$showMsg("支付成功")
  408. uni.navigateTo({
  409. url: '/subpkg_checkin/checkin/checkin'
  410. })
  411. } else {
  412. uni.$http.post(`/hotelOrder/cancelPayment/${this.order.id}`)
  413. }
  414. }
  415. }
  416. // #endif
  417. },
  418. async onLoad() {
  419. let res = await uni.$http.post(`/hotel/roomType`, {
  420. hotelId: this.currentHotel.hotelId,
  421. roomType: this.order.roomType
  422. })
  423. this.roomPicPath = IMG_BASE_URL + '/' + res.data.data.roomPicPath
  424. this.roomTypeName = res.data.data.roomTypeName
  425. this.unitPrice = res.data.data.unitPrice
  426. this.startDate = moment(new Date(this.order.startTime)).format('MM月DD日')
  427. this.startDay = getDay(new Date(this.order.startTime).getDay())
  428. this.endDate = moment(new Date(this.order.endTime)).format('MM月DD日')
  429. this.endDay = getDay(new Date(this.order.endTime).getDay())
  430. },
  431. // #ifdef MP-WEIXIN
  432. onShareAppMessage(info) {
  433. return {
  434. title: '源享住',
  435. path: 'pages/login/login',
  436. imageUrl: "/static/logo.png"
  437. }
  438. }
  439. // #endif
  440. }
  441. </script>
  442. <style lang="scss">
  443. page {
  444. background-color: #EFEFF4;
  445. }
  446. .room-type-item {
  447. border-radius: 30rpx;
  448. background-color: #FFFFFF;
  449. margin: 20rpx;
  450. padding: 40rpx 20rpx;
  451. display: flex;
  452. background: #FFFFFF;
  453. border-radius: 10rpx;
  454. .room-type-item-middle {
  455. margin-left: 30rpx;
  456. display: flex;
  457. flex-direction: column;
  458. width: 200rpx;
  459. .room-type-item-middle-text {
  460. font-size: 40rpx;
  461. font-weight: bold;
  462. color: #333333;
  463. }
  464. .room-type-item-middle-bottom {
  465. margin-top: 40rpx;
  466. font-size: 25rpx;
  467. text {
  468. margin-right: 20rpx;
  469. color: #666666
  470. }
  471. }
  472. }
  473. .room-type-item-right {
  474. width: 25%;
  475. margin-left: 20rpx;
  476. .room-type-item-right-text {
  477. margin-left: 60rpx;
  478. margin-top: 40rpx;
  479. }
  480. text {
  481. font-size: 40rpx;
  482. font-weight: bold;
  483. color: #FF5C58
  484. }
  485. }
  486. }
  487. .checkin-date-info {
  488. border-radius: 30rpx;
  489. background-color: #FFFFFF;
  490. margin: 20rpx 20rpx;
  491. padding: 20rpx;
  492. display: flex;
  493. background: #FFFFFF;
  494. border-radius: 10rpx;
  495. .date-selector {
  496. margin: 20rpx;
  497. display: flex;
  498. width: 70vw;
  499. .date-item {
  500. width: 35vw;
  501. .date-info {
  502. display: flex;
  503. }
  504. }
  505. }
  506. .day-num {
  507. display: flex;
  508. align-items: center;
  509. justify-content: space-between;
  510. }
  511. }
  512. .guest-info {
  513. display: flex;
  514. flex-direction: column;
  515. align-items: center;
  516. height: 220rpx;
  517. width: 100%;
  518. margin-top: 40rpx;
  519. .swipe-item {
  520. background-color: #ffffff;
  521. text-indent: 1em;
  522. position: relative;
  523. height: 100%;
  524. color: #333333;
  525. }
  526. .swipe-item::after {
  527. content: "";
  528. position: absolute;
  529. bottom: 0;
  530. left: 0;
  531. width: 100%;
  532. height: 1px;
  533. max-height: 1px;
  534. min-height: 1px;
  535. transform: scaleY(0.5);
  536. background-color: #eeeeee;
  537. }
  538. .u-form {
  539. background-color: #FFFFFF;
  540. .u-form-item {
  541. line-height: 70rpx;
  542. .u-form-item__body {
  543. margin-left: 32rpx;
  544. border-bottom: 2rpx solid #E5E5E5;
  545. }
  546. .u-form-item__body__left__content__label {
  547. font-size: 36rpx;
  548. color: #666666;
  549. }
  550. }
  551. }
  552. }
  553. .u-swipe-action {
  554. .u-swipe-action-item {
  555. margin-top: 40rpx;
  556. .u-form {
  557. background-color: #FFFFFF;
  558. .u-form-item {
  559. line-height: 70rpx;
  560. .u-form-item__body {
  561. margin-left: 32rpx;
  562. border-bottom: 2rpx solid #E5E5E5;
  563. }
  564. .u-form-item__body__left__content__label {
  565. font-size: 36rpx;
  566. color: #666666;
  567. }
  568. }
  569. }
  570. }
  571. }
  572. .add-guest-btn-container {
  573. margin: 30rpx;
  574. padding-bottom: 160rpx;
  575. }
  576. .confirm-btn-container {
  577. margin: 30rpx;
  578. padding-bottom: 100rpx;
  579. transform: translateY(-160rpx);
  580. .u-button__text {
  581. font-size: 30rpx !important;
  582. }
  583. }
  584. .paymentArea {
  585. position: fixed;
  586. bottom: 30rpx;
  587. height: 110rpx;
  588. display: flex;
  589. background-color: #EFEFF4;
  590. z-index: 99;
  591. .completeBtn {
  592. width: 50vw;
  593. .u-button {
  594. height: 110rpx;
  595. color: #ffffff;
  596. background-color: #F78203;
  597. display: flex;
  598. align-items: center;
  599. justify-content: center;
  600. font-size: 35rpx !important;
  601. }
  602. }
  603. .paymentArea--left {
  604. .price {
  605. display: block;
  606. margin-left: 20rpx;
  607. width: 50vw;
  608. line-height: 60rpx;
  609. font-size: 36rpx;
  610. font-weight: bold;
  611. text {
  612. &:nth-child(2) {
  613. color: #FF5C58;
  614. }
  615. }
  616. }
  617. .deposit {
  618. display: block;
  619. margin-left: 20rpx;
  620. width: 50vw;
  621. line-height: 40rpx;
  622. font-size: 24rpx;
  623. color: #666666;
  624. }
  625. }
  626. .deposit {
  627. display: block;
  628. }
  629. }
  630. </style>