<template>
  <view class="page">
    <!-- 顶部自定义导航栏 -->
    <customNavbar title="我的租赁资产" />

    <!-- 筛选栏 -->


    <!-- 租赁资产列表组件 -->
    <scroll-view
      scroll-y
      class="scroll-content"
      @scrolltolower="loadMore"
    >
      <asset-list
        :list="assetList"
        @click="goDetail"
      />
    </scroll-view>
  </view>
</template>

<script>
import AssetList from '@/components/asset/assetList.vue'
export default {
  name: 'MyLease',
  components: { AssetList},
  data() {
    return {
      assetList: [],
      pageNo: 1,
      pageSize: 10,
      loadStatus: 'loadmore',
    };
  },
  onLoad(options) {
	this.cusNo = options.cusNo;  
    this.loadAssets();
  },
  onShow() {
  	this.$checkToken(this.$getToken())
  },
  staticHost() {
  	return this.$config.staticUrl
  },
  methods: {
    changeFilter(value) {
      if (this.currentFilter === value) return;
      this.currentFilter = value;
      this.pageNo = 1;
      this.assetList = [];
      this.loadAssets();
    },

    loadAssets() {
      if (this.loadStatus !== 'loadmore') return;
         this.loadStatus = 'loading';
     
         this.$u.post('/assets/getMyAssetsList', {
           pageNo: this.pageNo,
           pageSize: this.pageSize
         },{
			 WT: this.$getToken()
		 }).then(res => {
           const rows = res.data.result || [];
     
           if (this.pageNo === 1) this.assetList = [];
     
           this.assetList = this.assetList.concat(rows);
     
           if (rows.length < this.pageSize) {
             this.loadStatus = 'nomore';
           } else {
             this.pageNo++;
             this.loadStatus = 'loadmore';
           }
         }).catch(err => {
           console.error(err);
           this.loadStatus = 'loadmore';
         });
    },

    loadMore() {
      this.loadAssets();
    },

    goDetail(item) {
      uni.navigateTo({
        url: `/pages-assets/assets/assetsDetail?assetsNo=${item.assetsNo}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #f7f8fa;
  padding-top: 175rpx;
}

.filter-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background-color: #fff;
  padding: 20rpx 0;
  margin-top: var(--custom-navbar-height);
  border-bottom: 1rpx solid #f0f0f0;

  .filter-btn {
    min-width: 150rpx;
    text-align: center;
    font-size: 26rpx;
    height: 60rpx;
    line-height: 60rpx;
    border-radius: 40rpx;
    margin: 0 8rpx;
  }
}

.scroll-content {
  flex: 1;
  height: calc(100vh - 200rpx);
}
</style>