<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <el-form-item label="审阅时间" prop="approvalTimes">
      <el-date-picker
        v-model="queryParams.approvalTimes"
        type="datetimerange"
        @keyup.enter.native="handleQuery"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期">
      </el-date-picker>
    </el-form-item>
      <el-form-item label="监控人员" prop="monitorByName">
        <el-input
          v-model="queryParams.monitorByName"
          placeholder="请输入监控人员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="风险等级" prop="approvalLevel">
        <el-select
                clearable
                v-model="queryParams.approvalLevel"
                :size="size"
                style="width: 200px"
              >
                <el-option
                  v-for="level in levelTaps"
                  :key="level.value"
                  :label="level.label"
                  :value="level.value"
                >
                </el-option>
              </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <h4><span>   备注： 风险A：风险较高，可能影响合作； 风险B：风险一般，建议人工了解； 风险C：风险较低，不影响继续合作。</span></h4>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业名称" align="center" prop="companyName" />
      <el-table-column label="新企业名称" align="center" prop="newCompanyName" />
      <el-table-column label="企业风险预警" align="center" width="300">
       <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            style="color: red;"
            @click="handleInfo(scope.row)"
          >{{scope.row.riskRemark}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="人工审阅等级" align="center" prop="approvalLevel" />
      <el-table-column label="审阅意见" align="center" prop="approvalRemark" />
      <el-table-column label="审阅人" align="center" prop="approvalByName" />
      <el-table-column label="审阅时间" align="center" prop="approvalTime" />
      <el-table-column label="操作" align="center" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleInfo(scope.row)"
          >已审阅</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--修改合作企业对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="companyName">
          <el-input v-model="form.companyName" disabled="true" />
        </el-form-item>
        <el-form-item label="监控人员名称" prop="monitorByName">
          <el-input v-model="form.monitorByName" placeholder="请输入监控人员名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--详情对话框 -->
    <el-dialog :title="infoTitle" :visible.sync="infoOpen" width="70%" append-to-body>
      <el-form ref="infoForm" :model="infoForm" :rules="infoRules" label-width="20px">
        <el-form-item label="" prop="">
          <h2 style="font-weight: bold">{{infoForm.baseinfo.companyName}}</h2>
        </el-form-item>
        <el-form-item label="" prop="" class="spaced-items">
           <el-button type="success" size="mini">{{infoForm.baseinfo.regStatus}}</el-button> 
           <el-button type="info" size="mini">{{infoForm.baseinfo.historyNames}}</el-button>
           <el-button type="primary" size="mini">{{infoForm.baseinfo.industry}}</el-button> 
           <el-button type="danger" size="mini">{{infoForm.companyInfo.riskRemark}}</el-button> 
           <el-button  size="mini">{{infoForm.companyInfo.updateTime}}</el-button> 
        </el-form-item>
        <el-form-item label="" prop="">
         <hr class="shr">
        </el-form-item>
        <el-form-item label="" prop="">
          <el-col :span="8">
            <span>统一社会信用代码：{{infoForm.baseinfo.creditCode}}</span>
          </el-col>
          <el-col :span="8">
            <span>电话：{{infoForm.baseinfo.phoneNumber}}</span>
          </el-col>
          <el-col :span="8">
            <span>国际行业：{{infoForm.baseinfo.industry}}</span>
          </el-col>
        </el-form-item>
        <el-form-item label="" prop="" class="spaced-items">
          <el-col :span="8">
            <span>法定代表人：<span style="color:blue">{{infoForm.baseinfo.legalPersonName}}</span></span>
          </el-col>
          <el-col :span="8">
            <span>邮箱：<span style="color:blue">{{infoForm.baseinfo.email}}</span></span>
          </el-col>
          <el-col :span="8">
            <span>企业规模：{{infoForm.baseinfo.staffNumRange}}</span>
          </el-col>
        </el-form-item>
        <el-form-item label="" prop="" class="spaced-items">
          <el-col :span="8">
            <span>注册资本：{{infoForm.baseinfo.regCapital}}</span>
          </el-col>
          <el-col :span="8">
            <span>网址：<span style="color:blue">{{infoForm.baseinfo.websiteList}}</a></span></span>
          </el-col>
          <el-col :span="8">
            <span>员工人数：{{infoForm.baseinfo.socialStaffNum}}</span>
          </el-col>
        </el-form-item>
        <el-form-item label="" prop="" class="spaced-items">
          <el-col :span="8">
            <span>成立日期：{{infoForm.baseinfo.estiblishTime}}</span>
          </el-col>
          <el-col :span="16">
            <span>地址：{{infoForm.baseinfo.regLocation}}</span>
          </el-col>
        </el-form-item>
        <el-form-item label="" prop="" class="spaced-items">
          <div>经营范围：<br/>{{infoForm.baseinfo.businessScope}}</div>
        </el-form-item>
        <el-form-item label="" prop="">
         <hr class="shr">
        </el-form-item>
        <el-form-item label="" prop=""> 
          <el-col :span="20">
            <el-button @click="bt1()" type="primary" :plain="bp1">企业信息变更（{{infoForm.companyInfo.staffNum + infoForm.companyInfo.inverstNum + infoForm.companyInfo.changeinfoNum}}+ {{infoForm.companyInfo.staffAdd + infoForm.companyInfo.inverstAdd + infoForm.companyInfo.changeinfoAdd}}）</el-button> 
            <el-button @click="bt2()" type="primary" :plain="bp2">法律诉讼（{{infoForm.companyInfo.courtRegisterNum + infoForm.companyInfo.dishonestNum}}+{{infoForm.companyInfo.courtRegisterAdd + infoForm.companyInfo.dishonestAdd}}）</el-button>
          </el-col>
          <el-col :span="4">
            <el-button type="warning" @click="handleAlog()">风险审阅</el-button> <br/> <span style="margin-left:20px" @click="handleAlogInfo()">审阅记录  </span>
          </el-col>
        </el-form-item>
        <el-form-item label="" prop="" v-if="ef1">
          <h4>主要人员 {{infoForm.companyInfo.staffNum?infoForm.companyInfo.staffNum:0}} <span style="color:orange">（近期新增 {{infoForm.companyInfo.staffAdd?infoForm.companyInfo.staffAdd:0}}）</span></h4>
        </el-form-item>
        <el-form-item label="" prop="" v-if="ef1">
                      <el-table
                  :data="infoForm.staffs"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="name"
                    label="姓名"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="typeJoin"
                    label="职位">
                  </el-table-column>
                </el-table>
        </el-form-item>

        <el-form-item label="" prop="" v-if="ef1">
          <h4>对外投资 {{infoForm.companyInfo.inverstNum?infoForm.companyInfo.inverstNum:0}} <span style="color:orange">（近期新增 {{infoForm.companyInfo.inverstAdd?infoForm.companyInfo.inverstAdd:0}}）</span></h4>
        </el-form-item>
        <el-form-item label="" prop="" v-if="ef1">
                      <el-table
                  :data="infoForm.inversts"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="name"
                    label="被投资企业名称"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="legalPersonName"
                    label="被投资法定代表人">
                  </el-table-column>
                  <el-table-column
                    prop="percent"
                    label="投资占比">
                  </el-table-column>
                  <el-table-column
                    prop="regCapital"
                    label="注册资本">
                  </el-table-column>
                  <el-table-column
                    prop="estiblishTime"
                    label="成立日期">
                  </el-table-column>
                  <el-table-column
                    prop="regStatus"
                    label="经营状态">
                  </el-table-column>
                </el-table>
        </el-form-item>
        
        <el-form-item label="" prop="" v-if="ef1">
          <h4>变更记录 {{infoForm.companyInfo.changeinfoNum?infoForm.companyInfo.changeinfoNum:0}} <span style="color:orange">（近期新增 {{infoForm.companyInfo.changeinfoAdd?infoForm.companyInfo.changeinfoAdd:0}}）</span></h4>
        </el-form-item>
        <el-form-item label="" prop="" v-if="ef1">
                      <el-table
                  :data="infoForm.changeinfos"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="changeTime"
                    label="变更日期"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="changeItem"
                    label="变更项目">
                  </el-table-column>
                  <el-table-column
                    prop="contentBefore"
                    label="变更前">
                  </el-table-column>
                  <el-table-column
                    prop="contentAfter"
                    label="变更后">
                  </el-table-column>
                </el-table>
        </el-form-item>

      <el-form-item label="" prop="" v-if="ef2">
          <h4>立案信息 {{infoForm.companyInfo.courtRegisterNum?infoForm.companyInfo.courtRegisterNum:0}} <span style="color:orange">（近期新增 {{infoForm.companyInfo.courtRegisterAdd?infoForm.companyInfo.courtRegisterAdd:0}}）</span></h4>
        </el-form-item>
        <el-form-item label="" prop="" v-if=ef2>
                      <el-table
                  :data="infoForm.courtRegisters"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="filingDate"
                    label="立案日期">
                  </el-table-column>
                  <el-table-column
                    prop="caseNo"
                    label="案号">
                  </el-table-column>
                  <el-table-column
                    prop="caseReason"
                    label="案由">
                  </el-table-column>
                  <el-table-column
                    prop="plaintiff"
                    label="公诉人/原告/上诉人/申请人">
                  </el-table-column>
                  <el-table-column
                    prop="defendant"
                    label="被告人/被告/被上诉人/被申请人">
                  </el-table-column>
                </el-table>
        </el-form-item>

     <el-form-item label="" prop="" v-if="ef2">
          <h4>失信被执行人 {{infoForm.companyInfo.dishonestNum?infoForm.companyInfo.dishonestNum:0}} <span style="color:orange">（近期新增 {{infoForm.companyInfo.dishonestAdd?infoForm.companyInfo.dishonestAdd:0}}）</span></h4>
        </el-form-item>
        <el-form-item label="" prop="" v-if=ef2>
                      <el-table
                  :data="infoForm.dishonests"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="publishdate"
                    label="发布日期"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="regdate"
                    label="立案日期">
                  </el-table-column>
                  <el-table-column
                    prop="casecode"
                    label="案号">
                  </el-table-column>
                  <el-table-column
                    prop="courtname"
                    label="执行法院">
                  </el-table-column>
                  <el-table-column
                    prop="performance"
                    label="履行情况">
                  </el-table-column>
                  <el-table-column
                    prop="gistid"
                    label="执行依据文号">
                  </el-table-column>
                </el-table>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--新增审阅记录对话框 -->
    <el-dialog :title="alogTitle" :visible.sync="alogOpen" width="500px" append-to-body>
      <el-form ref="alogForm" :model="alogForm" :rules="alogRules" label-width="80px">
        <el-form-item label="审阅等级" prop="approvalLevel">
          <el-select
                clearable
                @change="$forceUpdate()"
                v-model="alogForm.approvalLevel"
                :size="size"
                style="width: 200px"
              >
                <el-option
                  v-for="level in levels"
                  :key="level.value"
                  :label="level.label"
                  :value="level.value"
                >
                </el-option>
              </el-select>
        </el-form-item>
        <el-form-item label="审阅意见" prop="approvalRemark">
          <el-input v-model="alogForm.approvalRemark" placeholder="请输入审阅意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="alogSubmitForm">提交审阅</el-button>
        <el-button @click="alogCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--审阅记录对话框 -->
    <el-dialog :title="alogInfoTitle" :visible.sync="alogInfoOpen" width="70%" append-to-body>
      <el-form ref="alogInfoForm" :model="alogInfoForm" :rules="alogInfoRules" label-width="20px">
        <el-form-item label="" prop="">
                      <el-table
                  :data="alogInfoForm"
                  style="width: 100%">
                  <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="approvalLevel"
                    label="人工审阅等级"
                    >
                  </el-table-column>
                  <el-table-column
                    prop="approvalRemark"
                    label="审阅意见"
                    >
                  </el-table-column>
                  <el-table-column
                    prop="approvalByName"
                    label="审阅人"
                    >
                  </el-table-column>
                  <el-table-column
                    prop="approvalTime"
                    label="审阅时间"
                    >
                  </el-table-column>
                </el-table>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<style>

.spaced-items {
  margin-top: -30px; /* 调整间隔为20px */
}
.shr {
  border: none; /* 移除默认边框 */
    height: 1px; /* 设置高度 */
    background-color: #333; /* 设置颜色 */
    margin: 10px 0; /* 设置上下外边距 */
}
</style>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, getTycInfo, addAlog, query } from "@/api/ctyc/info";

export default {
  name: "Info",
  props: {
          oid: {
              type: String, // 指定数据类型
              default: '' // 指定默认值，如果message绑定的值设置为 undefined 即会使用该值
          }
        },
  data() {
    return {
      // 按钮模拟默认点击
      bp1: false,
      bp2: true,
      // 风险等级
      levelTaps: [{
          value: '',
          label: '全部'
        }, {
          value: 'A',
          label: 'A'
        }, {
          value: 'B',
          label: 'B'
        }, {
          value: 'C',
          label: 'C'
        }],
      // 详情弹出层标题
      alogInfoTitle: "",
      // 详情是否显示弹出层
      alogInfoOpen: false,
      // 详情表单参数
      alogInfoForm: {
      },
      // 详情表单校验
      alogInfoRules: {},
      // 风险等级
      levels: [{
          value: '',
          label: '请选择'
        }, {
          value: '风险A：风险较高，可能影响合作',
          label: '风险A：风险较高，可能影响合作'
        }, {
          value: '风险B：风险一般，建议人工了解',
          label: '风险B：风险一般，建议人工了解'
        }, {
          value: '风险C：风险较低，不影响继续合作',
          label: '风险C：风险较低，不影响继续合作'
        }],
      // 详情弹出层标题
      alogTitle: "",
      // 详情是否显示弹出层
      alogOpen: false,
      // 详情表单参数
      alogForm: {
      },
      // 详情表单校验
      alogRules: {},
      // 控制隐藏
      ef1: true,
      ef2: false,
      // 详情弹出层标题
      infoTitle: "",
      // 详情是否显示弹出层
      infoOpen: false,
      // 详情表单参数
      infoForm: {
        baseinfo: {},
        companyInfo: {}
      },
      // 详情表单校验
      infoRules: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合作企业表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        companyName: null,
        newCompanyName: null,
        monitorBy: null,
        monitorByName: null,
        revision: null,
        tenantId: null,
        approvalLevel: null,
        approvalRemark: null,
        approvalBy: null,
        approvalByName: null,
        approvalTime: null,
        status: 1,
        approvalTimes: '',
        approvalTimeStart: '',
        approvalTimeEnd: ''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    if(this.oid != ''){
      this.handleOaInfo(this.oid);
    }
  },
  methods: {
    /** 查询合作企业列表 */
    getList() {
      this.loading = true;
      if(this.queryParams.approvalTimes != null && this.queryParams.approvalTimes != ''){
        this.queryParams.approvalTimeStart = new Date(this.queryParams.approvalTimes[0]).toLocaleString();
        this.queryParams.approvalTimeEnd = new Date(this.queryParams.approvalTimes[1]).toLocaleString();
      }
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.queryParams.approvalTimeStart = '';
        this.queryParams.approvalTimeEnd = '';
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 风险审阅取消按钮
    alogCancel(){
        this.alogOpen = false;
        this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyId: null,
        companyName: null,
        newCompanyName: null,
        monitorBy: null,
        monitorByName: null,
        revision: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        tenantId: null,
        approvalLevel: null,
        approvalRemark: null,
        approvalBy: null,
        approvalByName: null,
        approvalTime: null,
        status: 1,
        approvalTimes: '',
        approvalTimeStart: '',
        approvalTimeEnd: ''
      };
      this.resetForm("form");
      this.alogForm = {
      };
      this.resetForm("alogForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加合作企业";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改合作企业";
      });
    },
    /** 详情按钮操作 */
    handleInfo(row) {
      this.reset();
      const companyId = row.companyId
      getTycInfo(companyId).then(response => {
        this.infoForm = response.data;
        this.infoOpen = true;
        this.ef1 = true;
        this.ef2 = false;
        this.bp1 = false;
        this.bp2 = true;
        this.infoTitle = "审阅";
      })
    },
    /** 详情按钮操作 */
    handleOaInfo(oid) {
      this.reset();
      const companyId = oid
      getTycInfo(companyId).then(response => {
        this.infoForm = response.data;
        this.infoOpen = true;
        this.ef1 = true;
        this.ef2 = false;
        this.bp1 = false;
        this.bp2 = true;
        this.infoTitle = "审阅";
      })
    },
    /** 风险审阅按钮操作 */
    handleAlog() {
      this.reset();
      this.alogOpen = true;
      this.alogForm.approvalLevel = ''
    },
    /** 审阅记录按钮操作 */
    handleAlogInfo() {
      this.reset();
      query(this.infoForm.companyInfo.companyId).then(response => {
        this.alogInfoForm = response.rows;
        this.alogInfoOpen = true;
        this.alogInfoTitle = "审阅记录";
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 风险审阅提交按钮 */
    alogSubmitForm() {
      this.$refs["alogForm"].validate(valid => {
        if (valid) {
          if(this.alogForm.approvalLevel!=null && this.alogForm.approvalLevel!='' &&
          this.infoForm.companyInfo.companyId != null && this.infoForm.companyInfo.companyId != ''){
            this.alogForm.companyId = this.infoForm.companyInfo.companyId;
            this.alogForm.companyName = this.infoForm.companyInfo.companyName;
              addAlog(this.alogForm).then(response => {
                this.$modal.msgSuccess("审阅提交成功");
                this.alogOpen = false;
                this.getList();
              });
          }else{
              this.$message.error('请选择审阅等级！');
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除合作企业编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ctyc/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    },
    /** 按钮事件控制隐藏 */
    bt1(){
      this.ef2 = false;
      this.ef1 = true;
      this.bp1 = false;
      this.bp2 = true;
    },
    bt2(){
      this.ef1 = false;
      this.ef2 = true;
      this.bp1 = true;
      this.bp2 = false;
    }
  }
};
</script>

