order_room.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <view class="content">
  3. <!-- 第一层表单 -->
  4. <view class="two_all">
  5. <view class="select-time" @click="openCalendar" v-if="roomType==1">
  6. <view class="select-time-one">
  7. <text class="select-list-time">{{startTime}}
  8. <text class="select-list">{{startWeek}}</text>
  9. </text>
  10. </view>
  11. <view class="select-center">
  12. <view class="select-line1"></view>
  13. <view class="select-circle">{{ruzhu_num}}晚</view>
  14. <view class="select-line2"></view>
  15. </view>
  16. <view class="select-time-one">
  17. <text class="select-list-time">{{endTime}}
  18. <text class="select-list">{{endWeek}}</text>
  19. </text>
  20. </view>
  21. </view>
  22. <view class="select-time" v-if="roomType==2">
  23. <view class="select-time-one">
  24. <text class="select-list-time">{{startTime}}
  25. <text class="select-list">{{startWeek}}</text>
  26. </text>
  27. </view>
  28. <view class="select-time-one">
  29. <text class="select-list-time" style="font-size: 12px;">{{zhongTime}}
  30. <text class="select-list">{{zhongshi}}小时</text>
  31. </text>
  32. </view>
  33. </view>
  34. <!-- 房型信息 -->
  35. <view class="select_name">{{typeName}}</view>
  36. <view class="select_type" v-if="roomType==1">全日房</view>
  37. <view class="select_type" v-else-if="roomType==2">钟点房</view>
  38. <view class="select_detail">
  39. {{roomArea}}㎡
  40. <text style="margin-left: 20px;">{{roomConfiguration}}</text>
  41. <!-- <text style="margin-left: 20px;">窗户位于走廊/窗户较小</text> -->
  42. </view>
  43. <uni-popup ref="popup_picker" :mask-click="true">
  44. <view class=popup_bg_picker>
  45. <uni-calendar :selected="info.selected" class="uni-calendar--hook" :clear-date="true" :date="info.date" :insert="info.insert" :lunar="info.lunar" :startDate="info.startDate"
  46. :endDate="info.endDate" :range="info.range" @change="change"/>
  47. </view>
  48. </uni-popup>
  49. </view>
  50. <!-- 第二层基本信息 -->
  51. <view class="second_basic">
  52. <view class="form_title">入住信息</view>
  53. <view class="form-line1"></view>
  54. <view class="form-num">房间数量:
  55. <text class="list-text">1间</text></view>
  56. <view class="form-line2"></view>
  57. <view class="form-name">住客姓名:
  58. <text class="list-text">{{cardName}}</text></view>
  59. <view class="form-line"></view>
  60. <view class="form-phone">联系电话:
  61. <text class="list-text">{{cardPhone}}</text></view>
  62. <view class="form-line" style="margin-top: 381rpx;"></view>
  63. <view class="uni-list-cell-db" v-if="roomType==1">预计到店:
  64. <picker style="margin-left: 70px;margin-top: -22px;"
  65. @change="bindPickerChange" :value="index" :range="array">
  66. <view class="uni-input" style="color: rgba(0, 0, 0, 1);">{{array[index]}}</view>
  67. <text class="jiantou">〉</text>
  68. </picker>
  69. </view>
  70. <view class="uni-list-cell-db" v-if="roomType==2">入住时段:
  71. <picker style="margin-left: 70px;margin-top: -22px;"
  72. @change="bindPickerChange2" :value="index2" :range="array2">
  73. <view class="uni-input" style="color: rgba(0, 0, 0, 1);">{{array2[index2]}}</view>
  74. <text class="jiantou">〉</text>
  75. </picker>
  76. </view>
  77. </view>
  78. <!-- 第三层表单 -->
  79. <view class="third_basic">
  80. <view class="third_title">费用明细</view>
  81. <view class="third-line1"></view>
  82. <view class="third-num">在线支付:
  83. <text class="third-text">
  84. 1间
  85. <template v-if="roomType==1">{{ruzhu_num}}晚</template>
  86. </text>
  87. <text style="margin-left: 10rpx;">共
  88. <text class="third-text2">¥{{payMount}}</text>
  89. </text>
  90. </view>
  91. </view>
  92. <!-- 第四层房费 -->
  93. <view class="four_basic">
  94. <view class="four_title">房费
  95. <text style="margin-left: 533rpx;">¥{{payMount}}</text>
  96. </view>
  97. <view class="four-line1"></view>
  98. <view class="four-num">{{startDate}}</view>
  99. <view class="four-num2">{{endDate}}</view>
  100. <view class="four-all">{{ruzhu_num}} x ¥{{roomPrice}}</view>
  101. </view>
  102. <!-- 支付框 -->
  103. <view class="fukuan">
  104. <view class="fu-price">¥{{payMount}}</view>
  105. <view class="fu-zhifu" :class="{'room-button2': freeRoom == 0}">
  106. <!-- <text v-if="freeRoom==0">房间已满</text> -->
  107. <!-- v-else<text v-else @click="getOrderSubmit('warn')">立即支付</text> -->
  108. <text @click="postOrder('warn')">立即支付</text>
  109. </view>
  110. </view>
  111. <!-- 提交订单时弹框 -->
  112. <uni-popup ref="popup_order" type="dialog">
  113. <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="确定" :content="order_txt" @confirm="dialogConfirm"
  114. @close="dialogClose"></uni-popup-dialog>
  115. </uni-popup>
  116. </view>
  117. </template>
  118. <script>
  119. import {
  120. getuserinfo,
  121. getprice,
  122. postOrder,
  123. getZhongTime
  124. } from '../../utils/api_hotel.js'
  125. /**
  126. * 获取任意时间
  127. */
  128. function getDate(date, AddDayCount = 0) {
  129. if (!date) {
  130. date = new Date()
  131. }
  132. if (typeof date !== 'object') {
  133. date = date.replace(/-/g, '/')
  134. }
  135. const dd = new Date(date)
  136. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  137. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  138. var week = new Date().getDay();
  139. var week2 = new Date().getDay()+1;
  140. const y = dd.getFullYear()
  141. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  142. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  143. const h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
  144. const f = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
  145. const s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
  146. return {
  147. fullDate: y + '-' + m + '-' + d,
  148. fullDate2: y + '-' + m + '-' + d+' '+h+':'+f+':'+s,
  149. fullTime: m + '月' + d + '日',
  150. year: y,
  151. month: m,
  152. date: d,
  153. day: dd.getDay(),
  154. sWeek:"周"+ a[week],
  155. eWeek:"周"+ a[week2]
  156. }
  157. }
  158. export default {
  159. data() {
  160. return {
  161. showCalendar: false,
  162. info: {
  163. lunar: true,
  164. range: true,
  165. insert: true,
  166. selected: [],
  167. startDate:'',
  168. date:'',
  169. endDate:''
  170. },
  171. startTime:'',//到店日期
  172. endTime:'',//离店日期
  173. startDate:'',//默认到店日期接口数据
  174. endDate:'',//默认离店日期接口数据
  175. startWeek:'',// 默认入店日
  176. endWeek:'',// 默认离店
  177. array: ['18:00前到店', '19:00前到店', '20:00前到店', '21:00前到店'],
  178. index: 0,
  179. array2: [''],//钟点房
  180. index2: 0,
  181. mayTime:'',// 预计到店时间
  182. typeName:'',//户型名
  183. textNum:0,//输入框当前字数
  184. cardName:'',//用户名
  185. cardPhone:'',//用户电话
  186. cardIdentity:'',//身份
  187. roomTypeId:'',//房间类型id
  188. remark:'',//备注要求
  189. payMount:0,//应付金额
  190. freeRoom:0,//剩余房间可预订的房间数
  191. ruzhu_num:1,//入住夜晚
  192. roomArea:'0',//房间面积
  193. roomType:1,//房间类型
  194. roomPrice:"",//房间单价
  195. roomConfiguration:'',//房间配置
  196. order_txt:'',//提交订单时信息
  197. msgType:'warn',
  198. zhongTime:'',//钟点房订的时间段
  199. zhongshi:'',//钟点房时间
  200. startDateZ:'',//钟点房默认到店日期接口数据
  201. endDateZ:'',//钟点房默认离店日期接口数据
  202. }
  203. },
  204. onLoad(option) {
  205. console.log(option)
  206. // this.payMount=Number(option.payMount)
  207. this.ruzhu_num=option.ruzhu_num
  208. this.roomArea=option.roomArea
  209. this.roomType=option.roomType
  210. this.roomConfiguration=option.roomConfiguration
  211. this.roomPrice=option.roomPrice
  212. this.freeRoom=option.surplusCount
  213. this.zhongTime=option.zhongTime
  214. this.zhongshi=option.zhongshi
  215. localStorage.setItem('roomTypeId',option.roomTypeId)
  216. localStorage.setItem('typeName',option.typeName)
  217. localStorage.setItem('startTime',option.startTime)
  218. localStorage.setItem('endTime',option.endTime)
  219. localStorage.setItem('enableStartTime',option.enableStartTime)
  220. localStorage.setItem('enableEndTime',option.enableEndTime)
  221. localStorage.setItem('zhongTime',option.zhongTime)
  222. },
  223. mounted() {
  224. this.roomTypeId=localStorage.getItem('roomTypeId')
  225. this.typeName=localStorage.getItem('typeName')
  226. this.startTime=localStorage.getItem('startTime')
  227. this.endTime=localStorage.getItem('endTime')
  228. this.zhongTime=localStorage.getItem('zhongTime')
  229. this.startDate=localStorage.getItem('enableStartTime')
  230. this.endDate=localStorage.getItem('enableEndTime')
  231. this.startWeek=this.getweekday(this.startDate)
  232. this.endWeek=this.getweekday(this.endDate)
  233. this.mayTime=this.startDate.substring(0,11)+"18:00:00"
  234. // console.log(this.getweekday(this.startDate))
  235. this.getZhongTime()
  236. // window.location.href ='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa46ef222053a1047&redirect_uri=https://chtech.ncjti.edu.cn/hotel/ihotel-api/ihotel/hotelUser/weixinAuth&response_type=code&scope=snsapi_base&state=pages/order_room/order_room#wechat_redirect';
  237. this.getUserInfo()
  238. },
  239. onReady() {
  240. this.$nextTick(() => {
  241. this.showCalendar = true
  242. })
  243. // TODO 模拟请求异步同步数据
  244. setTimeout(() => {
  245. this.info.date = getDate(new Date()).fullDate
  246. this.info.startDate = getDate(new Date()).fullDate
  247. this.info.endDate = getDate(new Date(),6).fullDate
  248. // this.startTime = getDate(new Date()).fullTime
  249. // this.endTime = getDate(new Date(),1).fullTime
  250. // this.startWeek = getDate(new Date()).sWeek
  251. // this.endWeek = getDate(new Date(),1).eWeek
  252. // this.ruzhu_num=1
  253. }, 20)
  254. },
  255. methods: {
  256. // 获取用户信息
  257. getUserInfo() {
  258. let _self = this
  259. var data="?userId="+localStorage.getItem('usersId')
  260. getuserinfo(data).then((res) => {
  261. if (res.success) {
  262. _self.cardName=res.data.userName
  263. _self.cardPhone=res.data.phone
  264. _self.cardIdentity=res.data.idCardInformation
  265. this.getjisuanprice()
  266. return;
  267. } else {
  268. console.log('获取用户信息失败')
  269. }
  270. }).catch((err) => {
  271. this.$message.error(err.message)
  272. });
  273. },
  274. //获取钟点房可住时间段
  275. getZhongTime(){
  276. this.array2=[]
  277. let _self = this
  278. var data="?houseNumberId="+_self.roomTypeId+"&startTime="+_self.startDate
  279. +"&liveTime="+this.zhongshi
  280. getZhongTime(data).then((res) => {
  281. if (res.success) {
  282. res.data.forEach(data => {
  283. if(data.status=="可用"){
  284. _self.array2.push(data.hourDate)
  285. this.startDateZ=localStorage.getItem('enableStartTime').substring(0,11)+this.array2[0].substring(0,8)
  286. this.endDateZ=localStorage.getItem('enableEndTime').substring(0,11)+this.array2[0].substring(9,17)
  287. }
  288. })
  289. return;
  290. } else {
  291. console.log('失败')
  292. }
  293. }).catch((err) => {
  294. uni.showModal({
  295. content:err.message
  296. })
  297. });
  298. },
  299. // 计算订单金额
  300. getjisuanprice() {
  301. this.payMount=0
  302. let _self = this
  303. var data="?userId="+localStorage.getItem('usersId')
  304. +
  305. "&houseId="+_self.roomTypeId+"&liveTime="+_self.startDate
  306. +"&leaveTime="+_self.endDate+"&houseOrderNumber=1"
  307. getprice(data).then((res) => {
  308. if (res.success) {
  309. _self.payMount=res.data
  310. return;
  311. } else {
  312. uni.showModal({
  313. content:res.message
  314. })
  315. }
  316. }).catch((err) => {
  317. uni.showModal({
  318. content:err.message
  319. })
  320. });
  321. },
  322. // onBridgeReady () {
  323. // console.log('调用微信支付WeixinJSBridge')
  324. // var vm = this
  325. // WeixinJSBridge.invoke(
  326. // 'getBrandWCPayRequest', { // 下面参数内容都是后台返回的
  327. // "appId": "wxd87cbe1db0437303", //公众号ID,由商户传入
  328. // "timeStamp": "1720083271",//时间戳,自1970年以来的秒数
  329. // "nonceStr": "ORsH3qtW9wauQQ7iV5ovSm6n58s6Z2Nu", //随机串
  330. // "package": "prepay_id=wx041654316576072897ded7969912130000",
  331. // "signType": "RSA", //微信签名方式:
  332. // "paySign": "ZbyL2qiE9QScgwEHhObRn5/9VQgJQxLo0zKc7VxUK+Emeb3Eas/rzePUp89rHnUVYDCRJcbNsmuR2b1LHY4mydBZVnPy1vwHE/EOrCmdgALZ4J8GcQK0wTLNu9kMx97WR0f9TItPN/sR604df9ca5CKA4P40vNaUIEdK45mkqo3MR2IAdvyn+L8DhW49cL7jlsqIRiohVwwRsS4n06mX/yx1kuA339l7hbwnHaq7D4elvEqFYoMSHD8CR3XnoZ0HFE7Klu1RChMzgO4WUgVIMUxhsF6bhy5TkSea25OG/QWGZW/EHOl58bTCg3PorhZeJ/7fDkIC6pNRtKndrdsd+Q==" //微信签名
  333. // },
  334. // function(res){
  335. // if(res.err_msg == "get_brand_wcpay_request:ok" ) {} // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
  336. // }
  337. // )
  338. // },
  339. //创建订单
  340. postOrder(type){
  341. // var vm = this
  342. // if (typeof WeixinJSBridge === 'undefined') { // 微信浏览器内置对象。参考微信官方文档
  343. // if (document.addEventListener) {
  344. // document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(), false)
  345. // } else if (document.attachEvent) {
  346. // document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady())
  347. // document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady())
  348. // }
  349. // } else {
  350. // console.log('准备调用微信支付')
  351. // vm.onBridgeReady()
  352. // }
  353. if(this.roomType=='1'){
  354. var startDate=this.startDate
  355. var endDate=this.endDate
  356. }else {
  357. var startDate=this.startDateZ
  358. var endDate=this.endDateZ
  359. }
  360. this.payUrl=''
  361. let _self = this
  362. this.$axios.defaults.headers.common['token'] = localStorage.getItem('token');
  363. this.$axios.defaults.headers.common['user_head'] = localStorage.getItem('user_head');
  364. this.$axios.defaults.headers.common['Content-Type'] ='application/json'
  365. var data={
  366. "userId": localStorage.getItem('usersId'),
  367. "houseId": this.roomTypeId,
  368. "payPrice": this.payMount,
  369. "houseOrderNumber": 1,
  370. "liveDay": this.ruzhu_num,
  371. "reserveLiveTime": startDate,
  372. "reserveLeaveTime": endDate,
  373. "reservePhone": this.cardPhone,
  374. "reserveName": this.cardName
  375. }
  376. postOrder(data).then((res) => {
  377. if (res.success) {
  378. uni.navigateTo({
  379. url:'/pages/submit_order/submit_order?houseOrderId='+res.data.id
  380. })
  381. // if(res.data.payAmount==0) {
  382. // uni.navigateTo({
  383. // url:'../zhifuchenggong/zhifuchenggong?orderId='+res.data.orderId
  384. // })
  385. // } else {
  386. // window.location.href = res.data.payUrl;
  387. // }
  388. // return;
  389. } else {
  390. this.msgType = type
  391. this.order_txt=res.message
  392. this.$refs.popup_order.open()
  393. }
  394. }).catch((err) => {
  395. this.$message.error(err.message)
  396. });
  397. },
  398. // 计算指定时间是周几
  399. getweekday(date){
  400. // date例如:'2022-03-05'
  401. var weekArray = new Array("周日","周一", "周二", "周三", "周四", "周五", "周六")
  402. var weeka = weekArray[new Date(date).getDay()]
  403. return weeka
  404. },
  405. //日历选择器
  406. openCalendar() {
  407. this.$refs.popup_picker.open()
  408. },
  409. change(e) {
  410. console.log('1change 返回:', e)
  411. // 模拟动态打卡
  412. // if (this.info.selected.length > 5) return
  413. this.info.selected=[
  414. {
  415. date: e.range.before,
  416. info: '到店'
  417. },
  418. {
  419. date: e.range.after,
  420. info: '离店'
  421. }
  422. ]
  423. if(e.range.before!=''&&e.range.after=='') {
  424. this.startWeek='周'+e.lunar.ncWeek.substring(2,3)
  425. } else if(e.range.before!=''&&e.range.after!=''){
  426. if((new Date(e.range.after).getTime())<(new Date(e.range.before).getTime())) {
  427. this.order_txt='离店日期不能小于到店日期'
  428. this.$refs.popup_order.open()
  429. }else{
  430. this.endWeek='周'+e.lunar.ncWeek.substring(2,3)
  431. this.startTime=e.range.before.substring(5,7)+'月'+e.range.before.substring(8,10)+'日'
  432. this.endTime=e.range.after.substring(5,7)+'月'+e.range.after.substring(8,10)+'日'
  433. this.startDate = e.range.before +' '+localStorage.getItem('liveTime')
  434. this.endDate = e.range.after +' '+localStorage.getItem('leaveTime')
  435. this.ruzhu_num=parseInt(((new Date(e.range.after).getTime())-(new Date(e.range.before).getTime()))/1000/60/60/24)
  436. }
  437. }
  438. this.getjisuanprice()
  439. },
  440. //选择器
  441. bindPickerChange: function(e) {
  442. console.log('picker发送选择改变,携带值为', e.detail.value)
  443. this.index = e.detail.value
  444. this.mayTime = this.startDate.substring(0,11)+this.array[this.index].substring(0,5)+":00"
  445. // console.log(this.mayTime)
  446. },
  447. //钟点房选择器
  448. bindPickerChange2: function(e) {
  449. console.log('picker发送选择改变,携带值为', e.detail.value)
  450. this.index2 = e.detail.value
  451. console.log(this.array2[this.index2].substring(0,8),this.array2[this.index2])
  452. if(this.array2.length<=0){
  453. }else{
  454. this.startDateZ=localStorage.getItem('enableStartTime').substring(0,11)+this.array2[this.index2].substring(0,8)
  455. this.endDateZ=localStorage.getItem('enableEndTime').substring(0,11)+this.array2[this.index2].substring(9,17)
  456. }
  457. this.mayTime = this.startDate.substring(0,11)+this.array[this.index].substring(0,5)+":00"
  458. // console.log(this.mayTime)
  459. },
  460. // 输入框
  461. bindTextAreaBlur: function (e) {
  462. this.textNum=e.detail.cursor
  463. this.remark=e.detail.value
  464. }
  465. }
  466. }
  467. </script>
  468. <style>
  469. @import url("./css/order_room.css");
  470. </style>