order_room.vue 11 KB

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