index.vue 5.7 KB

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