confirmOrder.vue 17 KB

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