<template>
  <view>
    <custom-nav-bar position="fixed" color="black" :left-text="option.name" left-arrow />

    <view class="law-list">
      <view class="law-list-line flex flex-v-center flex-between" :data-item="item" @tap="headleDetails"
        v-for="(item, index) in lawsRegulationList" :key="index">
        <view class="line-name flex1">{{ item.title }}</view>

        <image class="line-you" src="/static/images/ic-you.png"></image>
      </view>
    </view>
  </view>
</template>

<script>
  // const app = getApp();
  // const {
  //   peopleApi
  // } = app.globalData.api;
  import * as peopleApi from '@/api/peopleApi';
  import * as publicApi from '@/api/publicApi';
  export default {
    data() {
      return {
        option: {
          name: ''
        },

        // 页面传递数据
        lawsRegulationList: [],

        pageNo: 1,
        pageSize: 10,
        total: 0
      };
    },
    onLoad(option) {
      this.option = option
      this.lawsRegulationPageApi();
    },
    onReachBottom() {
      if (this.lawsRegulationList.length === this.total) {
        return;
      }
      this.mediatorPageApi(false);
    },
    methods: {
      /**
       * 接口
       */
      async lawsRegulationPageApi(reset = true) {
        const params = this.generalQueryData(reset);
        const res = await peopleApi.lawsRegulationPageApi(params);
        let _goodsList = []
        if (res.data) {
          const {
            list = [], total = 0
          } = res.data;
          if (reset) {
            _goodsList = list;
          } else {
            _goodsList = this.lawsRegulationList.concat(list);
          }
          this.pageNo = params.pageNo || 1;
          this.total = total;
          this.lawsRegulationList = _goodsList
        }
      },

      /**
       * 页面事件
       */
      // 分页参数处理事件
      generalQueryData(reset = false) {
        const {
          pageNo,
          pageSize,
          option
        } = this;
        const params = {
          pageNo: 1,
          pageSize: 10
        };
        if (option.categoryId) {
          params.categoryId = option.categoryId;
        }
        if (reset) {
          return params;
        }
        return {
          ...params,
          pageNo: pageNo + 1,
          pageSize
        };
      },

      headleDetails(event) {
        const {
          id
        } = event.currentTarget.dataset.item;
        uni.navigateTo({
          url: `/packages/public/pages/details/details?name=法律详情&referId=${id}`
        });
      }
    }
  };
</script>
<style lang="less">
  .law-list {
    margin-top: 32rpx;
    width: 100%;
    height: 100%;
    padding: 0 40rpx;

    .law-list-line {
      height: 98rpx;
      border-bottom: 1px solid #efefef;

      .line-name {
        font-size: 32rpx;
        font-weight: 400;
        color: #333333;
        line-height: 34rpx;
      }

      .line-you {
        width: 32rpx;
        height: 32rpx;
      }
    }
  }
</style>