order_room.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="content">
  3. <!-- 背景图 -->
  4. <view class="index_bg">
  5. <view class="welcome">
  6. <image class="welcome_img" src="../../static/index/welcome.png"></image>
  7. </view>
  8. </view>
  9. <!-- 第一层标题 -->
  10. <view class="touming_bg">
  11. <view class="touming_title">研究生公寓(南昌交通学院)</view>
  12. <view class="touming_txt">您辛苦了,欢迎入住!</view>
  13. </view>
  14. <!-- 第二层表单 -->
  15. <view class="two_all">
  16. <view class="select-time" @click="openCalendar">
  17. <view class="select-time-one">
  18. <text class="select-list">{{ startWeek }}入住</text>
  19. <text class="select-list-time">{{ startTime }}</text>
  20. </view>
  21. <view class="select-center">
  22. <view class="select-line1"></view>
  23. <view class="select-circle">{{ ruzhu_num }} 晚</view>
  24. <view class="select-line2"></view>
  25. </view>
  26. <view class="select-time-one">
  27. <text class="select-list">{{ endWeek }}离店</text>
  28. <text class="select-list-time">{{ endTime }}</text>
  29. </view>
  30. </view>
  31. <!-- <uni-popup ref="popup_picker" :mask-click="true">
  32. <view class=popup_bg_picker>
  33. <uni-calendar :selected="info.selected" class="uni-calendar--hook" :clear-date="true" :date="info.date" :insert="info.insert"
  34. :lunar="info.lunar" :startDate="info.startDate" :endDate="info.endDate" :range="info.range" @change="change" />
  35. </view>
  36. </uni-popup> -->
  37. <view class="form_bg">
  38. <view class="form_title">房型:{{ h_type }},1.5米双人床一张。</view>
  39. <view class="form-text">姓名:{{ cardName }}</view>
  40. <view class="form-text">手机:{{ cardPhone }}</view>
  41. <view class="form-text">身份:{{ cardIdentity }}</view>
  42. </view>
  43. </view>
  44. <!-- 注释 -->
  45. <!-- <view class="zhushi">
  46. <text class="zhushi-mark"><text class="zhushi-circle"></text>低价保证</text>
  47. <text class="zhushi-mark"><text class="zhushi-circle"></text>入住免房费</text>
  48. <text class="zhushi-mark"><text class="zhushi-circle"></text>提前选好房</text>
  49. </view> -->
  50. <view class="cancel-rule">取消规则:未办理入住的订单在入住当天前可以办理退款,入住当天凌晨后均不允许退款操作。</view>
  51. <view class="cancel-rule">
  52. 入住时间14:00,退房时间12:00
  53. </view>
  54. <!-- 支付框 -->
  55. <view class="fukuan">
  56. <view class="fu-price"><text style="font-size: 28rpx;">总计:</text>¥{{ payMount }}</view>
  57. <view class="fu-zhifu" :class="{'room-button2': freeRoom == 0}">
  58. <text v-if="freeRoom == 0">房间已满</text>
  59. <text v-else @tap="getOrderSubmit()">立即支付</text>
  60. </view>
  61. </view>
  62. <!-- 提交订单时弹框 -->
  63. <uni-popup ref="popup_order" type="dialog">
  64. <uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="确定" :content="order_txt" @confirm="dialogConfirm"></uni-popup-dialog>
  65. </uni-popup>
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. accredit
  71. } from '@/static/shared.js';
  72. export default {
  73. data() {
  74. return {
  75. showCalendar: false,
  76. info: {
  77. lunar: true,
  78. range: true,
  79. insert: true,
  80. selected: [],
  81. startDate: '',
  82. date: '',
  83. endDate: ''
  84. },
  85. startTime: '', //到店日期
  86. endTime: '', //离店日期
  87. startDate: '', //默认到店日期接口数据
  88. endDate: '', //默认离店日期接口数据
  89. startWeek: '', // 默认入店日
  90. endWeek: '', // 默认离店
  91. array: ['18:00前到店', '19:00前到店', '20:00前到店', '21:00前到店'],
  92. index: 0,
  93. mayTime: '', // 预计到店时间
  94. typeName: '', //户型名
  95. textNum: 0, //输入框当前字数
  96. cardName: '', //用户名
  97. cardPhone: '', //用户电话
  98. cardIdentity: '', //身份
  99. submitToken: '', //请求令牌
  100. // roomTypeId: '', //房间类型id
  101. remark: '', //备注要求
  102. payMount: 0, //应付金额
  103. price: 0,
  104. freeRoom: 0, //剩余房间
  105. ruzhu_num: 1, //入住夜晚
  106. order_txt: '', //提交订单时信息
  107. msgType: 'warn',
  108. cardNumber: '',
  109. payData: {}
  110. }
  111. },
  112. onLoad(option) {
  113. // console.log('option', option)
  114. this.ruzhu_num = option.ruzhu_num
  115. this.price = option.price
  116. this.payMount = Number(option.price * option.ruzhu_num) //应付金额
  117. this.freeRoom = option.freeRoom //剩余房间
  118. // this.roomTypeId = option.roomTypeId //房间类型id
  119. this.h_type = option.typeName //户型名
  120. this.startTime = option.startTime //到店日期
  121. this.endTime = option.endTime //离店日期
  122. this.startDate = option.enableStartTime.substring(0, 11) + "12:00:00" //默认到店日期接口数据
  123. this.endDate = option.enableEndTime.substring(0, 11) + "14:00:00" //默认离店日期接口数据
  124. // this.startWeek = this.$utils.getweekday(this.startDate) // 默认入店日
  125. // this.endWeek = this.$utils.getweekday(this.endDate) // 默认离店
  126. this.startWeek = option.startWeek
  127. this.endWeek = option.endWeek
  128. this.mayTime = this.startDate.substring(0, 11) + "18:00:00" // 预计到店时间
  129. // console.log(this.$utils.getweekday(this.startDate))
  130. },
  131. mounted() {
  132. // 获取用户信息
  133. this.getUserInfo();
  134. },
  135. onReady() {
  136. var that = this
  137. that.$nextTick(() => {
  138. that.showCalendar = true
  139. })
  140. // TODO 模拟请求异步同步数据
  141. setTimeout(() => {
  142. that.info.date = that.$utils.getDate(new Date()).fullDate
  143. that.info.startDate = that.$utils.getDate(new Date()).fullDate
  144. // that.info.endDate = that.$utils.getDate(new Date(), 6).fullDate
  145. that.info.endDate = that.$utils.getDate(new Date('2023-09-15')).fullDate
  146. if (that.$utils.isEmpty(that.startTime)) {
  147. that.startTime = that.$utils.getDate(new Date()).fullTime
  148. }
  149. if (that.$utils.isEmpty(that.endTime)) {
  150. that.endTime = that.$utils.getDate(new Date(), 1).fullTime
  151. }
  152. if (that.$utils.isEmpty(that.startWeek)) {
  153. that.startWeek = that.$utils.getDate(new Date()).sWeek
  154. }
  155. if (that.$utils.isEmpty(that.endWeek)) {
  156. that.endWeek = that.$utils.getDate(new Date(), 1).eWeek
  157. }
  158. if (that.$utils.isEmpty(that.ruzhu_num)) {
  159. that.ruzhu_num = 1
  160. }
  161. }, 20)
  162. },
  163. methods: {
  164. /**
  165. * 调起支付
  166. */
  167. onBridgeReady() {
  168. var that = this;
  169. // 在这里可以使用WeixinJSBridge对象进行支付调用等操作
  170. // 调用支付接口
  171. if (typeof WeixinJSBridge !== 'undefined') {
  172. WeixinJSBridge.invoke('getBrandWCPayRequest', that.payData,
  173. function(res) {
  174. if (res.err_msg == "get_brand_wcpay_request:ok") {
  175. // 使用以上方式判断前端返回,微信团队郑重提示:
  176. //res.errMsg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  177. uni.showModal({
  178. title: '提示',
  179. content: '支付成功',
  180. showCancel: false,
  181. success: (res) => {
  182. if (res.confirm) {
  183. uni.navigateTo({
  184. url: "/pages/my_orderlist/my_orderlist?Inv=2"
  185. })
  186. }
  187. }
  188. });
  189. } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
  190. uni.showToast({
  191. title: '支付取消',
  192. icon: 'success'
  193. });
  194. } else {
  195. uni.showModal({
  196. title: '提示',
  197. content: res.errMsg,
  198. showCancel: false
  199. })
  200. }
  201. });
  202. }
  203. },
  204. /**
  205. * 获取用户信息
  206. */
  207. getUserInfo() {
  208. var that = this
  209. var tempCardNumber = that.$utils.getEncryptedData('cardNumber')
  210. if (that.$utils.isEmpty(tempCardNumber)) {
  211. uni.showToast({
  212. title: '用户卡号为空'
  213. });
  214. return;
  215. }
  216. that.cardNumber = tempCardNumber;
  217. that.$myRequest({
  218. url: '/hotelReservation/zhotel/appuser.action?card_number=' + that.cardNumber
  219. }).then(res => {
  220. // console.log(res);
  221. let data = res.data.data
  222. if (res.data.code === 200) {
  223. that.cardName = data.user_name
  224. that.cardPhone = data.user_phone
  225. if (data.identity_type === 0) {
  226. that.cardIdentity = '其它'
  227. } else if (data.identity_type === 1) {
  228. that.cardIdentity = '学生'
  229. } else if (data.identity_type === 4) {
  230. that.cardIdentity = '教职工'
  231. } else if (data.identity_type === 5) {
  232. that.cardIdentity = '校友'
  233. } else if (data.identity_type === 6) {
  234. that.cardIdentity = '访客'
  235. } else {
  236. that.cardIdentity = '临时人员'
  237. }
  238. } else {
  239. alert('未获得用户数据')
  240. }
  241. });
  242. },
  243. /**
  244. * 提交订单
  245. */
  246. getOrderSubmit() {
  247. let that = this
  248. that.$myRequest({
  249. method: 'POST',
  250. url: '/hotelReservation/zhotel/apporder_pay.action',
  251. data: {
  252. 'card_number': that.cardNumber,
  253. 'h_type': that.h_type,
  254. 'live_time': that.startDate.substring(0, 10),
  255. 'end_time': that.endDate.substring(0, 10)
  256. },
  257. headers: {
  258. 'Content-Type': 'application/json'
  259. }
  260. }).then(res => {
  261. let data = res.data
  262. if (data.code === 200) {
  263. let d = data.data;
  264. that.payData = {
  265. "appId": d.appId,
  266. "nonceStr": d.nonceStr,
  267. "paySign": d.paySign,
  268. "package": "prepay_id=" + d.prepay_id,
  269. "signType": d.signType,
  270. "timeStamp": d.timeStamp
  271. }
  272. if (typeof WeixinJSBridge === 'undefined') {
  273. if (document.addEventListener) {
  274. document.addEventListener('WeixinJSBridgeReady', that.onBridgeReady, false);
  275. } else if (document.attachEvent) {
  276. document.attachEvent('WeixinJSBridgeReady', that.onBridgeReady);
  277. document.attachEvent('onWeixinJSBridgeReady', ththatis.onBridgeReady);
  278. }
  279. } else {
  280. that.onBridgeReady();
  281. }
  282. } else {
  283. that.msgType = 'warn'
  284. that.order_txt = data.message
  285. that.$refs.popup_order.open()
  286. }
  287. });
  288. },
  289. dialogConfirm() {
  290. uni.showToast({
  291. title: '确定'
  292. })
  293. },
  294. //日历选择器
  295. openCalendar() {
  296. // this.$refs.popup_picker.open()
  297. },
  298. // 重新选择日期
  299. change(e) {
  300. // console.log('1change 返回:', e)
  301. // 模拟动态打卡
  302. // if (this.info.selected.length > 5) return
  303. var before = e.range.before;
  304. var after = e.range.after;
  305. this.info.selected = [{
  306. date: before,
  307. info: '到店'
  308. },
  309. {
  310. date: after,
  311. info: '离店'
  312. }
  313. ];
  314. if (before !== '' && after === '') {
  315. this.startWeek = '周' + e.lunar.ncWeek.substring(2, 3)
  316. } else if (before !== '' && after !== '') {
  317. if ((new Date(after).getTime()) == (new Date(before).getTime())) {
  318. uni.showToast({
  319. title: '不能选同一天',
  320. icon: 'error',
  321. duration: 1500
  322. });
  323. return;
  324. }
  325. this.endWeek = '周' + e.lunar.ncWeek.substring(2, 3);
  326. if ((new Date(after).getTime()) < (new Date(before).getTime())) {
  327. var temp = before;
  328. before = after;
  329. after = temp;
  330. var tmp = this.startWeek;
  331. this.startWeek = this.endWeek;
  332. this.endWeek = tmp;
  333. }
  334. this.startTime = before.substring(5, 7) + '月' + before.substring(8, 10) + '日'
  335. this.endTime = after.substring(5, 7) + '月' + after.substring(8, 10) + '日'
  336. this.startDate = before + ' 14:00:00'
  337. this.endDate = after + ' 12:00:00'
  338. this.ruzhu_num = parseInt(((new Date(after).getTime()) - (new Date(before).getTime())) / 1000 / 60 / 60 / 24)
  339. this.payMount = this.ruzhu_num * this.price
  340. }
  341. },
  342. //选择器
  343. bindPickerChange: function(e) {
  344. console.log('picker发送选择改变,携带值为', e.detail.value)
  345. this.index = e.detail.value
  346. this.mayTime = this.startDate.substring(0, 11) + this.array[this.index].substring(0, 5) + ":00"
  347. // console.log(this.mayTime)
  348. },
  349. // 输入框
  350. bindTextAreaBlur: function(e) {
  351. // console.log(e.detail.cursor)
  352. // console.log(e.detail.value)
  353. this.textNum = e.detail.cursor
  354. this.remark = e.detail.value
  355. }
  356. }
  357. }
  358. </script>
  359. <style>
  360. @import url("./css/order_room.css");
  361. </style>