roomconfirm.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="pages roomconfirm">
  3. <view class="search-wrap wrap">
  4. <view class="write-radius search-block">
  5. <input type="text" class="search-input" v-model="searchparams.hotelId" value="" placeholder="酒店ID" />
  6. <input type="text" class="search-input" v-model="searchparams.search" value="" placeholder="订单编号或消费码关键字" />
  7. <button type="primary" @click="searchf" class="search-button">搜索</button>
  8. </view>
  9. </view>
  10. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  11. <!-- // @init="mescrollInit" @down="downCallback" @up="upCallback"为固定值,不可删改(与mescroll-mixins保持一致)
  12. // :down="downOption" :up="upOption" 绝大部分情况无需配置
  13. // :top="顶部偏移量" :bottom="底部偏移量" :topbar="状态栏" :safearea="安全区" (常用)
  14. // 字节跳动小程序 ref="mescrollRef" 必须配置
  15. // 此处支持写入原生组件 -->
  16. <view v-for="(data,index) in dataList" :key="index">
  17. <view class="writeoff-item" :data-id="data.id" @click="jumpDetails">
  18. <view class="writeoff-item-til">{{ data.hotel.title }}</view>
  19. <view class="writeoff-item-con">
  20. <view class="writeoff-item-img">
  21. <image class="image" :src="data.litpic" mode="scaleToFill"></image>
  22. </view>
  23. <view class="writeoff-item-info">
  24. <view class="writeoff-item-name">{{ data.room.title }}</view>
  25. <view class="writeoff-item-hd">
  26. <image class="image" src="/static/img/hotelCardIcon.png" mode="widthFix"></image>
  27. {{data.hd_num}} 张蝴蝶券
  28. </view>
  29. <view class="writeoff-item-time">入离日期: {{data.usedate}} - {{data.departdate}}</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </mescroll-body>
  35. </view>
  36. </template>
  37. <script>
  38. // 引入mescroll-mixins.js
  39. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  40. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  41. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  42. export default {
  43. mixins: [MescrollMixin], // 使用mixin
  44. components: {
  45. MescrollBody
  46. },
  47. onLoad() {
  48. },
  49. onShow() {
  50. let serf = this;
  51. //检查登录,获取token
  52. let loginRes = this.checkLogin('/pages/writeoff/writeoff', '2');
  53. // console.log('loginRes',loginRes);
  54. if(!loginRes){return false;}
  55. serf.params.token=loginRes[0];
  56. serf.searchparams.token=loginRes[0];
  57. // uni.getStorage({
  58. // key: 'token',
  59. // success: function(res) {
  60. // //数据成功获取,用户已登录
  61. // // console.log(res.data);
  62. // serf.params.token=res.data;
  63. // // console.log(serf.params.token);
  64. // },
  65. // fail: function(res) {
  66. // //数据未获取成功,用户没有登录,这里我们直接跳转到登录页面
  67. // uni.navigateTo({
  68. // url: '/pages/login/login',
  69. // });
  70. // }
  71. // });
  72. },
  73. data() {
  74. return {
  75. params:{
  76. token:'',
  77. startTime:'',
  78. endTime:'',
  79. search:'',
  80. hotelId:null,
  81. },
  82. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  83. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  84. downOption: {
  85. // ...
  86. },
  87. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  88. upOption: {
  89. page: {
  90. size: 10 // 每页数据的数量,默认10
  91. },
  92. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  93. empty: {
  94. tip: '暂无相关数据'
  95. }
  96. },
  97. // 列表数据
  98. dataList: [],
  99. //搜索
  100. searchparams:{
  101. token:'',
  102. hotelId:'',
  103. search:'',
  104. }
  105. }
  106. },
  107. methods: {
  108. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  109. mescrollInit(mescroll) {
  110. this.mescroll = mescroll;
  111. },
  112. /*下拉刷新的回调, 有三种处理方式:*/
  113. downCallback(){
  114. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  115. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  116. },
  117. /*上拉加载的回调*/
  118. upCallback(page) {
  119. let pageNum = page.num; // 页码, 默认从1开始
  120. let pageSize = page.size; // 页长, 默认每页10条
  121. this.params = Object.assign(this.params,{page:pageNum,rows:pageSize});
  122. this.$api.http.post(this.config.apiBaseurl+'hotel/reserve/data',this.params,{
  123. header: {
  124. Accept:'application/json',
  125. Authorization: 'Bearer '+ this.params.token, //注意Bearer后面有一空格
  126. }
  127. }).then(data => {
  128. if(data.data.code=='1001'){
  129. uni.redirectTo({
  130. url:'/pages/login/login?backpage=/pages/roomconfirm/roomconfirm'+'&backtype='+2,
  131. });
  132. };
  133. console.log(data);
  134. // 接口返回的当前页数据列表 (数组)
  135. let curPageData = data.data.rows;
  136. console.log('curPageData',curPageData);
  137. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  138. let curPageLen = curPageData.length;
  139. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  140. // let totalPage = data.xxx;
  141. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  142. let totalSize = data.data.total;
  143. // 接口返回的是否有下一页 (true/false)
  144. // let hasNext = data.xxx;
  145. //设置列表数据
  146. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  147. this.dataList = this.dataList.concat(curPageData); //追加新数据
  148. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  149. this.mescroll.endBySize(curPageLen, totalSize);
  150. setTimeout(()=>{
  151. this.mescroll.endSuccess(curPageLen)
  152. },20)
  153. }).catch(err => {
  154. this.mescroll.endErr()
  155. console.log(err)
  156. });
  157. },
  158. //跳转至详情
  159. jumpDetails(e) {
  160. let id = e.currentTarget.dataset.id;
  161. console.log('id',id);
  162. uni.navigateTo({
  163. url: '/pages/roomconfirm/roomconfirmitem/roomconfirmitem?id=' + id
  164. });
  165. },
  166. //搜索
  167. searchf(){
  168. // console.log(this.searchparams);
  169. this.params = this.searchparams;
  170. this.mescroll.resetUpScroll();
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. page{background-color: $uni-bg-color-grey;}
  177. .writeoff-item{margin: 24rpx;padding: 24rpx;border-radius: 24rpx;background-color: #fff;box-shadow: 0px 18px 47px -19px rgba(0, 0, 0, 0.1);}
  178. .writeoff-item-til{margin-bottom: 15rpx;font-size: 24rpx;}
  179. .writeoff-item-con{display: flex;align-items: center;}
  180. .writeoff-item-img{position: relative;margin-right: 24rpx;width: 150rpx;height: 150rpx;border-radius: 14rpx;overflow: hidden;}
  181. .writeoff-item-img .image{height: 100%;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);}
  182. .writeoff-item-info{color: #666;}
  183. .writeoff-item-name{margin-bottom: 4rpx;font-size: 32rpx;font-weight: bold;}
  184. .writeoff-item-hd{margin-bottom: 4rpx;}
  185. .writeoff-item-hd .image{width: 27rpx;height: 21rpx;margin-right: 5rpx;}
  186. .writeoff-item-time{font-size: 24rpx;}
  187. </style>