index.vue 5.8 KB

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