<template>
  <div class="corePersonnel">
    <head-form
      title="裁判文书"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="false"
      @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"
    >
      <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'
import skeleton from '../component/skeleton'
export default {
  name: 'Judgment',
  mixins: [mixin],
  components: {
    skeleton
  },
  props: ['companyId'],
  data() {
    return {
      queryParams: {
        cid: this.companyId,//5504335
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        {label: '案由', prop: 'causeAction'},
        {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,
      isSkeleton:true
    }
  },
  created() {
    this.handleQuery()
    this.lawsuitsCauseActions()
    this.lawsuitsRoles()
  },
  computed: {

  },
  methods: {
    handleQuery(params) {
      let data = params ? params : this.queryParams
      this.isSkeleton = 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.isSkeleton = 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>
