<template>
  <div class="corePersonnel court-announcement">
    <head-form-new title="法院公告" :form-data="formData" :query-params="queryParams" :total="tableDataTotal" :isExcel="true"
      @handle-search="handleSearch" />
    <skeleton v-if="isSkeleton" style="padding: 16px"></skeleton>
    <tables v-if="!isSkeleton" :tableData="tableData" :forData="forData" :tableDataTotal="tableDataTotal" :queryParams="queryParams"
      @handle-current-change="handleCurrentChange" />

  </div>
</template>

<script>
import {
  noticesPage,
  noticesType,
  noticesRole,
  noticesCaseReason
} from '@/api/detail/party-a/riskInformation';
import mixin from '../mixins/mixin';
import skeleton from '../component/skeleton';
export default {
  name: 'CourtNotice',
  mixins: [mixin],
  components: {
    skeleton
  },
  props: ['companyId'],
  data() {
    return {
      queryParams: {
        cid: this.companyId, //20734
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        { label: '案由', prop: 'caseReason' },
        { label: '公告时间', prop: 'date', width: '95' },
        { label: '当事人', prop: 'people', width: '240' },
        { label: '公告类型', prop: 'type', width: '210' },
        { label: '公告法院', prop: 'court', width: '280' }
      ],
      formData: [
        { type: 1, fieldName: 'type', value: '', placeholder: '公告类型', options: [], uid: this.getUid() },
        { type: 1, fieldName: 'caseReason', value: '', placeholder: '案由', options: [], uid: this.getUid() },
        { type: 1, fieldName: 'role', value: '', placeholder: '身份', options: [], uid: this.getUid() },
        { type: 2, fieldName: 'time', value: '', placeholder: '', startTime: 'dateFrom', endTime: 'dateTo', uid: this.getUid() }
      ],
      //列表
      tableLoading: false,
      tableData: [],
      tableDataTotal: 0,
      isSkeleton: true
    };
  },
  created() {
    this.handleQuery();
    this.noticesTypes();
    this.noticesRoles();
    this.noticesCaseReasons();
  },
  computed: {

  },
  methods: {
    handleQuery(params) {
      let data = params ? params : this.queryParams;
      this.isSkeleton = true;
      noticesPage(data).then(res => {
        this.tableData = res.rows;
        this.tableDataTotal = res.total;
        this.isSkeleton = false;
      });
    },
    // 公告
    noticesTypes() {
      noticesType({ cid: this.queryParams.cid }).then(res => {
        let data = res.data;
        if (data.length > 0) {
          for (var i = 0; i < data.length; i++) {
            this.formData[0].options.push({
              name: data[i].type + '（' + data[i].count + '）',
              value: data[i].type,
            });
          }
        }
      });
    },
    // 身份
    noticesRoles() {
      noticesRole({ cid: this.queryParams.cid }).then(res => {
        let data = res.data;
        if (data.length > 0) {
          for (var i = 0; i < data.length; i++) {
            this.formData[2].options.push({
              name: data[i].role + '（' + data[i].count + '）',
              value: data[i].role,
            });
          }
        }
      });
    },
    // 案由
    noticesCaseReasons() {
      noticesCaseReason({ cid: this.queryParams.cid }).then(res => {
        let data = res.data;
        if (data.length > 0) {
          for (var i = 0; i < data.length; i++) {
            this.formData[1].options.push({
              name: data[i].caseReason + '（' + data[i].count + '）',
              value: data[i].caseReason,
            });
          }
        }
      });
    },

  }
}
</script>
<style lang="scss" scoped>
.corePersonnel {
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .query-box {
    margin: 10px 0 20px;
  }
}

.court-announcement {
  @import "@/assets/styles/search-common.scss";
}
</style>
