<template>
  <div class="corePersonnel">
    <head-form
      title="裁判文书"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="false"
      @handle-search="handleSearch"
    />

    <tables
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
    >
      <template slot="relatedCompanies" slot-scope="scope">
        <div v-for="item in scope.row.relatedCompanies">
          <span>{{ item.clean_role }}：</span>{{ item.name }}
        </div>
      </template>
    </tables>


  </div>
</template>

<script>
import {
  lawsuitsPage,
  lawsuitsCauseAction,
  lawsuitsRole
} from '@/api/detail/party-a/riskInformation'
import mixin from '../mixins/mixin'
export default {
  name: 'Judgment',
  mixins: [mixin],
  components: {

  },
  props: {
    companyId: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,//5504335
        pageNum: 1,
        pageSize: 10
      },
      forData: [
        {label: '案由', prop: 'causeAction', width: '240'},
        {label: '执行案号', prop: 'causeNo', width: '210'},
        {label: '身份', prop: 'role', width: '120'},
        {label: '当事人', prop: 'relatedCompanies', width: '240', slot: true},
        {label: '案件金额（元）', prop: 'subAmount', width: '140'},
        {label: '判决结果', prop: 'judgeresult', width: '508'},
        {label: '判决日期', prop: 'date', width: '95'},
      ],
      formData: [
        { type: 1, fieldName: 'causeAction', value: '', placeholder: '案由', options: []},
        { type: 1, fieldName: 'role', value: '', placeholder: '身份', options: []},
        { type: 2, fieldName: 'time', value: '', placeholder: '',startTime: 'dateFrom',endTime: 'dateTo'},
        { type: 3, fieldName: 'keys', value: '', placeholder: '搜索关键字'}
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
    }
  },
  created() {
    this.handleQuery()
    this.lawsuitsCauseActions()
    this.lawsuitsRoles()
  },
  computed: {

  },
  methods: {
    handleQuery(params) {
      let data = params ? params : this.queryParams
      this.tableLoading = true
      lawsuitsPage(data).then(res => {
        this.tableData = res.rows
        for (var i=0;i<this.tableData.length;i++){
          this.tableData[i].relatedCompanies = JSON.parse(this.tableData[i].relatedCompanies)
        }
        this.tableDataTotal = res.total
        this.tableLoading = false
      })
    },
    lawsuitsCauseActions(){
      lawsuitsCauseAction({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].causeAction + '（' + data[i].num + '）',
              value: data[i].causeAction,
            })
          }
        }
      })
    },
    lawsuitsRoles(){
      lawsuitsRole({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].num + '）',
              value: data[i].role,
            })
          }
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.corePersonnel{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .query-box{
    margin: 10px 0 20px;
  }
}
</style>
