<template>
  <div class="corePersonnel judicial-document">
    <head-form-new 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', align: "right" },
        { label: '判决结果', prop: 'judgeresult', width: '508' },
        { label: '判决日期', prop: 'date', width: '95' },
      ],
      formData: [
        { type: 1, fieldName: 'causeAction', 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() },
        { type: 3, fieldName: 'keys', value: '', placeholder: '请输入执行案号', uid: this.getUid() }
      ],
      //列表
      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;
  }
}

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