swiper-list-item.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!-- 在这个文件对每个tab对应的列表进行渲染 -->
  2. <template>
  3. <view class="content">
  4. <!-- :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句,因为默认是允许点击返回顶部的,但是这个页面有多个scroll-view,会全部返回顶部,所以需要控制是当前index才允许点击返回顶部 -->
  5. <!-- 如果当前页已经加载过数据或者当前切换到的tab是当前页,才展示当前页数据(懒加载) -->
  6. <z-paging v-if="firstLoaded || isCurrentPage" ref="paging" v-model="dataList" @query="queryList" :fixed="true">
  7. <!-- 如果希望其他view跟着页面滚动,可以放在z-paging标签内 -->
  8. <view class="" style="overflow-y: scroll !important;height: 94vh;">
  9. <block v-for="(items, indexs) in dataList" :key="indexs" v-if="dataList">
  10. <view class="jie_card" @click="detail(items.id,items.status)">
  11. <view class="jie_card_title">
  12. <text class="jie_card_title_text">借单号:{{items.encoding}}</text>
  13. <text class="jie_tags" v-if="items.purpose===1">教学借单</text>
  14. <text class="jie_tags jie_tags2" v-if="items.purpose===0">科研借单</text>
  15. </view>
  16. <uv-line></uv-line>
  17. <view class="jie_contend">
  18. <view class="jie_contend_text">
  19. <text class="jie_contend_text1">借取人:</text>
  20. <text class="jie_contend_text2">{{items.username}}</text>
  21. </view>
  22. <view class="jie_contend_text">
  23. <text class="jie_contend_text1">联系电话:</text>
  24. <text class="jie_contend_text2">{{items.mobile}}</text>
  25. </view>
  26. <view class="jie_contend_text">
  27. <text class="jie_contend_text1">申请时间:</text>
  28. <text class="jie_contend_text2">{{items.create_time}}</text>
  29. </view>
  30. </view>
  31. <view class="jie_card_ztai" v-if="items.status===6">学院审批</view>
  32. <view class="jie_card_ztai" v-if="items.status===0">待审批</view>
  33. <view class="jie_card_ztai jie_card_ztai2" v-if="items.status===2">待使用</view>
  34. <view class="jie_card_ztai" v-if="items.status===5">已逾期</view>
  35. <view class="jie_card_ztai jie_card_ztai2" v-if="items.status===3">使用中</view>
  36. <view class="jie_card_ztai" v-if="items.status===1">已驳回</view>
  37. <view class="jie_card_ztai" v-if="items.status===7">学院驳回</view>
  38. <view class="jie_card_ztai jie_card_ztai2" v-if="items.status===4">已归还</view>
  39. <view class="jie_card_ztai" v-if="items.status===8">修改配件</view>
  40. </view>
  41. </block>
  42. <view v-else>
  43. <uv-empty text="暂无数据" icon="https://cdn.uviewui.com/uview/empty/list.png"></uv-empty>
  44. </view>
  45. <view style="width: 100%; height: 5vh;"></view>
  46. </view>
  47. </z-paging>
  48. </view>
  49. </template>
  50. <script>
  51. import { requestApi } from '@/api/request.js';
  52. export default {
  53. data() {
  54. return {
  55. // v-model绑定的这个变量不要在分页请求结束中自己赋值!!!
  56. pageNo: 1,
  57. pageSize: 10,
  58. dataList: [],
  59. // 当前组件是否已经加载过了
  60. firstLoaded: false,
  61. // 是否滚动到当前页
  62. isCurrentPage: false
  63. }
  64. },
  65. props:{
  66. // 当前组件的index,也就是当前组件是swiper中的第几个
  67. tabIndex: {
  68. type: Number,
  69. default: function(){
  70. return 0
  71. }
  72. },
  73. // 当前swiper切换到第几个index
  74. currentIndex: {
  75. type: Number,
  76. default: function(){
  77. return 0
  78. }
  79. }
  80. },
  81. watch: {
  82. currentIndex: {
  83. handler(newVal) {
  84. if(newVal === this.tabIndex){
  85. // 懒加载,当滑动到当前的item时,才去加载
  86. if(!this.firstLoaded){
  87. // 这里需要延迟渲染z-paging的原因是为了避免在一些平台上立即渲染可能引发的底层报错问题
  88. this.$nextTick(() => {
  89. setTimeout(() => {
  90. this.isCurrentPage = true;
  91. }, 100);
  92. })
  93. }
  94. }
  95. },
  96. immediate: true
  97. },
  98. },
  99. methods: {
  100. detail(id , status) {
  101. if(this.tabIndex + 1 == 3 && (status ==1 || status == 7 || status == 8) ){
  102. wx.navigateTo({
  103. url: '/pages/teacher/edit?data=' + JSON.stringify(id)
  104. })
  105. }else{
  106. wx.navigateTo({
  107. url: '/pages/index/detail?data=' + JSON.stringify(id)
  108. })
  109. }
  110. },
  111. // 接收父组件传过来的刷新列表要求
  112. reload() {
  113. this.$nextTick(() => {
  114. // 刷新列表数据(如果不希望列表pageNo被重置可以用refresh代替reload方法)
  115. this.$refs.paging && this.$refs.paging.reload();
  116. })
  117. },
  118. async queryList(pageNo, pageSize) {
  119. wx.showLoading({ title: '加载中' });
  120. const params = {
  121. page: pageNo,
  122. limit: pageSize,
  123. type: this.tabIndex + 1
  124. };
  125. await requestApi('index.php/admin/borrow.borrowApp/apply', params).then(res => {
  126. //将请求的结果数组传递给z-paging
  127. this.$refs.paging.complete(res.data.list.data);
  128. console.log(res.data.list.data)
  129. this.firstLoaded = true;
  130. wx.hideLoading();
  131. }).catch(res => {
  132. this.$refs.paging.complete(false);
  133. })
  134. },
  135. itemClick(item) {
  136. console.log('点击了', item.title);
  137. }
  138. }
  139. }
  140. </script>
  141. <style>
  142. /* 注意:父节点需要固定高度,z-paging的height:100%才会生效 */
  143. .content {
  144. height: 100%;
  145. }
  146. .item {
  147. position: relative;
  148. height: 150rpx;
  149. display: flex;
  150. align-items: center;
  151. justify-content: space-between;
  152. padding: 0rpx 30rpx;
  153. }
  154. .item-detail {
  155. padding: 5rpx 15rpx;
  156. border-radius: 10rpx;
  157. font-size: 28rpx;
  158. color: white;
  159. background-color: #007AFF;
  160. }
  161. .item-line {
  162. position: absolute;
  163. bottom: 0rpx;
  164. left: 0rpx;
  165. height: 1px;
  166. width: 100%;
  167. background-color: #eeeeee;
  168. }
  169. </style>