my_orderlist.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="content">
  3. <!-- 切换栏 -->
  4. <scroll-view :scroll-x="true" class="inv-h-w">
  5. <view :class="['inv-h',Inv==6?'inv-h-se':'']" @click="changeTab(6)">全部</view>
  6. <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="changeTab(1)">待支付</view>
  7. <view :class="['inv-h',Inv==2?'inv-h-se':'']" @click="changeTab(2)">待入住</view>
  8. <view :class="['inv-h',Inv==3?'inv-h-se':'']" @click="changeTab(3)">已入住</view>
  9. <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="changeTab(0)">已取消</view>
  10. <view :class="['inv-h',Inv==4?'inv-h-se':'']" @click="changeTab(4)">待结账</view>
  11. <view :class="['inv-h',Inv==5?'inv-h-se':'']" @click="changeTab(5)">已完成</view>
  12. </scroll-view>
  13. <!-- 订单样式 -->
  14. <view class="room-kuang">
  15. <view class="room-xinxi" v-for="(item,index) in troom" :key="index">
  16. <view @click="navigateToOrderMark(item.id)">
  17. <image class="room-image" :src="item.roomTypeMasterImg"></image>
  18. <view class="room-name">{{item.roomTypeName}}</view>
  19. <view class="room-time">{{item.enableStartTime|snippet}}-{{item.enableEndTime|snippet}}</view>
  20. <view class="room-order">订单号:{{item.id}}</view>
  21. <view class="room-type">
  22. <text v-if="item.orderStatu==0">已取消</text>
  23. <text v-if="item.orderStatu==1">待支付</text>
  24. <text v-if="item.orderStatu==2">待入住</text>
  25. <text v-if="item.orderStatu==3">已入住</text>
  26. <text v-if="item.orderStatu==4">
  27. 待结账
  28. </text>
  29. <text v-if="item.orderStatu==5">已完成</text>
  30. </view>
  31. <view class="room-price">¥{{item.payAmount}}</view>
  32. </view>
  33. <uni-countdown v-if="item.orderStatu == 1" class="room-count" color="#FF5733" :show-day="false" :second="timeupSecond" @timeup="timeup(item.createTime)" />
  34. <text v-if="item.orderStatu == 1" class="room-count-txt">之后取消</text>
  35. <view class="room-button" v-if="item.orderStatu != 4 && item.orderStatu != 2 && item.orderStatu != 3">
  36. <text v-if="item.orderStatu == 0" @click="getOrderDelete(item.id)">删除</text>
  37. <text v-if="item.orderStatu == 1" @click="getOrderCancel(item.id)">取消订单</text>
  38. <text v-if="item.orderStatu == 5" @click="getOrderDelete(item.id)">删除</text>
  39. <!-- <text v-if="item.orderStatu == 2">取消订单</text> -->
  40. <!-- <text v-if="item.orderStatu == 3" @click="navigateToXuzhu">续住</text> -->
  41. </view>
  42. <view class="room-button2" :class="{'room-button3': item.orderStatu == 1 || item.orderStatu == 4}">
  43. <text v-if="item.orderStatu == 0" @click="navigateToZaici(item.enableStartTime,item.enableEndTime,item.roomTypeId)">再次预定</text>
  44. <text v-if="item.orderStatu == 1" @click="getOrderPay(item.id)">支付</text>
  45. <text v-if="item.orderStatu == 4" @click="navigateToJiezhang(item.id)">去处理</text>
  46. <text v-if="item.orderStatu == 5" @click="navigateToWanchengZaici()">再次预定</text>
  47. <text v-if="item.orderStatu == 2" @click="getOrderHold(item.id)">办理入住</text>
  48. <text v-if="item.orderStatu == 3" @click="getOrderReturn(item.id)">退房</text>
  49. </view>
  50. <view class="room-line" v-if="index<(troom.length-1)"></view>
  51. </view>
  52. </view>
  53. <!-- 办理续住弹窗 -->
  54. <uni-popup ref="popup_xuzhu" type="dialog" :mask-click="false">
  55. <view class="popup_bg_xu">
  56. <text class="popup_title">办理续住</text>
  57. <text class="popup_error" @click="popupXuzhuClose"></text>
  58. <text class="popup_xu_line"></text>
  59. <!-- 时间选择 -->
  60. <view class="select-time-xu" @click="openXuCalendar">
  61. <view class="select-time-one-xu">
  62. <text class="select-list">周四入住</text>
  63. <text class="select-list-time">07月21日</text>
  64. </view>
  65. <view class="select-center">
  66. <view class="select-line1"></view>
  67. <view class="select-circle">1晚</view>
  68. <view class="select-line2"></view>
  69. </view>
  70. <view class="select-time-one-xu">
  71. <text class="select-list">周五离店</text>
  72. <text class="select-list-time">07月22日</text>
  73. </view>
  74. </view>
  75. <text class="popup_xu_txt">注:办理续住最多7天,如超过7天需要重新预定</text>
  76. <!-- 支付框 -->
  77. <view class="fukuan">
  78. <view class="fu-price"><text style="font-size: 28rpx;">总计:</text>¥20.00</view>
  79. <view class="fu-zhifu">立即支付</view>
  80. </view>
  81. </view>
  82. </uni-popup>
  83. <uni-popup ref="popup_xu" :mask-click="true">
  84. <uni-calendar :selected="infoXu.selected" class="uni-calendar--hook" :clear-date="true" :date="infoXu.date" :insert="infoXu.insert" :lunar="infoXu.lunar" :startDate="infoXu.startDate"
  85. :endDate="infoXu.endDate" :range="infoXu.range" @change="changeXu"/>
  86. </uni-popup>
  87. </view>
  88. </template>
  89. <script>
  90. /**
  91. * 获取任意时间
  92. */
  93. function getDate(date, AddDayCount = 0) {
  94. if (!date) {
  95. date = new Date()
  96. }
  97. if (typeof date !== 'object') {
  98. date = date.replace(/-/g, '/')
  99. }
  100. const dd = new Date(date)
  101. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  102. var a = new Array("日", "一", "二", "三", "四", "五", "六");
  103. var week = new Date().getDay();
  104. var week2 = new Date().getDay()+1;
  105. const y = dd.getFullYear()
  106. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  107. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  108. const h = dd.getHours() < 10 ? '0' + dd.getHours() : dd.getHours()
  109. const f = dd.getMinutes() < 10 ? '0' + dd.getMinutes() : dd.getMinutes()
  110. const s = dd.getSeconds() < 10 ? '0' + dd.getSeconds() : dd.getSeconds()
  111. return {
  112. fullDate: y + '-' + m + '-' + d,
  113. fullDate2: y + '-' + m + '-' + d+' '+h+':'+f+':'+s,
  114. fullTime: m + '月' + d + '日',
  115. year: y,
  116. month: m,
  117. date: d,
  118. day: dd.getDay(),
  119. sWeek:"周"+ a[week],
  120. eWeek:"周"+ a[week2]
  121. }
  122. }
  123. // 导入图片
  124. import room1 from '../../static/index/room_image.svg'
  125. import room2 from '../../static/index/room_image.svg'
  126. export default {
  127. data(){
  128. return {
  129. Inv: 6,
  130. room:[],
  131. troom:[],
  132. timeupSecond:null,
  133. //续住里选择器
  134. infoXu: {
  135. lunar: true,
  136. range: true,
  137. insert: true,
  138. selected: [],
  139. startDate:'',
  140. date:'',
  141. endDate:''
  142. },
  143. }
  144. },
  145. filters:{
  146. //字过长变为...
  147. snippet: function(value) {
  148. if(value.length>=10) {
  149. return value.slice(0, 10);
  150. } else {
  151. return value
  152. }
  153. },
  154. },
  155. onShow() {
  156. // 模拟从后台拿到的数据
  157. var room = []
  158. // list数组中为每一项添加双向绑定的属性---这个属性要在页面显示(onShow)添加
  159. room.forEach(el => el.isChecked = false);
  160. this.room = room;
  161. this.troom = room;//真实数据赋值给页面数据
  162. this.changeTab(this.Inv)
  163. },
  164. onLoad(option) {
  165. this.Inv=option.Inv;
  166. },
  167. /**
  168. * 生命周期函数--监听页面卸载
  169. */
  170. onUnload: function () {
  171. clearInterval(this.timer);
  172. },
  173. mounted(){
  174. },
  175. onReady() {
  176. this.$nextTick(() => {
  177. this.showCalendar = true
  178. })
  179. // TODO 模拟请求异步同步数据
  180. setTimeout(() => {
  181. // console.log('date:'+getDate(new Date()).fullDate)
  182. // console.log('startDate:'+getDate(new Date()).fullDate)
  183. // console.log('endDate:'+getDate(new Date(),6).fullDate)
  184. this.infoXu.date = getDate(new Date()).fullDate
  185. this.infoXu.startDate = getDate(new Date()).fullDate
  186. this.infoXu.endDate = getDate(new Date(),6).fullDate
  187. }, 2000)
  188. },
  189. methods:{
  190. // 订单列表
  191. getOrderPage() {
  192. let _self = this
  193. var Inv2=this.Inv
  194. _self.troom = []
  195. _self.room = []
  196. if (this.Inv==6) {
  197. Inv2=''
  198. }
  199. this.$axios.get("/ihotel/hotelOrder/user/order/page?curPage=1&pageSize=100&statu="+Inv2,
  200. {
  201. headers:{
  202. 'user_token':localStorage.getItem('token')
  203. }
  204. }).then(res => {
  205. res = res.data
  206. if (res.success) {
  207. // console.log(res)
  208. res.data.list.forEach(data => {
  209. _self.troom.push(data)
  210. _self.room.push(data)
  211. })
  212. } else {
  213. console.log('获取订单列表失败')
  214. }
  215. });
  216. },
  217. // 支付订单
  218. getOrderPay(id) {
  219. let _self = this
  220. this.$axios.get(`/ihotel/hotelOrder/user/order/pay/${id}`,
  221. {
  222. headers:{
  223. 'user_token':localStorage.getItem('token')
  224. }
  225. }).then(res => {
  226. res = res.data
  227. if (res.success) {
  228. if(res.data.payAmount==0) {
  229. uni.navigateTo({
  230. url: '../zhifuchenggong/zhifuchenggong?orderId='+res.data.orderId
  231. })
  232. } else {
  233. window.location.href = res.data.payUrl;
  234. }
  235. } else {
  236. alert(res.message)
  237. console.log('支付失败')
  238. }
  239. });
  240. },
  241. // 办理退房
  242. getOrderReturn(id) {
  243. let _self = this
  244. this.$axios.defaults.headers.common['user_token'] = localStorage.getItem('token');
  245. this.$axios.put(`/ihotel/hotelOrder/user/order/return/${id}`,).then(res => {
  246. res = res.data
  247. if (res.success) {
  248. console.log(res)
  249. alert('退房成功')
  250. this.getOrderPage()
  251. } else {
  252. alert(res.message)
  253. }
  254. });
  255. },
  256. // 办理入住
  257. getOrderHold(id) {
  258. let _self = this
  259. this.$axios.defaults.headers.common['user_token'] = localStorage.getItem('token');
  260. this.$axios.put(`/ihotel/hotelOrder/user/order/hold/${id}`,).then(res => {
  261. res = res.data
  262. if (res.success) {
  263. alert('办理入住成功')
  264. this.getOrderPage()
  265. } else {
  266. alert(res.message)
  267. }
  268. });
  269. },
  270. // 删除订单
  271. getOrderDelete(id) {
  272. let _self = this
  273. this.$axios.defaults.headers.common['user_token'] = localStorage.getItem('token');
  274. this.$axios.delete(`/ihotel/hotelOrder/user/order/${id}`,).then(res => {
  275. res = res.data
  276. if (res.success) {
  277. alert('删除订单成功')
  278. this.getOrderPage()
  279. } else {
  280. alert(res.message)
  281. }
  282. });
  283. },
  284. // 待支付取消订单
  285. getOrderCancel(id) {
  286. let _self = this
  287. this.$axios.defaults.headers.common['user_token'] = localStorage.getItem('token');
  288. this.$axios.put(`/ihotel/hotelOrder/user/order/cancel/${id}`,).then(res => {
  289. res = res.data
  290. if (res.success) {
  291. alert('取消成功')
  292. this.getOrderPage()
  293. } else {
  294. alert(res.message)
  295. }
  296. });
  297. },
  298. // 订单取消再次预订
  299. navigateToZaici(enableStartTime,enableEndTime,roomTypeId){
  300. uni.navigateTo({
  301. url:"../order_room/order_room?enableStartTime="+enableStartTime+"&enableEndTime="+enableEndTime+"&startTime="+enableStartTime.substring(5,7)+'月'+enableStartTime.substring(8,10)+'日'+"&endTime="+enableEndTime.substring(5,7)+'月'+enableEndTime.substring(8,10)+'日'+"&roomTypeId="+roomTypeId
  302. })
  303. },
  304. // 订单已完成再次预订
  305. navigateToWanchengZaici(){
  306. uni.navigateBack({
  307. delta:5
  308. })
  309. },
  310. //处理结账
  311. navigateToJiezhang(id) {
  312. uni.navigateTo({
  313. url:"../order_mark/order_mark?orderId="+id
  314. })
  315. },
  316. /*
  317. * @Explain:选项卡点击切换
  318. */
  319. changeTab(Inv) {
  320. console.log(Inv)
  321. var that = this;
  322. this.Inv =Inv
  323. var arr = [];
  324. this.getOrderPage(this.Inv)
  325. that.room.map(item => {//遍历真实数据,拿到所需要的数据放在页面数据tlist中,展示在页面上
  326. if(item.orderStatu == this.Inv){
  327. arr.push(item);
  328. }
  329. })
  330. that.troom = arr;
  331. // if(this.Inv == 6){//获取全部数据
  332. // that.troom = that.room;
  333. // }
  334. //滚动到顶部
  335. uni.pageScrollTo({
  336. duration: 0, //过渡时间必须为0,否则运行到手机会报错
  337. scrollTop: 0 //滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离(如res.top - data.top)
  338. })
  339. },
  340. // 倒计时
  341. timeup(createTime) {
  342. var that = this;
  343. /**setInterval间歇调用 */
  344. that.timer = setInterval(function () {
  345. //订单下单时间
  346. var buy_time = createTime;
  347. //计算剩余下单时间
  348. var time = (new Date(buy_time).getTime() + 10* 60 * 1000) - (new Date().getTime());
  349. if(time>0){
  350. //计算剩余的分钟
  351. var minutes = parseInt(time / 1000 / 60 % 60, 10);
  352. //计算剩余的秒数
  353. var seconds = parseInt(time / 1000 % 60, 10);
  354. that.timeupSecond=parseInt(time / 1000);
  355. // console.log(that.timeupSecond)
  356. //判断分钟和秒数小于10要在前面加个0.
  357. if(minutes<10){
  358. minutes = '0' + minutes;
  359. }
  360. if (seconds < 10) {
  361. seconds = '0' + seconds;
  362. }
  363. var timer = minutes + ":" + seconds;
  364. // that.setData({
  365. // timer: timer
  366. // })
  367. }
  368. }, 1000);
  369. if(that.timeupSecond==0) {
  370. uni.showToast({
  371. title: '时间到'
  372. })
  373. this.getOrderPage()
  374. }
  375. // this.timeupSecond = 0
  376. },
  377. // 跳转到订单详情
  378. navigateToOrderMark(id) {
  379. // console.log(id)
  380. uni.navigateTo({
  381. url: "../order_mark/order_mark?orderId="+id,
  382. })
  383. },
  384. //办理续住弹窗
  385. navigateToXuzhu(){
  386. this.$refs.popup_xuzhu.open()
  387. },
  388. popupXuzhuClose() {
  389. this.$refs.popup_xuzhu.close()
  390. },
  391. // 续住里日期选择器弹窗
  392. openXuCalendar() {
  393. this.$refs.popup_xu.open()
  394. },
  395. changeXu(e) {
  396. console.log('1change 返回:', e)
  397. // 模拟动态打卡
  398. if (this.infoXu.selected.length > 5) return
  399. this.infoXu.selected.push({
  400. date: e.range.before,
  401. info: '到店'
  402. })
  403. this.infoXu.selected.push({
  404. date: e.range.after,
  405. info: '离店'
  406. })
  407. },
  408. },
  409. }
  410. </script>
  411. <style>
  412. @import url(./css/my_orderlist.css);
  413. </style>