order_room.vue 11 KB

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