index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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" v-if="item.qtyShowFlag && item.qtyShowFlag == 1">剩余{{item.currentQty}}{{item.unitType}}</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;color:#999">
  23. <view>使用{{item.qty}}</view>
  24. <view>{{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=='loading'" :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. uni.setNavigationBarTitle({
  71. title: opts.bundleName
  72. })
  73. // 监听整改完成后刷新事件
  74. uni.$on('refreshBL',this.getRow)
  75. this.getRow(1)
  76. },
  77. onUnload() {
  78. uni.$off('refreshBL',this.getRow)
  79. },
  80. methods:{
  81. // tabs通知swiper切换
  82. tabsChange(index) {
  83. this.swiperCurrent = index;
  84. },
  85. swiperChange(event){
  86. this.action = 'swiperChange'
  87. this.status = 'loading'
  88. },
  89. // swiper-item左右移动,通知tabs的滑块跟随移动
  90. transition(e) {
  91. let dx = e.detail.dx;
  92. this.$refs.uTabs.setDx(dx);
  93. },
  94. // 由于swiper的内部机制问题,快速切换swiper不会触发dx的连续变化,需要在结束时重置状态
  95. // swiper滑动结束,分别设置tabs和swiper的状态
  96. animationfinish(e) {
  97. let current = e.detail.current;
  98. let isCurtab = this.current == current
  99. if(this.status!="nomore"){
  100. let loadData = this.action == 'swiperChange' ? !isCurtab : isCurtab;
  101. if(loadData){
  102. this.$refs.uTabs.setFinishCurrent(current);
  103. this.swiperCurrent = current;
  104. this.current = current;
  105. this.resetPage();
  106. }
  107. }
  108. },
  109. // scroll-view到底部加载更多
  110. onreachBottom() {
  111. this.action = 'onreachBottom'
  112. if(this.list.length < this.total){
  113. this.resetPage()
  114. }else{
  115. this.status = "nomore"
  116. }
  117. },
  118. // 查询列表
  119. getRow (pageNo) {
  120. if (pageNo) {
  121. this.pageNo = pageNo
  122. }
  123. let params = {
  124. pageNo: this.pageNo,
  125. pageSize: this.pageSize,
  126. customerBundleId: this.customerBundleId, // tab分类
  127. }
  128. const url = [getCustomerBundleDetail,getCustomerUseHistory]
  129. this.status = "loading"
  130. url[this.current](params).then(res => {
  131. if (res.status == 200) {
  132. if(this.pageNo>1){
  133. this.list = this.list.concat(res.data.list || [])
  134. }else{
  135. this.list = res.data.list || []
  136. }
  137. this.total = res.data.count || 0
  138. } else {
  139. this.list = []
  140. this.total = 0
  141. this.noDataText = res.message
  142. }
  143. if(this.list.length<this.total){
  144. this.status = "loadmore"
  145. }else{
  146. this.status = "nomore"
  147. }
  148. })
  149. },
  150. resetPage(){
  151. this.status = 'loading';
  152. // 上划分页
  153. if(this.action == 'onreachBottom'){
  154. this.pageNo += 1
  155. this.getRow()
  156. }
  157. // 左右切换tab
  158. if(this.action == 'swiperChange'){
  159. this.list = [];
  160. this.getRow(1);
  161. }
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. page {
  168. height: 100%;
  169. }
  170. .pagesCons{
  171. height: 100%;
  172. display: flex;
  173. flex-direction: column;
  174. .text-right {
  175. text-align: right;
  176. }
  177. .utabs{
  178. border-bottom: 1px solid #eee;
  179. }
  180. .check-list{
  181. flex: 1;
  182. .swiper-item{
  183. width: 100%;
  184. height: 100%;
  185. overflow: hidden;
  186. .scroll-view {
  187. width: 100%;
  188. height: 100%;
  189. overflow: auto;
  190. }
  191. }
  192. }
  193. // 列表样式
  194. .check-order-list{
  195. background: #ffffff;
  196. border-bottom: 1px solid #eee;
  197. padding: 1em;
  198. &:active{
  199. background: #f8f8f8;
  200. }
  201. .l_box{
  202. font-size: 1em;
  203. flex: 2;
  204. }
  205. .r_box{
  206. color: #999;
  207. justify-content: flex-end;
  208. text-align: right;
  209. flex: 1;
  210. > view{
  211. padding: 0 0.1em;
  212. }
  213. }
  214. }
  215. }
  216. </style>