index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="pagesCons">
  3. <view class="utabs">
  4. <u-tabs-swiper ref="uTabs" :list="tabList" name="dispName" :current="current" bar-width="150" active-color="#58c4c4" @change="tabsChange" :is-scroll="false"
  5. swiperWidth="750"></u-tabs-swiper>
  6. </view>
  7. <swiper class="check-list" :current="swiperCurrent" @transition="transition" @change="swiperChange" @animationfinish="animationfinish">
  8. <swiper-item class="swiper-item" v-for="(tabs, index) in tabList" :key="index">
  9. <scroll-view scroll-y class="scroll-view" @scrolltolower="onreachBottom">
  10. <view
  11. class="check-order-list"
  12. v-if="index==current"
  13. v-for="(item,sindex) in list"
  14. :key="item.id+'-'+sindex"
  15. >
  16. <view v-if="current==0" class="flex align_center justify_between">
  17. <view class="l_box">{{item.detailName}}</view>
  18. <view class="r_box">剩余{{item.currentQty}}次</view>
  19. </view>
  20. <view v-if="current==1">
  21. <view class="l_box">{{item.serveName}}</view>
  22. <view class="flex align_center justify_between" style="padding-top: 0.2em;">
  23. <view class="r_box">使用{{item.qty}}次</view>
  24. <view class="r_box">{{item.createDate.split(' ')[0]}}</view>
  25. </view>
  26. </view>
  27. </view>
  28. <view style="padding: 20upx;">
  29. <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
  30. <u-loadmore v-if="list.length" :status="status" />
  31. </view>
  32. </scroll-view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </template>
  37. <script>
  38. import { getCustomerBundleDetail,getCustomerUseHistory } from '@/api/bundel.js'
  39. export default {
  40. components: {
  41. },
  42. data() {
  43. return {
  44. status: 'loadmore',
  45. noDataText: '暂无数据',
  46. tabList: [
  47. {
  48. dispName: '品项明细',
  49. typeId: 1,
  50. queryLabel: 'WAIT_REFORM' // tab参数
  51. },
  52. {
  53. dispName: '使用记录',
  54. typeId: 2,
  55. queryLabel: 'FINISH_REFORM' // tab参数
  56. }
  57. ],
  58. current: 0,
  59. swiperCurrent: 0,
  60. pageNo: 1,
  61. pageSize: 15,
  62. list: [],
  63. total: 0,
  64. action:'swiperChange', // 操作类型,上划分页,或左右滑动
  65. customerBundleId:''
  66. }
  67. },
  68. onLoad(opts) {
  69. this.customerBundleId = opts.customerBundleId
  70. // 监听整改完成后刷新事件
  71. uni.$on('refreshBL',this.getRow)
  72. this.getRow(1)
  73. },
  74. onUnload() {
  75. uni.$off('refreshBL',this.getRow)
  76. },
  77. methods:{
  78. // tabs通知swiper切换
  79. tabsChange(index) {
  80. this.swiperCurrent = index;
  81. },
  82. swiperChange(event){
  83. this.action = 'swiperChange'
  84. this.status = 'loading'
  85. },
  86. // swiper-item左右移动,通知tabs的滑块跟随移动
  87. transition(e) {
  88. let dx = e.detail.dx;
  89. this.$refs.uTabs.setDx(dx);
  90. },
  91. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  92. // swiper滑动结束,分别设置tabs和swiper的状态
  93. animationfinish(e) {
  94. let current = e.detail.current;
  95. let isCurtab = this.current == current
  96. if(this.status!="nomore"){
  97. let loadData = this.action == 'swiperChange' ? !isCurtab : isCurtab;
  98. if(loadData){
  99. this.$refs.uTabs.setFinishCurrent(current);
  100. this.swiperCurrent = current;
  101. this.current = current;
  102. this.resetPage();
  103. }
  104. }
  105. },
  106. // scroll-view到底部加载更多
  107. onreachBottom() {
  108. this.action = 'onreachBottom'
  109. if(this.list.length < this.total){
  110. this.resetPage()
  111. }else{
  112. this.status = "nomore"
  113. }
  114. },
  115. // 查询列表
  116. getRow (pageNo) {
  117. if (pageNo) {
  118. this.pageNo = pageNo
  119. }
  120. let params = {
  121. pageNo: this.pageNo,
  122. pageSize: this.pageSize,
  123. customerBundleId: this.customerBundleId, // tab分类
  124. }
  125. const url = [getCustomerBundleDetail,getCustomerUseHistory]
  126. this.status = "loading"
  127. url[this.current](params).then(res => {
  128. if (res.status == 200) {
  129. if(this.pageNo>1){
  130. this.list = this.list.concat(res.data.list || [])
  131. }else{
  132. this.list = res.data.list || []
  133. }
  134. this.total = res.data.count || 0
  135. } else {
  136. this.list = []
  137. this.total = 0
  138. this.noDataText = res.message
  139. }
  140. if(this.list.length<this.total){
  141. this.status = "loadmore"
  142. }else{
  143. this.status = "nomore"
  144. }
  145. })
  146. },
  147. resetPage(){
  148. this.status = 'loading';
  149. // 上划分页
  150. if(this.action == 'onreachBottom'){
  151. this.pageNo += 1
  152. this.getRow()
  153. }
  154. // 左右切换tab
  155. if(this.action == 'swiperChange'){
  156. this.list = [];
  157. this.getRow(1);
  158. }
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. page {
  165. height: 100%;
  166. }
  167. .pagesCons{
  168. height: 100%;
  169. display: flex;
  170. flex-direction: column;
  171. .text-right {
  172. text-align: right;
  173. }
  174. .utabs{
  175. border-bottom: 1px solid #eee;
  176. }
  177. .check-list{
  178. flex: 1;
  179. .swiper-item{
  180. width: 100%;
  181. height: 100%;
  182. overflow: hidden;
  183. .scroll-view {
  184. width: 100%;
  185. height: 100%;
  186. overflow: auto;
  187. }
  188. }
  189. }
  190. // 列表样式
  191. .check-order-list{
  192. background: #ffffff;
  193. border-bottom: 1px solid #eee;
  194. padding: 1em;
  195. &:active{
  196. background: #f8f8f8;
  197. }
  198. .l_box{
  199. font-size: 1em;
  200. flex-grow: 1;
  201. }
  202. .r_box{
  203. color: #999;
  204. > view{
  205. padding: 0 0.1em;
  206. }
  207. }
  208. }
  209. }
  210. </style>