makeOut.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template>
  2. <view class="hotel-makeOut">
  3. <view class="content">
  4. <view class="info-box">
  5. <zs-img class="img" :src="form.roomPic" width="200rpx" height="200rpx" radius="full"></zs-img>
  6. <view class="info">
  7. <view class="title">
  8. {{form.roomNameCn}}
  9. </view>
  10. <view class="desc-box">
  11. <view class="text" v-if="info.area">
  12. {{info.area}}
  13. </view>
  14. <view class="text" v-if="info.window">
  15. {{info.window |filterWindow}}
  16. </view>
  17. </view>
  18. <view class="notice">
  19. {{info.meal}} {{info.cancel}}
  20. </view>
  21. </view>
  22. </view>
  23. <view class="bottom-box">
  24. <view class="time-box">
  25. <view class="item">
  26. <view class="label">
  27. 入住
  28. </view>
  29. <view class="time">
  30. {{form.checkin | filterDate('time')}}
  31. </view>
  32. </view>
  33. <view class="item">
  34. <view class="label">
  35. 离店
  36. </view>
  37. <view class="time">
  38. {{form.checkout | filterDate('time')}}
  39. </view>
  40. </view>
  41. </view>
  42. <view class="day">
  43. {{day}}晚
  44. </view>
  45. </view>
  46. </view>
  47. <view class="content room-box">
  48. <view class="sub-title">
  49. 房间数
  50. </view>
  51. <view class="desc">
  52. {{form.numberofRooms}}间房 每间房2 成人 0儿童
  53. </view>
  54. <view class="tab-box">
  55. <view class="tab" :class="[d+1 == form.numberofRooms?'active':'',d%4?'ml20':'']" v-for="(i,d) in 8" :key="d" @click="choose(d)">
  56. {{i+1}}间
  57. </view>
  58. </view>
  59. </view>
  60. <view class="content add-box">
  61. <view class="sub-title">
  62. 入住信息
  63. </view>
  64. <u--form
  65. labelPosition="left"
  66. :model="form"
  67. ref="uForm"
  68. labelWidth="150rpx"
  69. >
  70. <view v-for="(item,index) in form.customerInfo" :key="index">
  71. <view class="title-box">
  72. <view class="title">
  73. 房间{{index+1}}
  74. </view>
  75. </view>
  76. <u-form-item
  77. label="姓名"
  78. :prop="`customerInfo.${index}.value`"
  79. :ref="'customerInfo.'+index+'.value'"
  80. borderBottom
  81. required
  82. >
  83. <u--input
  84. v-model="item.value"
  85. border="none"
  86. placeholder="请填写实际入住人姓名"
  87. ></u--input>
  88. </u-form-item>
  89. </view>
  90. <u-form-item
  91. label="联系手机"
  92. prop="contactPhone"
  93. borderBottom
  94. ref="item1"
  95. required
  96. >
  97. <u--input
  98. v-model="form.contactPhone"
  99. border="none"
  100. :maxlength="11"
  101. placeholder="用于接收短信通知"
  102. ></u--input>
  103. </u-form-item>
  104. </u--form>
  105. </view>
  106. <view class="content ticket-box">
  107. <view class="sub-title">
  108. 发票信息
  109. </view>
  110. <view class="box" @click="handleCall">
  111. <view class="ticket-title">
  112. 不需要发票
  113. </view>
  114. <view class="ticket-desc">
  115. 需要发票可以 联系 400-797-5000 客服开票
  116. </view>
  117. <image class="icon" src="../static/right.png" mode=""></image>
  118. </view>
  119. </view>
  120. <view class="btn-box">
  121. <view class="left">
  122. <view class="num">
  123. 共{{form.numberofRooms}}件
  124. </view>
  125. <view class="total">
  126. 合计 <view class="price-box">
  127. <view class="unit">
  128. </view>
  129. <view class="price">
  130. {{form.totalPrice}}
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. <button class="btn" @click="handleBuy" :loading="loading">
  136. 提交订单
  137. </button>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import {addOrder} from '@/api/hotel.js'
  143. import {
  144. creatPayOrder,
  145. queryPayOrder,
  146. } from '@/api/payment.js'
  147. export default {
  148. data() {
  149. return {
  150. tab: 0,
  151. day:1,
  152. form:{
  153. "roomNameCn":'',
  154. "hotelIdPic":'',
  155. "roomPic":'',
  156. "channel":'ZhongShu',
  157. "checkin": "",
  158. "checkout": "",
  159. "childAges": [
  160. 0
  161. ],
  162. "childNum": 0,
  163. "contactEmail": "",
  164. "contactName": "",
  165. "contactPhone": "",
  166. "customerArriveTime": "",
  167. "customerInfo": [
  168. {
  169. value:''
  170. }
  171. ],
  172. "hotelId": 0,
  173. "manNum": 0,
  174. "numberofRooms": 1,
  175. "ratePlanId": "",
  176. "specialRemarks": "",
  177. "totalPrice": 0
  178. },
  179. rules:{
  180. contactPhone:[
  181. {
  182. required: true,
  183. message: '请输入手机号',
  184. trigger: ['blur', 'change']
  185. },
  186. {
  187. // 自定义验证函数,见上说明
  188. validator: (rule, value, callback) => {
  189. // 上面有说,返回true表示校验通过,返回false表示不通过
  190. // uni.$u.test.mobile()就是返回true或者false的
  191. return uni.$u.test.mobile(value);
  192. },
  193. message: '手机号码不正确',
  194. // 触发器可以同时用blur和change
  195. trigger: ['change','blur'],
  196. }
  197. ],
  198. customerInfo:[]
  199. },
  200. loading:false,
  201. query: {
  202. "msgType": "wx.unifiedOrder",
  203. "orderDesc": "",
  204. "orderNo": "",
  205. "channel":'ZhongShu',
  206. "subOpenId": "",
  207. "userId": ""
  208. },
  209. averagePrice:0,
  210. info:{
  211. roomNameCn:'',
  212. area:'',
  213. window:'',
  214. meal:'',
  215. cancel:''
  216. }
  217. }
  218. },
  219. computed: {
  220. price() {
  221. this.form.totalPrice = this.averagePrice*this.form.numberofRooms*this.day
  222. return ''
  223. }
  224. },
  225. filters: {
  226. filterDate: function(value,type) {
  227. let timestamp = new Date(value).getTime()
  228. if(type == 'time'){
  229. return uni.$u.timeFormat(timestamp, 'mm月dd日');
  230. }else if(type == 'day'){
  231. let arr = ['日','一','二','三','四','五','六']
  232. let num = new Date(timestamp).getDay()
  233. return `周${arr[num]}`
  234. }
  235. },
  236. filterWindow:function(val){
  237. if(val === 0){
  238. return '无窗'
  239. }else if(val === 1){
  240. return '部分有窗'
  241. }else if(val === 2){
  242. return '有窗'
  243. }else if(val === 3){
  244. return '不确定'
  245. }else if(val === 4){
  246. return '内窗'
  247. }else if(val === 5){
  248. return '天窗'
  249. }else if(val === 6){
  250. return '封闭窗'
  251. }else if(val === 7){
  252. return '飘窗'
  253. }
  254. },
  255. },
  256. methods: {
  257. handleCall() {
  258. uni.makePhoneCall({
  259. phoneNumber: '400-797-5000' //仅为示例
  260. });
  261. },
  262. setRules() {
  263. this.form.customerInfo.forEach((ele, index) => {
  264. this.$set(this.rules, `customerInfo.${index}.value`, [
  265. {
  266. required: true,
  267. message: '请填写姓名',
  268. trigger: ['blur', 'change']
  269. },
  270. ])
  271. })
  272. this.$nextTick(() => {
  273. this.$refs.uForm.setRules(this.rules)
  274. })
  275. },
  276. choose(val){
  277. this.form.numberofRooms = val+1
  278. this.form.manNum = val+1
  279. if(this.form.customerInfo.length<val+1){
  280. let num = val+1 - this.form.customerInfo.length
  281. for (let index = 0; index < num; index++) {
  282. this.form.customerInfo.push({
  283. value:''
  284. })
  285. }
  286. }else if(this.form.customerInfo.length>val+1){
  287. this.form.customerInfo.length = val+1
  288. }
  289. this.$nextTick(()=>{
  290. this.setRules()
  291. })
  292. console.log('this.form.customerInfo',this.form.customerInfo,this.form.numberofRooms);
  293. },
  294. addOrder(query){
  295. if (this.loading) return
  296. this.loading = true
  297. uni.showLoading({
  298. title: '支付中'
  299. })
  300. let that = this
  301. addOrder(query).then(res=>{
  302. if(res.state == 'Success'){
  303. this.query.orderNo = res.content.orderNo
  304. this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
  305. this.query.orderDesc = this.form.roomNameCn
  306. creatPayOrder(this.query).then(data => {
  307. that.payData = JSON.parse(data.content.miniPayRequest)
  308. if (data.content.miniPayRequest == null) return uni.hideLoading()
  309. console.log(666,that.payData);
  310. uni.requestPayment({
  311. "provider": "wxpay",
  312. "orderInfo": that.payData,
  313. "appid": that.payData
  314. .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  315. "paySign": that.payData.paySign,
  316. "nonceStr": that.payData.nonceStr, // 随机字符串
  317. "package": that.payData.package, // 固定值
  318. // "prepayid": that.payData.package, // 统一下单订单号
  319. "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  320. "signType": that.payData.signType, //签名算法
  321. success(msg) {
  322. console.log('msg', that.query.orderNo);
  323. queryPayOrder(that.query.orderNo).then(res1 => {
  324. that.loading = false
  325. uni.hideLoading()
  326. if (res1.state == 'Success') {
  327. uni.reLaunch({
  328. url: '/my/order/index'
  329. })
  330. }
  331. })
  332. },
  333. fail(e) {
  334. console.log('err', e);
  335. that.loading = false
  336. uni.hideLoading()
  337. uni.showToast({
  338. title: '取消支付',
  339. icon: 'fail'
  340. })
  341. // 取消支付后
  342. uni.reLaunch({
  343. url:'/my/order/hotel/detail?id='+that.query.orderNo
  344. })
  345. }
  346. })
  347. })
  348. }
  349. })
  350. },
  351. handleBuy() {
  352. this.$refs.uForm.validate().then(res => {
  353. let form = JSON.parse(JSON.stringify(this.form))
  354. let list = []
  355. form.customerInfo.map(item=>{
  356. list.push(item.value)
  357. })
  358. form.customerInfo = list
  359. form.contactName = form.customerInfo[0]
  360. form.customerArriveTime = uni.$u.timeFormat(new Date(form.checkin).getTime()+1000*60*60*24 , 'yyyy-mm-dd')+' 17:00:00'
  361. this.addOrder(form)
  362. })
  363. }
  364. },
  365. onReady() {
  366. // this.$refs.uForm.setRules(this.rules)
  367. this.setRules()
  368. },
  369. onLoad(options) {
  370. this.form.checkin = options.checkInDate
  371. this.form.checkout = options.checkOutDate
  372. this.day = options.day
  373. let that = this
  374. const eventChannel = this.getOpenerEventChannel();
  375. eventChannel.on('pay', function(data) {
  376. let {manNum,childNum,hotelId,ratePlanId,averagePrice,roomPic,hotelPic,roomNameCn,area,window,meal,cancel} = data
  377. that.form.manNum = manNum
  378. that.form.childNum = childNum
  379. that.form.hotelId = hotelId
  380. that.form.ratePlanId = ratePlanId
  381. that.averagePrice = averagePrice
  382. that.form.hotelIdPic = hotelPic
  383. that.form.roomPic = roomPic
  384. that.form.roomNameCn = roomNameCn
  385. that.info = {
  386. area,
  387. window,
  388. meal,
  389. cancel
  390. }
  391. console.log('数据:',data);
  392. })
  393. }
  394. }
  395. </script>
  396. <style lang="scss" >
  397. .hotel-makeOut{
  398. background: #F9F9F9;
  399. border-radius: 0rpx 0rpx 0rpx 0rpx;
  400. padding: 20rpx 24rpx 200rpx;
  401. .u-form-item__body__left__content__label{
  402. font-size: 24rpx!important;
  403. color: #222222!important;
  404. }
  405. .content{
  406. padding: 24rpx;
  407. background: #fff;
  408. border-radius: 16rpx 16rpx 16rpx 16rpx;
  409. margin-bottom: 20rpx;
  410. .sub-title{
  411. font-weight: 600;
  412. font-size: 28rpx;
  413. color: #222222;
  414. padding-bottom: 26rpx;
  415. border-bottom: 1rpx solid #F0F0F0;
  416. }
  417. }
  418. .info-box{
  419. display: flex;
  420. .info{
  421. margin-left: 20rpx;
  422. flex: 1;
  423. .title{
  424. font-weight: 600;
  425. font-size: 36rpx;
  426. color: #222222;
  427. width: 450rpx;
  428. white-space: nowrap;
  429. overflow: hidden;
  430. text-overflow: ellipsis;
  431. margin-top: 20rpx;
  432. }
  433. .desc-box{
  434. display: flex;
  435. align-items: center;
  436. font-size: 24rpx;
  437. color: #AAAAAA;
  438. margin-top: 20rpx;
  439. .text{
  440. padding-right: 10rpx;
  441. }
  442. .text+.text{
  443. border-left: 2rpx solid #F0F0F0;
  444. padding-left: 10rpx;
  445. }
  446. }
  447. .notice{
  448. font-size: 24rpx;
  449. color: #AAAAAA;
  450. margin-top: 20rpx;
  451. }
  452. }
  453. }
  454. .bottom-box{
  455. display: flex;
  456. align-items: center;
  457. padding-top: 26rpx;
  458. border-top: 1rpx solid #F0F0F0;
  459. margin-top: 20rpx;
  460. .time-box{
  461. flex: 1;
  462. display: flex;
  463. .item{
  464. display: flex;
  465. align-items: center;
  466. .label{
  467. font-weight: 300;
  468. font-size: 24rpx;
  469. color: #AAAAAA;
  470. }
  471. .time{
  472. font-size: 24rpx;
  473. color: #222222;
  474. margin-left: 20rpx;
  475. }
  476. }
  477. .item+.item{
  478. margin-left: 80rpx;
  479. }
  480. }
  481. .day{
  482. font-size: 24rpx;
  483. color: #222222;
  484. font-weight: bold;
  485. }
  486. }
  487. .room-box{
  488. .desc{
  489. font-weight: 300;
  490. font-size: 24rpx;
  491. color: #AAAAAA;
  492. margin-top: 20rpx;
  493. }
  494. .tab-box{
  495. display: flex;
  496. flex-wrap: wrap;
  497. .ml20{
  498. margin-left: 20rpx;
  499. }
  500. .tab{
  501. width: 148rpx;
  502. height: 52rpx;
  503. line-height: 52rpx;
  504. text-align: center;
  505. background: #F0F0F0;
  506. border-radius: 8rpx 8rpx 8rpx 8rpx;
  507. font-weight: 300;
  508. font-size: 28rpx;
  509. color: #AAAAAA;
  510. margin-top: 20rpx;
  511. }
  512. .tab.active{
  513. background: #E2ECFF;
  514. color: #3879F9;
  515. }
  516. }
  517. }
  518. .add-box{
  519. .title-box{
  520. display: flex;
  521. align-items: center;
  522. justify-content: space-between;
  523. margin-top: 20rpx;
  524. .title{
  525. font-size: 28rpx;
  526. color: #222222;
  527. font-weight: bold;
  528. }
  529. .add-btn{
  530. font-weight: 300;
  531. font-size: 24rpx;
  532. color: #3879F9;
  533. }
  534. }
  535. }
  536. .btn-box {
  537. position: fixed;
  538. bottom: 0%;
  539. left: 0%;
  540. z-index: 2;
  541. width: 100%;
  542. display: flex;
  543. align-items: center;
  544. justify-content: space-between;
  545. box-sizing: border-box;
  546. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  547. background: #fff;
  548. border-top: 1rpx solid #EEEEEE;
  549. .left{
  550. display: flex;
  551. align-items: flex-end;
  552. .num{
  553. font-weight: 300;
  554. font-size: 24rpx;
  555. color: #AAAAAA;
  556. }
  557. .total{
  558. font-weight: 300;
  559. font-size: 24rpx;
  560. color: #222222;
  561. display: flex;
  562. align-items: flex-end;
  563. margin-left: 6rpx;
  564. .price-box{
  565. display: flex;
  566. align-items: flex-end;
  567. font-weight: 400;
  568. font-size: 32rpx;
  569. color: #222222;
  570. .unit{
  571. font-size: 20rpx;
  572. }
  573. }
  574. }
  575. }
  576. .btn {
  577. width: 280rpx;
  578. height: 80rpx;
  579. line-height: 80rpx;
  580. text-align: center;
  581. background: $uni-color-primary;
  582. border-radius: 40rpx;
  583. font-weight: 600;
  584. font-size: 28rpx;
  585. color: #FFFFFF;
  586. margin: 0;
  587. }
  588. }
  589. .ticket-box{
  590. .box{
  591. position: relative;
  592. .ticket-title{
  593. font-weight: 500;
  594. font-size: 24rpx;
  595. color: #222222;
  596. margin-top: 20rpx;
  597. }
  598. .ticket-desc{
  599. font-weight: 300;
  600. font-size: 24rpx;
  601. color: #AAAAAA;
  602. margin-top: 20rpx;
  603. }
  604. .icon{
  605. width: 48rpx;
  606. height: 48rpx;
  607. position: absolute;
  608. right: 0%;
  609. top: 50%;
  610. margin-top: -24rpx;
  611. }
  612. }
  613. }
  614. }
  615. </style>