<template>
  <div class="corePersonnel">
    <head-form
      title="法院公告"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    />

    <tables
      :tableLoading="tableLoading"
      :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'
export default {
  name: 'CourtNotice',
  mixins: [mixin],
  components: {

  },
  props: ['companyId'],
  data() {
    return {
      queryParams: {
        cid: this.companyId, //20734
        pageNum: 1,
        pageSize: 10
      },
      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: []},
        { type: 1, fieldName: 'caseReason', value: '', placeholder: '案由', options: []},
        { type: 1, fieldName: 'role', value: '', placeholder: '身份', options: []},
        { type: 2, fieldName: 'time', value: '', placeholder: '',startTime: 'dateFrom',endTime: 'dateTo'}
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
    }
  },
  created() {
    this.handleQuery()
    this.noticesTypes()
    this.noticesRoles()
    this.noticesCaseReasons()
  },
  computed: {

  },
  methods: {
    handleQuery(params) {
      let data = params ? params : this.queryParams
      this.tableLoading = true
      noticesPage(data).then(res => {
        this.tableData = res.rows
        this.tableDataTotal = res.total
        this.tableLoading = 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[1].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[2].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;
  }
}
</style>
