confirmOrder.vue 17 KB

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