order_room.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <view class="content">
  3. <!-- 第一层表单 -->
  4. <view class="two_all">
  5. <view class="select-time" @click="openCalendar">
  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. <!-- 房型信息 -->
  23. <view class="select_name">大床房</view>
  24. <view class="select_type">包吃住型</view>
  25. <view class="select_detail">
  26. 16-20㎡
  27. <text style="margin-left: 20px;">双人床</text>
  28. <text style="margin-left: 20px;">窗户位于走廊/窗户较小</text>
  29. </view>
  30. <uni-popup ref="popup_picker" :mask-click="true">
  31. <view class=popup_bg_picker>
  32. <uni-calendar :selected="info.selected" class="uni-calendar--hook" :clear-date="true" :date="info.date" :insert="info.insert" :lunar="info.lunar" :startDate="info.startDate"
  33. :endDate="info.endDate" :range="info.range" @change="change"/>
  34. </view>
  35. </uni-popup>
  36. </view>
  37. <!-- 第二层基本信息 -->
  38. <view class="second_basic">
  39. <view class="form_title">入住信息</view>
  40. <view class="form-line1"></view>
  41. <view class="form-num">房间数量:
  42. <text class="list-text">1间</text></view>
  43. <view class="form-line2"></view>
  44. <view class="form-name">住客姓名:
  45. <text class="list-text">{{cardName}}</text></view>
  46. <view class="form-line"></view>
  47. <view class="form-phone">联系电话:
  48. <text class="list-text">{{cardPhone}}</text></view>
  49. <view class="form-line" style="margin-top: 381rpx;"></view>
  50. <view class="uni-list-cell-db">预计到店:
  51. <picker style="margin-left: 70px;margin-top: -22px;"
  52. @change="bindPickerChange" :value="index" :range="array">
  53. <view class="uni-input" style="color: rgba(0, 0, 0, 1);">{{array[index]}}</view>
  54. <text class="jiantou">〉</text>
  55. </picker>
  56. </view>
  57. </view>
  58. <!-- 第三层表单 -->
  59. <view class="third_basic">
  60. <view class="third_title">费用明细</view>
  61. <view class="third-line1"></view>
  62. <view class="third-num">在线支付:
  63. <text class="third-text">1间1晚</text>
  64. <text style="margin-left: 10rpx;">共
  65. <text class="third-text2">¥280.00</text>
  66. </text>
  67. </view>
  68. </view>
  69. <!-- 第四层房费 -->
  70. <view class="four_basic">
  71. <view class="four_title">房费
  72. <text style="margin-left: 533rpx;">¥280</text>
  73. </view>
  74. <view class="four-line1"></view>
  75. <view class="four-num">2023-08-01</view>
  76. <view class="four-num2">2023-08-02</view>
  77. <view class="four-all">1 x ¥280</view>
  78. </view>
  79. <!-- 支付框 -->
  80. <view class="fukuan">
  81. <view class="fu-price">¥{{payMount}}</view>
  82. <view class="fu-zhifu" :class="{'room-button2': freeRoom == 0}">
  83. <text v-if="freeRoom==0">房间已满</text>
  84. <text v-else @click="getOrderSubmit('warn')">立即支付</text>
  85. </view>
  86. </view>
  87. <!-- 提交订单时弹框 -->
  88. <uni-popup ref="popup_order" type="dialog">
  89. <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="确定" :content="order_txt" @confirm="dialogConfirm"
  90. @close="dialogClose"></uni-popup-dialog>
  91. </uni-popup>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. getsubmittoken,
  97. getorderconfirm,
  98. getuserinfo,
  99. getsubmit
  100. } from '../../utils/api_hotel.js'
  101. /**
  102. * 获取任意时间
  103. */
  104. function getDate(date, AddDayCount = 0) {
  105. if (!date) {
  106. date = new Date()
  107. }
  108. if (typeof date !== 'object') {
  109. date = date.replace(/-/g, '/')
  110. }
  111. const dd = new Date(date)
  112. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  113. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  114. var week = new Date().getDay();
  115. var week2 = new Date().getDay()+1;
  116. const y = dd.getFullYear()
  117. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  118. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  119. const h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
  120. const f = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
  121. const s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
  122. return {
  123. fullDate: y + '-' + m + '-' + d,
  124. fullDate2: y + '-' + m + '-' + d+' '+h+':'+f+':'+s,
  125. fullTime: m + '月' + d + '日',
  126. year: y,
  127. month: m,
  128. date: d,
  129. day: dd.getDay(),
  130. sWeek:"周"+ a[week],
  131. eWeek:"周"+ a[week2]
  132. }
  133. }
  134. export default {
  135. data() {
  136. return {
  137. showCalendar: false,
  138. info: {
  139. lunar: true,
  140. range: true,
  141. insert: true,
  142. selected: [],
  143. startDate:'',
  144. date:'',
  145. endDate:''
  146. },
  147. startTime:'',//到店日期
  148. endTime:'',//离店日期
  149. startDate:'',//默认到店日期接口数据
  150. endDate:'',//默认离店日期接口数据
  151. startWeek:'',// 默认入店日
  152. endWeek:'',// 默认离店
  153. array: ['18:00前到店', '19:00前到店', '20:00前到店', '21:00前到店'],
  154. index: 0,
  155. mayTime:'',// 预计到店时间
  156. typeName:'',//户型名
  157. textNum:0,//输入框当前字数
  158. cardName:'',//用户名
  159. cardPhone:'',//用户电话
  160. cardIdentity:'',//身份
  161. submitToken:'',//请求令牌
  162. roomTypeId:'',//房间类型id
  163. remark:'',//备注要求
  164. payMount:0,//应付金额
  165. freeRoom:0,//剩余房间
  166. ruzhu_num:1,//入住夜晚
  167. order_txt:'',//提交订单时信息
  168. msgType:'warn',
  169. }
  170. },
  171. onLoad(option) {
  172. console.log(option)
  173. // this.payMount=Number(option.payMount)
  174. // this.ruzhu_num=option.ruzhu_num
  175. // this.freeRoom=option.freeRoom
  176. localStorage.setItem('roomTypeId',option.roomTypeId)
  177. localStorage.setItem('typeName',option.typeName)
  178. localStorage.setItem('startTime',option.startTime)
  179. localStorage.setItem('endTime',option.endTime)
  180. localStorage.setItem('enableStartTime',option.enableStartTime)
  181. localStorage.setItem('enableEndTime',option.enableEndTime)
  182. },
  183. mounted() {
  184. this.roomTypeId=localStorage.getItem('roomTypeId')
  185. this.typeName=localStorage.getItem('typeName')
  186. this.startTime=localStorage.getItem('startTime')
  187. this.endTime=localStorage.getItem('endTime')
  188. this.startDate=localStorage.getItem('enableStartTime').substring(0,11)+"12:00:00"
  189. this.endDate=localStorage.getItem('enableEndTime').substring(0,11)+"14:00:00"
  190. this.startWeek=this.getweekday(this.startDate)
  191. this.endWeek=this.getweekday(this.endDate)
  192. this.mayTime=this.startDate.substring(0,11)+"18:00:00"
  193. // console.log(this.getweekday(this.startDate))
  194. this.getTokenSubmit()
  195. // 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';
  196. this.getUserInfo()
  197. this.getOrderConfirm('warn')
  198. },
  199. onReady() {
  200. this.$nextTick(() => {
  201. this.showCalendar = true
  202. })
  203. // TODO 模拟请求异步同步数据
  204. setTimeout(() => {
  205. this.info.date = getDate(new Date()).fullDate
  206. this.info.startDate = getDate(new Date()).fullDate
  207. this.info.endDate = getDate(new Date(),6).fullDate
  208. this.startTime = getDate(new Date()).fullTime
  209. this.endTime = getDate(new Date(),1).fullTime
  210. this.startWeek = getDate(new Date()).sWeek
  211. this.endWeek = getDate(new Date(),1).eWeek
  212. this.ruzhu_num=1
  213. }, 20)
  214. },
  215. methods: {
  216. // 获取请求令牌
  217. getTokenSubmit() {
  218. let _self = this
  219. getsubmittoken().then((res) => {
  220. if (res.success) {
  221. this.submitToken=res.data.submitToken
  222. return;
  223. } else {
  224. console.log('获取请求令牌失败')
  225. }
  226. }).catch((err) => {
  227. this.$message.error(err.message)
  228. });
  229. // this.$axios.get("/hotel/ihotel-api/ihotel/hotelOrder/user/submit/token",
  230. // {
  231. // headers:{
  232. // 'user_token':localStorage.getItem('token')
  233. // }
  234. // }).then(res => {
  235. // res = res.data
  236. // if (res.success) {
  237. // this.submitToken=res.data.submitToken
  238. // } else {
  239. // console.log('获取请求令牌失败')
  240. // }
  241. // });
  242. },
  243. // 获取用户信息
  244. getUserInfo() {
  245. let _self = this
  246. getuserinfo().then((res) => {
  247. if (res.success) {
  248. if (res.data.statu == '1') {
  249. _self.cardName=res.data.name
  250. _self.cardPhone=res.data.telPhone
  251. _self.cardIdentity=res.data.identityType
  252. }else {
  253. alert('您没有权限,请联系客服')
  254. }
  255. return;
  256. } else {
  257. console.log('获取用户信息失败')
  258. }
  259. }).catch((err) => {
  260. this.$message.error(err.message)
  261. });
  262. // this.$axios.get("/hotel/ihotel-api/ihotel/hotelUser/userInfo",
  263. // {
  264. // headers:{
  265. // 'user_token':localStorage.getItem('token')
  266. // }
  267. // }).then(res => {
  268. // res = res.data
  269. // if (res.success) {
  270. // if (res.data.statu == '1') {
  271. // _self.cardName=res.data.name
  272. // _self.cardPhone=res.data.telPhone
  273. // _self.cardIdentity=res.data.identityType
  274. // }else {
  275. // alert('您没有权限,请联系客服')
  276. // }
  277. // } else {
  278. // console.log('获取用户信息失败')
  279. // }
  280. // });
  281. },
  282. // 确认订单
  283. getOrderConfirm(type) {
  284. let _self = this
  285. var data="?startTime="+this.startDate.substring(0,10)+
  286. "&endTime="+this.endDate.substring(0,10)+
  287. '&roomTypeId='+this.roomTypeId
  288. getorderconfirm(data).then((res) => {
  289. if (res.success) {
  290. this.payMount=res.data.totalAmount
  291. this.freeRoom=res.data.freeNum
  292. this.ruzhu_num=res.data.nums
  293. return;
  294. } else {
  295. this.msgType = type
  296. this.order_txt=res.message
  297. this.$refs.popup_order.open()
  298. }
  299. }).catch((err) => {
  300. this.$message.error(err.message)
  301. });
  302. // this.$axios.get("/hotel/ihotel-api/ihotel/hotelOrder/user/order/confirm?startTime="+this.startDate.substring(0,10)+"&endTime="+this.endDate.substring(0,10)+'&roomTypeId='+this.roomTypeId).then(res => {
  303. // res = res.data
  304. // if (res.success) {
  305. // this.payMount=res.data.totalAmount
  306. // this.freeRoom=res.data.freeNum
  307. // this.ruzhu_num=res.data.nums
  308. // } else {
  309. // this.msgType = type
  310. // this.order_txt=res.message
  311. // this.$refs.popup_order.open()
  312. // }
  313. // });
  314. },
  315. // 提交订单
  316. getOrderSubmit(type) {
  317. uni.navigateTo({
  318. url:'/pages/submit_order/submit_order'
  319. })
  320. this.payUrl=''
  321. let _self = this
  322. this.$axios.defaults.headers.common['user_token'] = localStorage.getItem('token');
  323. this.$axios.defaults.headers.common['request_token'] = this.submitToken;
  324. this.$axios.defaults.headers.common['Content-Type'] ='application/json'
  325. var data={
  326. "enableStartTime":this.startDate,//入住时间
  327. "enableEndTime":this.endDate,//离店时间
  328. "roomTypeId":this.roomTypeId,//房间类型id
  329. "payAmount":this.payMount,//需支付金额
  330. "userName":this.cardName,
  331. "userPhone":this.cardPhone,
  332. "mayIntoTime":this.mayTime,
  333. "remark":this.remark,
  334. }
  335. getsubmit(data).then((res) => {
  336. if (res.success) {
  337. uni.navigateTo({
  338. url:'/pages/submit_order/submit_order'
  339. })
  340. // if(res.data.payAmount==0) {
  341. // uni.navigateTo({
  342. // url:'../zhifuchenggong/zhifuchenggong?orderId='+res.data.orderId
  343. // })
  344. // } else {
  345. // window.location.href = res.data.payUrl;
  346. // }
  347. // return;
  348. } else {
  349. this.msgType = type
  350. this.order_txt=res.message
  351. this.$refs.popup_order.open()
  352. }
  353. }).catch((err) => {
  354. this.$message.error(err.message)
  355. });
  356. // this.$axios.post("/hotel/ihotel-api/ihotel/hotelOrder/user/order/submit",
  357. // {
  358. // "enableStartTime":this.startDate,//入住时间
  359. // "enableEndTime":this.endDate,//离店时间
  360. // "roomTypeId":this.roomTypeId,//房间类型id
  361. // "payAmount":this.payMount,//需支付金额
  362. // "userName":this.cardName,
  363. // "userPhone":this.cardPhone,
  364. // "mayIntoTime":this.mayTime,
  365. // "remark":this.remark,
  366. // }
  367. // ).then(res => {
  368. // res = res.data
  369. // if (res.success) {
  370. // if(res.data.payAmount==0) {
  371. // uni.navigateTo({
  372. // url:'../zhifuchenggong/zhifuchenggong?orderId='+res.data.orderId
  373. // })
  374. // } else {
  375. // window.location.href = res.data.payUrl;
  376. // }
  377. // } else {
  378. // this.msgType = type
  379. // this.order_txt=res.message
  380. // this.$refs.popup_order.open()
  381. // }
  382. // });
  383. },
  384. // 计算指定时间是周几
  385. getweekday(date){
  386. // date例如:'2022-03-05'
  387. var weekArray = new Array("周日","周一", "周二", "周三", "周四", "周五", "周六")
  388. var weeka = weekArray[new Date(date).getDay()]
  389. return weeka
  390. },
  391. //日历选择器
  392. openCalendar() {
  393. this.$refs.popup_picker.open()
  394. },
  395. change(e) {
  396. console.log('1change 返回:', e)
  397. // 模拟动态打卡
  398. // if (this.info.selected.length > 5) return
  399. this.info.selected=[
  400. {
  401. date: e.range.before,
  402. info: '到店'
  403. },
  404. {
  405. date: e.range.after,
  406. info: '离店'
  407. }
  408. ]
  409. if(e.range.before!=''&&e.range.after=='') {
  410. this.startWeek='周'+e.lunar.ncWeek.substring(2,3)
  411. } else if(e.range.before!=''&&e.range.after!=''){
  412. if((new Date(e.range.after).getTime())<(new Date(e.range.before).getTime())) {
  413. this.order_txt='离店日期不能小于到店日期'
  414. this.$refs.popup_order.open()
  415. }else{
  416. this.endWeek='周'+e.lunar.ncWeek.substring(2,3)
  417. this.startTime=e.range.before.substring(5,7)+'月'+e.range.before.substring(8,10)+'日'
  418. this.endTime=e.range.after.substring(5,7)+'月'+e.range.after.substring(8,10)+'日'
  419. this.startDate = e.range.before +' 14:00:00'
  420. this.endDate = e.range.after +' 12:00:00'
  421. this.ruzhu_num=parseInt(((new Date(e.range.after).getTime())-(new Date(e.range.before).getTime()))/1000/60/60/24)
  422. }
  423. }
  424. },
  425. //选择器
  426. bindPickerChange: function(e) {
  427. console.log('picker发送选择改变,携带值为', e.detail.value)
  428. this.index = e.detail.value
  429. this.mayTime = this.startDate.substring(0,11)+this.array[this.index].substring(0,5)+":00"
  430. // console.log(this.mayTime)
  431. },
  432. // 输入框
  433. bindTextAreaBlur: function (e) {
  434. // console.log(e.detail.cursor)
  435. // console.log(e.detail.value)
  436. this.textNum=e.detail.cursor
  437. this.remark=e.detail.value
  438. }
  439. }
  440. }
  441. </script>
  442. <style>
  443. @import url("./css/order_room.css");
  444. </style>