Procházet zdrojové kódy

更新 分页逻辑

wzh před 3 roky
rodič
revize
7abfd2039f

+ 23 - 13
miniprogram/components/voyages/voyages.js

@@ -16,10 +16,10 @@ Component({
     size: 20,
     list: [],
     total: 0,
-    cargoOwnerId:0
+    cargoOwnerId: 0
   },
   methods: {
-    async getVoyageList() {
+    async getVoyageList(isScroll) {
       let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
       if (!cargoOwnerId) {
         this.setData({
@@ -57,7 +57,7 @@ Component({
           total: 1
         })
         return
-      }else{
+      } else {
         this.setData({
           cargoOwnerId
         })
@@ -69,15 +69,26 @@ Component({
         currentPage: this.data.currentPage,
         size: this.data.size
       })
+      this.setData({
+        currentPage: this.data.currentPage
+      })
       if (res.data.status == 0) {
-        this.setData({
-          list: res.data.result,
-          total: res.data.total
-        })
+        if (isScroll) {
+          this.setData({
+            list: [...this.data.list, ...res.data.result],
+            total: res.data.total
+          })
+        } else {
+          this.setData({
+            list: res.data.result,
+            total: res.data.total
+          })
+        }
+
       } else {
-        this.setData({
-          list: [],
-          total: 0,
+        wx.showToast({
+          icon: "none",
+          title: res.data.msg,
         })
       }
     },
@@ -95,7 +106,6 @@ Component({
     },
     goToDetail(e) {
       let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
-
       if (!cargoOwnerId) {
         wx.showToast({
           icon: "none",
@@ -111,9 +121,9 @@ Component({
       })
     },
     scrollList() {
-      if (this.data.total == 0 || this.data.total < this.data.size * this.data.currentPage) return
+      if (this.data.total == 0 || this.data.total <= this.data.size * this.data.currentPage) return
       this.data.currentPage += 1
-      this.getVoyageList()
+      this.getVoyageList(true)
     }
   }
 })

+ 1 - 1
miniprogram/pages/index/index.js

@@ -19,7 +19,7 @@ Page({
   forbidTouchMove() {
 
   },
-  onShow() {
+  onLoad() {
     let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
     if (cargoOwnerId) {
       this.getIndexInfo()

+ 58 - 26
miniprogram/pages/voyages/detail/detail.js

@@ -6,8 +6,8 @@ Page({
   data: {
     id: '',
     tab: 1,
-    recordCurrentPage: 1,
-    dischargeCurrentPage: 1,
+    shipDischargeCurrentPage: 1,
+    truckLoadCurrentPage: 1,
     coordinates: [],
     medias: [],
     policys: [],
@@ -16,7 +16,10 @@ Page({
     infoType: 'ship',
     shipDischargeList: [],
     truckLoadList: [],
-    polyline: {}
+    shipDischargeTotal: 0,
+    truckLoadTotal: 0,
+    polyline: {},
+    pageSize: 20
   },
   changeTab(e) {
     let {
@@ -49,7 +52,8 @@ Page({
     }
     let polyline = {
       points,
-      color: "#ff454d"
+      color: "#ff454d",
+      width: 50
     }
     this.setData({
       coordinates,
@@ -62,27 +66,30 @@ Page({
   },
 
   async getCarLoadRecordList(isScroll) {
+    if (this.data.truckLoadTotal != 0 && this.data.truckLoadTotal < this.data.pageSize * this.data.truckLoadCurrentPage) return
     if (isScroll) {
-      this.data.recordCurrentPage += 1
+      this.data.truckLoadCurrentPage += 1
     } else {
-      this.data.recordCurrentPage = 1
+      this.data.truckLoadCurrentPage = 1
     }
     let res = await postApi("/voyage/getCarLoadRecordList", {
       voyageId: this.data.id,
-      size: 50,
-      currentPage: this.data.recordCurrentPage
+      size: this.data.pageSize,
+      currentPage: this.data.truckLoadCurrentPage
+    })
+    this.setData({
+      truckLoadCurrentPage: this.data.truckLoadCurrentPage,
     })
 
     if (0 == res.data.status) {
       if (isScroll) {
-
-
         let truckLoadList = [...this.data.truckLoadList, ...res.data.result]
         for (let i of truckLoadList) {
           i.weighTime = this.cutTimeString(i.weighTime)
         }
         this.setData({
-          truckLoadList
+          truckLoadList,
+          truckLoadTotal: res.data.total
         })
       } else {
         let truckLoadList = res.data.result
@@ -91,51 +98,56 @@ Page({
           i.weighTime = this.cutTimeString(i.weighTime)
         }
         this.setData({
-          truckLoadList
+          truckLoadList,
+          truckLoadTotal: res.data.total
         })
       }
     } else {
-      this.setData({
-        truckLoadList: []
+      wx.showToast({
+        icon: 'none',
+        title: res.data.msg,
       })
     }
   },
 
   async getDischargeList(isScroll) {
     if (isScroll) {
-      this.data.dischargeCurrentPage += 1
+      this.data.shipDischargeCurrentPage += 1
     } else {
-      this.data.dischargeCurrentPage = 1
+      this.data.shipDischargeCurrentPage = 1
     }
     let res = await postApi("/voyage/getDischargeList", {
       voyageId: this.data.id,
-      size: 50,
-      currentPage: this.data.dischargeCurrentPage
+      size: this.data.pageSize,
+      currentPage: this.data.shipDischargeCurrentPage
+    })
+    this.setData({
+      shipDischargeCurrentPage: this.data.shipDischargeCurrentPage,
     })
-
     if (0 == res.data.status) {
       if (isScroll) {
-
         let shipDischargeList = [...this.data.shipDischargeList, ...res.data.result]
         for (let i of shipDischargeList) {
           i.dischargeTime = this.cutTimeString(i.dischargeTime)
         }
         this.setData({
-          shipDischargeList
+          shipDischargeList,
+          shipDischargeTotal: res.data.total
         })
       } else {
-
         let shipDischargeList = res.data.result
         for (let i of shipDischargeList) {
           i.dischargeTime = this.cutTimeString(i.dischargeTime)
         }
         this.setData({
-          shipDischargeList
+          shipDischargeList,
+          shipDischargeTotal: res.data.total
         })
       }
     } else {
-      this.setData({
-        shipDischargeList: []
+      wx.showToast({
+        icon: "none",
+        title: res.data.msg,
       })
     }
 
@@ -156,8 +168,19 @@ Page({
       type
     } = e.currentTarget.dataset
     this.setData({
-      infoType: type
+      infoType: type,
+      truckLoadCurrentPage: 1,
+      shipDischargeCurrentPage: 1,
+      shipDischargeList: [],
+      truckLoadList: [],
+      shipDischargeTotal: 0,
+      truckLoadTotal: 0,
     })
+    if (type == "ship") {
+      this.getDischargeList()
+    } else {
+      this.getCarLoadRecordList()
+    }
   },
 
   cutTimeString(str) {
@@ -173,6 +196,15 @@ Page({
     }
   },
 
+  scrollShip() {
+    if (this.data.shipDischargeTotal == 0 || this.data.shipDischargeTotal <= this.data.pageSize * this.data.shipDischargeCurrentPage) return
+    this.getDischargeList(true)
+  },
+  scrollTruck() {
+    if (this.data.truckLoadTotal == 0 || this.data.truckLoadTotal <= this.data.pageSize * this.data.truckLoadCurrentPage) return
+    this.getCarLoadRecordList(true)
+  },
+
 
   onLoad(options) {
     this.setData({

+ 7 - 5
miniprogram/pages/voyages/detail/detail.wxml

@@ -1,4 +1,4 @@
-<map polyline="{{polyline}}" style="width: 100%;height: 400rpx;" name="map"></map>
+<map scale="8" latitude="31.923534" longitude="120.551381" polyline="{{polyline}}" style="width: 100%;height: 400rpx;" name="map"></map>
 <view class="df aic jcsb p20" style="border-bottom: 1px solid #999;border-top: 1px solid #999;">
   <view class="tabsview" bindtap="changeTab" data-tab="{{1}}" style="color:{{tab==1?'#0d8fcc':''}};border-bottom:{{tab==1?'2rpx solid #0d8fcc':''}}">航次信息</view>
   <view class="tabsview" bindtap="changeTab" data-tab="{{2}}" style="color:{{tab==2?'#0d8fcc':''}};border-bottom:{{tab==2?'2rpx solid #0d8fcc':''}}">航次详情</view>
@@ -126,22 +126,23 @@
       <view bindtap="changeInfoType" data-type="truck" style="color:{{infoType=='truck'?'#0d8fcc':''}};border-bottom:{{infoType=='truck'?'2rpx solid #0d8fcc':''}}">汽车装货记录</view>
     </view>
     <view class="ship-discharge-list" wx:if="{{infoType=='ship'}}">
-      <view class="df aic jcsb mb20 mt10 fz20">
+      <view class="df aic jcsb mb20 mt10 fz22">
         <view>卸货时间</view>
         <view>卸货吨位</view>
         <view>卸货件数</view>
         <view>磅单</view>
       </view>
-      <view wx:for="{{shipDischargeList}}" wx:key="index" class="df aic jcsb mb20 fz20">
+      <view wx:for="{{shipDischargeList}}" wx:key="index" class="df aic jcsb mb20 fz22">
         <view>{{item.dischargeTime}}</view>
         <view>{{item.dischargeTons||''}}</view>
         <view>{{item.dischargePieces||''}}</view>
         <view wx:if="{{item.files&&item.files.length}}" bindtap="previewImage" data-src="{{item.files[0].viewUrl}}" data-files="{{item.files}}">查看</view>
         <view wx:else>暂无</view>
       </view>
+      <view bindtap="scrollShip" class="bottom-text">{{shipDischargeTotal==0?'暂无数据':(shipDischargeTotal>pageSize*shipDischargeCurrentPage?'点击或滑动加载更多...':'已加载完毕')}}</view>
     </view>
     <view class="truck-load-list" wx:if="{{infoType=='truck'}}">
-      <view class="df aic jcsb mb20 mt10 fz20">
+      <view class="df aic jcsb mb20 mt10 fz22">
         <view>车号</view>
         <view>毛重</view>
         <view>皮重</view>
@@ -149,7 +150,7 @@
         <view>称重时间</view>
         <view>单据</view>
       </view>
-      <view wx:for="{{truckLoadList}}" wx:key="index" class="df aic jcsb mb20 fz20">
+      <view wx:for="{{truckLoadList}}" wx:key="index" class="df aic jcsb mb20 fz22">
         <view>{{item.carNum}}</view>
         <view>{{item.grossWeight}}</view>
         <view>{{item.tare}}</view>
@@ -158,6 +159,7 @@
         <view wx:if="{{item.file}}" bindtap="previewImage" data-src="{{item.file.viewUrl}}">查看</view>
         <view wx:else>暂无</view>
       </view>
+      <view bindtap="scrollTruck" class="bottom-text">{{truckLoadTotal==0?'暂无数据':(truckLoadTotal>pageSize*truckLoadCurrentPage?'点击或滑动加载更多...':'已加载完毕')}}</view>
     </view>
   </view>
   <view wx:if="{{tab==5}}">