<template>
  <div class="main-content abnormal">
    <!-- <div class="content-header">
      <span class="title">严重违法名录列入：经办</span>
      <el-button type="warning" icon="el-icon-caret-left" size="mini" class="back-btn" @click="$router.back()">返回上一层</el-button>
    </div> -->
    <DetailHead result="业务受理" />
    <div class="content-body">
      <el-form ref="form" :model="form" label-width="220px" label-position="right" :rules="formRules">
        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>主体信息</label></div>
          </div>
          <div class="form-body flex-row">
            <el-row class="zt">
              <el-col :span="4" class="zt_label">统一社会信用代码/注册号</el-col>
              <el-col :span="8" class="zt_value">
                {{ eBaseInfo.uniscid || eBaseInfo.regno }}
              </el-col>
              <el-col :span="4" class="zt_label">主体名称</el-col>
              <el-col :span="8" class="zt_value">
                <router-link target="_blank" :to="{path:'/comprehensive/details',query:{pripid:eBaseInfo.pripid,shrink:true}}" style="color: #1F65FF">
                  {{ eBaseInfo.entname }}
                </router-link>
              </el-col>
            </el-row>
            <el-row class="zt">
              <el-col :span="4" class="zt_label">企业状态</el-col>
              <el-col :span="8" class="zt_value">{{ eBaseInfo.regstateCn }}</el-col>
              <el-col :span="4" class="zt_label">登记机关	</el-col>
              <el-col :span="8" class="zt_value">{{ eBaseInfo.regorgCn }}</el-col>
            </el-row>
            <el-row class="zt">
              <el-col :span="4" class="zt_label">商事主体类型</el-col>
              <el-col :span="8" class="zt_value">{{ eBaseInfo.enttypeCn }}</el-col>
              <el-col :span="4" class="zt_label">法定代表人</el-col>
              <el-col :span="8" class="zt_value">{{ eBaseInfo.name }}</el-col>
            </el-row>
            <el-row class="zt">
              <el-col :span="4" class="zt_label">成立日期</el-col>
              <el-col :span="8" class="zt_value">{{ $moment(eBaseInfo.estdate).format('YYYY-MM-DD') }}</el-col>
              <el-col :span="4" class="zt_label">经营期限</el-col>
              <el-col :span="8" class="zt_value">
                {{ (eBaseInfo.opto || '长期') }}
              </el-col>
            </el-row>
            <el-row class="zt">
              <el-col :span="4" class="zt_label">经营地址</el-col>
              <el-col :span="20" class="zt_value">{{ eBaseInfo.dom || eBaseInfo.address }}</el-col>
            </el-row>
            <el-row class="zt">
              <el-col :span="4" class="zt_label">经营范围	</el-col>
              <el-col :span="20" class="zt_value">{{ eBaseInfo.opscope }}</el-col>
            </el-row>
          </div>
        </div>
        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>严重违法信息</label></div>
          </div>
          <div class="form-body">
            <el-row class="bt0">
              <el-form-item label="来源类型" prop="sourceType">
                <el-col :span="24">
                  <el-select v-model="form.sourceType" placeholder="请选择来源类型" style="width:100%" class="custom" filterable :disabled="form.sourceType==='1' || lastLink ==='6'" @change="refreshReasonOptions">
                    <template v-for="item in sourceTypeList">
                      <el-option
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      />
                    </template>
                  </el-select>
                </el-col>
              </el-form-item>
            </el-row>
            <template v-if="form.sourceType ==='2'">
              <el-row class="bt0">
                <el-form-item label="是否经过听证程序" prop="ishea">
                  <el-col :span="24">
                    <el-radio v-model="form.ishea" label="1" :disabled="lastLink ==='6' || isSjAccept">是</el-radio>
                    <el-radio v-model="form.ishea" label="0" :disabled="lastLink ==='6' || isSjAccept">否</el-radio>
                  </el-col>
                </el-form-item>
              </el-row>
              <el-row v-if="form.ishea === '1'" class="bt0">
                <el-form-item label="当事人听证中提出的主要意见" prop="heaop">
                  <el-col :span="24">
                    <el-input v-model="form.heaop" type="textarea" placeholder="请输入当事人听证中提出的主要意见" style="width:100%" :autosize="{ minRows: 2}" maxlength="1000" show-word-limit :disabled="lastLink ==='6' || isSjAccept" />
                  </el-col>
                </el-form-item>
              </el-row>
              <el-row v-if="form.ishea === '1'" class="bt0">
                <el-form-item label="听证意见" prop="heaop">
                  <el-col :span="24">
                    <el-input v-model="form.heaopinionl" type="textarea" placeholder="请输入当事人听证意见" style="width:100%" autosize maxlength="1000" show-word-limit :disabled="lastLink ==='6' || isSjAccept" />
                  </el-col>
                </el-form-item>
              </el-row>
            </template>
            <template v-else-if="form.sourceType ==='3'">
              <el-row class="bt0">
                <el-form-item label="人民法院司法文书标题" prop="juddoctitle">
                  <el-col :span="24">
                    <el-input v-model="form.juddoctitle" placeholder="请输入人民法院司法文书标题" />
                  </el-col>
                </el-form-item>
              </el-row>
              <el-row class="bt0">
                <el-form-item label="人民法院司法文书文号" prop="juddocno">
                  <el-col :span="24">
                    <el-input v-model="form.juddocno" placeholder="请输入人民法院司法文书文号" />
                  </el-col>
                </el-form-item>
              </el-row>
            </template>
            <template v-if="form.sourceType!=='1' && form.decorg ==='440101'">
              <el-row class="bt0">
                <el-form-item label="列入日期" prop="abntime">
                  <el-col :span="24">
                    <el-date-picker
                      v-model="form.abntime"
                      style="width: 100%"
                      :clearable="false"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      size="small"
                      type="date"
                      placeholder="选择日期"
                      :picker-options="{
                        firstDayOfWeek: 1,
                        disabledDate: (date)=>{
                          return date.setHours(0,0,0,0) > (new Date()).setHours(0,0,0,0)
                        }
                      }"
                    />
                  </el-col>
                </el-form-item>
              </el-row>
            </template>
            <el-row class="bt0">
              <el-form-item label="列入原因" prop="reason">
                <el-col :span="24">
                  <el-select v-model="reason" placeholder="请选择列入原因" style="width:100%" class="custom" filterable :disabled="lastLink ==='6' || isSjAccept">
                    <el-option
                      v-for="item in reasonOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-col>
                <el-col :span="24">
                  <el-input v-model="form.reason" type="textarea" style="width:100%" placeholder="请输入列入原因" disabled />
                </el-col>
              </el-form-item>

            </el-row>
            <el-row class="bt0">
              <el-form-item label="事实理由" prop="lostcreditexplain">
                <el-col :span="24">
                  <el-input v-model="form.lostcreditexplain" type="textarea" placeholder="请输入事实理由" style="width:100%" :autosize="{ minRows: 2, maxRows: 6 }" maxlength="2000" show-word-limit :disabled="lastLink ==='6' || isSjAccept" />
                </el-col>
              </el-form-item>
            </el-row>

            <el-row class="bt0 p0">
              <el-form-item label="材料上传" class="upload">
                <el-upload
                  :action="uploadPath"
                  :data="{bizseq:bizseq}"
                  :on-remove="removeFile"
                  :on-success="uploadCallback"
                  :on-preview="previewFile"
                  :before-upload="beforeFileUpload"
                  :before-remove="beforeRemove"
                  accept=".doc,.docx,.xlsx,.xls,.pdf,.jpg,.zip,.rar,.7z"
                  multiple
                  :file-list="fileList"
                  style="max-width:800px;display: inline-block"
                  class="uploadFileList"
                >
                  <div style="display: inline-block;">
                    <el-button size="small" style="display: inline-block;margin-right:10px" type="primary">点击上传</el-button>
                    <div slot="tip" style="display: inline-block;" class="el-upload__tip">只能上传jpg/png/pdf/doc/docx/xls/xlsx/rar/zip/7z文件，且单个文件不能超过20M</div>
                  </div>
                </el-upload>
                <div v-if="form.sourceType ==='2' || form.sourceType ==='3'" style="line-height: normal;font-size: 14px">
                  应上传材料：
                  1.行政处罚决定书；
                  2.拟列入严重违法失信名单审批表；
                  3.拟列入严重违法失信名单听证告知书；
                  4.送达回证；
                  5.列入严重违法失信名单决定审批表；
                  6.列入严重违法失信名单决定书（拟）；
                  <template v-if="form.sourceType ==='3'">
                    7.法院判决文书；
                  </template>
                </div>
              </el-form-item>
            </el-row>

          </div>
        </div>
        <div v-if="form.sourceType!=='1' && form.decorg ==='440101'" class="form">
          <div class="tab">
            <div class="tab-title"><label>列入严重违法决定书内容</label></div>
          </div>
          <div class="form-body">
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="文书号" prop="writsno" label-width="240px">
                  <el-input v-model.trim="form.writsno" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="当事人" prop="party" label-width="240px">
                  <el-input v-model.trim="form.party" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="主体资格证照名称" prop="certificate" label-width="240px">
                  <el-input v-model.trim="form.certificate" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="统一信用代码/身份证件号码" prop="usccId" label-width="240px">
                  <el-input v-model.trim="form.usccId" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="法定代表人姓名" prop="legalName" label-width="240px">
                  <el-input v-model.trim="form.legalName" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证件号码" prop="idNumber" label-width="240px">
                  <el-input v-model.trim="form.idNumber" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phone" label-width="240px">
                  <el-input v-model.trim="form.phone" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="其他联系方式" prop="otherCert" label-width="240px">
                  <el-input v-model.trim="form.otherCert" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="24">
                <el-form-item label="住所/经营场所（住址）" prop="residence" label-width="240px">
                  <el-input v-model.trim="form.residence" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <div v-if="form.sourceType ==='2'" class="form">
          <div class="tab">
            <div class="tab-title"><label>行政处罚决定书内容</label></div>
          </div>
          <div class="form-body flex-row">
            <el-row class="xzcf_text">
              <el-col :span="4" class="label">处罚决定书文号</el-col>
              <el-col :span="8">
                <el-input v-model="cppenaltyInfoGs.sbookcode" :disabled="lastLink ==='6' || isSjAccept" />
                <el-button type="primary" icon="el-icon-search" size="mini" :disabled="lastLink ==='6' || isSjAccept" @click="cppenaltyVisible=true">搜索</el-button>
              </el-col>
              <el-col :span="4" class="label">违法行为类型</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.sgisttypename" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
            </el-row>
            <el-row class="xzcf_text">
              <el-col :span="4" class="label">处罚种类</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.spuntypename" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
              <el-col :span="4" class="label">处罚金额</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.penam" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
            </el-row>
            <el-row class="xzcf_text">

              <el-col :span="4" class="label">没收金额</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.forfam" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
              <el-col :span="4" class="label">行政处罚决定机关</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.cfdjjg" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
            </el-row>
            <el-row class="xzcf_text">
              <el-col :span="4" class="label">处罚决定书日期</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.cfjdsj" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
              <el-col :span="4" class="label">公示日期</el-col>
              <el-col :span="8"><el-input v-model="cppenaltyInfoGs.cfjdsj" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
            </el-row>
            <el-row class="xzcf_text">
              <el-col :span="4" class="label">当事人</el-col>
              <el-col :span="20"><el-input v-model="cppenaltyInfoGs.dsrmc" :disabled="lastLink ==='6' || isSjAccept" /></el-col>
            </el-row>
            <el-row class="xzcf_text">
              <el-col :span="4" class="label">处罚内容</el-col>
              <el-col :span="20">
                <el-input v-model="cppenaltyInfoGs.spuncontent" type="textarea" :autosize="{ minRows: 2, maxRows: 20 }" :disabled="lastLink ==='6' || isSjAccept" />
              </el-col>
            </el-row>
          </div>
        </div>
        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>处理意见</label></div>
          </div>
          <div class="form-body history">
            <div v-if="historyLog.length === 0" class="none">暂无历史意见</div>
            <el-steps direction="vertical">
              <el-step v-for="(each,index) in historyLog" :key="'historyLog'+index" :title="each.step + '：' + each.handler + ' 处办日期：' + each.handledate" :description="each.opinioncontent" status="finish" />
            </el-steps>
          </div>
        </div>
        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>经办意见</label></div>
          </div>
          <div class="form-body">
            <el-row class="p0">
              <el-form-item label="经办结论" prop="nextNodeId">
                <el-radio v-if="form.sourceType !=='1' && form.decorg ==='440101'" v-model="form.nextNodeId" label="examineSuccess">审批通过，推送公示</el-radio>
                <div v-else>
                  <el-radio v-model="form.nextNodeId" label="review">拟列入</el-radio>
                  <el-radio v-model="form.nextNodeId" label="overNullify">结束流程</el-radio>
                </div>
                <!--                <el-radio v-if="lastLink !=='6'" v-model="form.nextNodeId" label="overNullify">作废办结</el-radio>-->
                <el-radio v-if="isSjAccept" v-model="form.nextNodeId" label="bureauExamineSuccess">退回区局</el-radio>
              </el-form-item>
            </el-row>
            <el-row class="bt0">
              <el-form-item v-if="form.nextNodeId != 'overNullify'" label="经办意见" prop="opinion">
                <el-col :span="24">
                  <el-input v-model="form.opinion" type="textarea" :autosize="{ minRows: 5 }" maxlength="2000" placeholder="请输入经办意见" style="width:100%" />
                </el-col>
                <el-col :span="12">
                  <label>常用语</label>
                  <el-select v-model="opinion" placeholder="请选择" class="custom" style="width:100%">
                    <el-option
                      v-for="item in opinionOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item v-else label="结束原因" prop="endReason">
                <el-col :span="24">
                  <el-input v-model="form.endReason" type="textarea" :autosize="{ minRows: 5 }" maxlength="2000" placeholder="请输入结束原因" style="width:100%" />
                </el-col>
              </el-form-item>
            </el-row>

            <el-row v-if="form.nextNodeId==='review' && user.orgId != '001'" class="bt0">
              <el-form-item label="审核人" prop="reviewerId">
                <el-col :span="12">
                  <el-select v-model="form.reviewerId" placeholder="请选择审核人" class="custom" style="width:100%">
                    <el-option
                      v-for="item in reviewer"
                      :key="'reviewer'+item.primaryKey"
                      :label="item.name"
                      :value="item.primaryKey"
                    />
                  </el-select>
                </el-col>
              </el-form-item>
            </el-row>
          </div>
        </div>
      </el-form>
      <div class="submit-box">
        <el-button type="primary" :loading="submitLoading" @click="submitForm">提交</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </div>
    </div>
    <el-dialog title="行政处罚信息查找" :visible.sync="cppenaltyVisible" width="850px">
      <el-row style="border:unset">
        <el-col :span="9">
          <span>文书号</span>
          <el-input v-model="pendecNo" placeholder="请输入行政处罚文书号（最多只展示5条，请使用准确查询）" size="medium" @keyup.enter.native="listCppenalty" />
        </el-col>
        <el-col :span="10" :offset="1">
          <span>当事人</span>
          <el-input v-model="caseName" placeholder="请输入当事人名称" size="medium" @keyup.enter.native="listCppenalty" />
        </el-col>
        <el-col :span="4">
          <el-button type="primary" icon="el-icon-search" size="medium" style="float: right;margin-top:10px" :loading="cppLoading" @click="listCppenalty">搜索</el-button>
        </el-col>
      </el-row>

      <el-table :data="cppenaltyList" @row-dblclick="dbCppenalty">
        <el-table-column property="sbookcode" label="处罚决定书文号" width="300" />
        <el-table-column property="dsrmc" label="当事人" min-width="200" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import DetailHead from '@/components/DetailHead'
import { removeAttachementById, listAttachmentByBizseq } from '@/api/attachment'
import {
  listIllegalByBizSeq,
  removeByIllegallistid,
  getNewCD73,
  nextProcessInclude, likePendecNo, cppenaltyInfoGsGetById
} from '@/api/illegal'
import { getUsersWithPermission } from '@/api/user'
import { validBeforeUpload } from '@/api/fileUpload'
import { taskOpinion } from '@/api/task'
import { getEntBaseByPripid } from '@/api/entBase'
import { isMenHu } from '@/utils/utils'

export default {
  components: {
    DetailHead
  },
  data() {
    return {
      isSsj: false, // 是否存在送市局节点
      isSjAccept: false, //  是否为送市局的经办环节
      caseName: '',
      pendecNo: '',
      cppLoading: false,
      cppenaltyList: [],
      cppenaltyVisible: false,
      cppenaltyInfoGs: {
        sbookcode: '',
        sgisttypename: '',
        spuntypename: '',
        penam: '',
        forfam: '',
        cfdjjg: '',
        cfjdsj: '',
        dsrmc: '',
        spuncontent: ''
      },
      uploadPath: `${process.env.VUE_APP_BASE_API}/attachment/uploadFileByBizseq`,
      showEntbase: false,
      bizseq: '',
      workflowId: '',
      tasklistid: '',
      entbase: [], // 主体名单列表
      // 分页数据,这里用来保存每页切割后的数据
      // 看起来格式是这样的[[{},{},{}],[{},{},{}]]
      // 数组内套数组，每个数组就是一页数据
      totalPageData: [],
      // 共几页
      pageNum: '',
      // 每页显示数量
      pageSize: 10,
      // 当前显示页码
      currentPage: 1,
      // 总共多少条数据
      total: 1,
      // 当前要显示的数据
      dataShow: [],
      // 选中数组
      multipleSelection: [],
      form: {
        nextNodeId: 'review',
        lostcreditexplain: '',
        reason: '',
        opinion: '',
        endReason: '',
        abntime: null,
        writsno: '',
        party: '',
        certificate: '',
        usccId: '',
        legalName: '',
        phone: '',
        otherCert: '',
        idNumber: '',
        residence: '',
        sourceType: '',
        ishea: '',
        heaop: '',
        heaopinionl: ''
      },
      formRules: {
        endReason: [
          { required: true, message: '请输入结束原因', trigger: 'blur' }
        ],
        reason: [
          { required: true, message: '请输入列入原因', trigger: 'blur' }
        ],
        lostcreditexplain: [
          { required: true, message: '请输入事实理由', trigger: 'blur' }
        ],
        opinion: [
          { required: true, message: '请输入经办意见', trigger: ['blur', 'change'] }
        ],
        reviewerId: [
          { required: true, message: '请选择审核人' }
        ],
        abntime: [
          { required: true, message: '请选择列入时间' }
        ],
        party: [
          { required: true, message: '请输入' }
        ],
        legalName: [
          { required: true, message: '请输入' }
        ],
        certificate: [
          { required: true, message: '请输入' }
        ],
        usccId: [
          { required: true, message: '请输入' }
        ],
        idNumber: [
          { required: true, message: '请输入' }
        ],
        writsno: [
          { required: true, message: '请输入' }
        ],
        phone: [
          { required: true, message: '请输入' }
        ],
        residence: [
          { required: true, message: '请输入' }
        ],
        sourceType: [
          { required: true, message: '请选择' }
        ],
        juddocno: [
          { required: true, message: '请选择' }
        ],
        juddoctitle: [
          { required: true, message: '请选择' }
        ],
        heaop: [
          { required: true, message: '请选择' }
        ],
        heaopinionl: [
          { required: true, message: '请选择' }
        ],
        ishea: [
          { required: true, message: '请选择' }
        ]
      },
      reason: '',
      opinion: '',
      reasonOptions: [],
      sourceTypeList: [
        {
          value: '1',
          label: '经营异常满三年'
        },
        {
          value: '2',
          label: '行政处罚'
        },
        {
          value: '3',
          label: '法院判决'
        },
        {
          value: '9',
          label: '其他'
        }
      ],
      opinionOptions: [{
        value: 0,
        label: '拟同意'
      }, {
        value: 1,
        label: '同意'
      }, {
        value: 2,
        label: '不同意'
      }],
      historyLog: [],
      exmainerOptions: [],
      fileList: [],
      user: JSON.parse(sessionStorage.getItem('user')),
      reviewer: [],
      submitLoading: false,
      eBaseInfo: {},
      decisionOrgan: JSON.parse(sessionStorage.getItem('user')).decisionOrgan,
      reasonOptionsStorage: [],
      lastLink: ''
    }
  },
  watch: {
    // 原因渲染
    reason() {
      this.form.serillrea = this.reason
      let name = ''
      this.reasonOptions.forEach(each => {
        if (this.reason === each.value) {
          name = each.label
        }
      })
      this.form.reason = name
    },
    // 意见渲染
    opinion() {
      let name = ''
      this.opinionOptions.forEach(each => {
        if (this.opinion === each.value) {
          name = each.label
        }
      })
      this.form.opinion = name
    }
  },
  mounted() {
    this.bizseq = this.$route.query.bizseq // 获取跳转携带的参数bizseq
    this.workflowId = this.$route.query.workflowId
    this.tasklistid = this.$route.query.tasklistid
    // 加载常用语
    this.opinionOptions = this.$util.getCommonWords(this.user.primaryKey)
    // 加载处办记录
    taskOpinion(this.workflowId).then(res => {
      if (res.code === 0) {
        res.data.forEach(each => {
          switch (each.opiniontype) {
            case '0': each.step = '经办人'; break
            case '1': each.step = '审核人'; break
            case '2': each.step = '审批人'; break
            case '6':
              each.step = '送市局办理'
              this.isSsj = true; break
            case '8': each.step = '归档'; break
          }
          this.historyLog.push(each)
          this.lastLink = each.opiniontype
          if (this.isSsj && this.user.orgId === '001') {
            this.isSjAccept = true
          }
        })
      } else {
        this.$message.error('加载处办记录失败')
      }
    })
    // 加载异常名录主体
    listIllegalByBizSeq(this.bizseq).then(res => {
      if (res.code === 0) {
        // 添加分页index
        let i = 1
        const pageStart = (this.currentPage - 1) * this.pageSize
        res.data.forEach(each => {
          each.index = pageStart + i++
          each.name = each.entname
          each.uscc = each.regno
          each.typeName = each.entTypeName
          if (this.$route.query.isAbnormal) {
            this.reason = '0001'
          } else {
            this.$set(this, 'reason', each.serillrea)
          }
          this.form.illegallistid = each.illegallistid
          this.form.writsno = each.writsno
          this.form.party = each.party
          this.form.certificate = each.certificate
          this.form.usccId = each.usccId
          this.form.legalName = each.legalName
          this.form.idNumber = each.idNumber
          this.form.phone = each.phone
          this.form.otherCert = each.phone
          this.form.residence = each.residence
          this.form.sourceType = each.sourceType
          this.form.caseId = each.caseId
          this.form.ishea = each.ishea
          this.form.heaop = each.heaop
          this.form.decorg = each.decorg
          this.form.heaopinionl = each.heaopinionl ? each.heaopinionl : ''
          this.entbase.push(each)
          if (each.sourceType !== '1') {
            this.sourceTypeList = [{
              value: '2',
              label: '行政处罚'
            },
            {
              value: '3',
              label: '法院判决'
            },
            {
              value: '9',
              label: '其他'
            }]
            // 行政处罚控件默认当天列入时间
            this.form.abntime = each.abntime ? each.abntime : this.$moment(new Date()).format('YYYY-MM-DD')
          } else {
            this.sourceTypeList = [{
              value: '1',
              label: '经营异常满三年'
            }]
            // 默认选择被列入经营异常名录届满 3 年仍未履行相关义务的
            this.reason = '0001'
          }
          // 事由初始化
          if (each.lostcreditexplain) {
            this.form.lostcreditexplain = each.lostcreditexplain
          } else {
            this.generateDocument()
          }
          // 初始化行政处罚决定书内容
          this.cppenaltyInfoGs.id = each.caseId
          this.cppenaltyInfoGs.sbookcode = each.sbookcode
          this.cppenaltyInfoGs.sgisttypename = each.sgisttypename
          this.cppenaltyInfoGs.spuntypename = each.spuntypename
          this.cppenaltyInfoGs.penam = each.penam
          this.cppenaltyInfoGs.forfam = each.forfam
          this.cppenaltyInfoGs.cfdjjg = each.cfdjjg
          this.cppenaltyInfoGs.cfjdsj = each.cfjdsj
          this.cppenaltyInfoGs.dsrmc = each.dsrmc
          this.cppenaltyInfoGs.spuncontent = each.spuncontent
          if (this.$util.isEmpty(this.cppenaltyInfoGs.sbookcode)) { // 有可能是旧数据
            if (this.$util.isNotEmpty(this.form.caseId)) {
              cppenaltyInfoGsGetById({ id: this.form.caseId }).then(res => {
                if (res.data) {
                  this.cppenaltyInfoGs = res.data
                  this.cppenaltyInfoGs.cfjdsj = this.$util.isNotEmpty(this.cppenaltyInfoGs.cfjdsj) ? this.$util.formatDate.format(new Date(Date.parse(this.cppenaltyInfoGs.cfjdsj)), 'yyyy-MM-dd hh:mm:ss') : ''
                }
              })
            }
          }
          // if (this.form.caseId) {
          //   cppenaltyInfoGsGetById({ caseId: this.form.caseId }).then(res => {
          //     if (res.data) {
          //       this.cppenaltyInfoGs = res.data
          //       this.cppenaltyInfoGs.cfjdsj = this.$util.isNotEmpty(this.cppenaltyInfoGs.cfjdsj) ? this.$util.formatDate.format(new Date(Date.parse(this.cppenaltyInfoGs.cfjdsj)), 'yyyy-MM-dd hh:mm:ss') : ''
          //     }
          //   })
          // }
        })
        // 查询企业主体信息
        getEntBaseByPripid(res.data[0].pripid).then(res => {
          this.eBaseInfo = res.data
          // 首次经办的文书加载需要初始赋值
          if (!this.form.writsno) {
            this.form.party = this.eBaseInfo.entname
            // this.form.certificate =
            this.form.usccId = this.eBaseInfo.uniscid || this.eBaseInfo.regno
            this.form.legalName = this.eBaseInfo.lerep
            this.form.idNumber = this.eBaseInfo.cerno
            this.form.phone = this.eBaseInfo.phone
            this.form.residence = this.eBaseInfo.dom || this.eBaseInfo.address
          }
        })

        // 分页处理
        this.total = this.entbase.length
        // 计算页数
        this.calcPageData()
        // 加载企业列入原因
        getNewCD73().then(res => {
          if (res.code === 0) {
            const list = []
            res.data.forEach(each => {
              if (this.entbase[0].sourceType !== '1' && each.code === '0001') {
                // 忽略满三年原因
                return
              }
              list.push({
                value: each.code,
                label: each.name
              })
            })
            this.reasonOptions = list
            this.reasonOptionsStorage = list
            if (this.$util.isNotEmpty(this.reason)) {
              this.form.specause = this.reason
              let name = ''
              this.reasonOptions.forEach(each => {
                if (this.reason === each.value) {
                  name = each.label
                }
              })
              this.form.reason = name
            }
          }
        })
      } else {
        this.$message.error('加载异常名录主体信息失败')
      }
    })
    // 加载审核人
    this.loadReviewer()

    // 加载附件清单
    listAttachmentByBizseq(this.bizseq).then(data => {
      data.forEach(each => {
        each.id = each.attachmentid
        each.name = each.filename
        each.url = `${process.env.VUE_APP_DOWNLOAD_URL}/` + each.temppath
      })
      this.fileList = data
    })
  },
  methods: {
    dbCppenalty(row) {
      this.cppenaltyInfoGs = row
      this.cppenaltyInfoGs.cfjdsj = this.$util.isNotEmpty(this.cppenaltyInfoGs.cfjdsj) ? this.$util.formatDate.format(new Date(Date.parse(this.cppenaltyInfoGs.cfjdsj)), 'yyyy-MM-dd hh:mm:ss') : ''
      this.cppenaltyVisible = false
    },
    listCppenalty() {
      if (!this.pendecNo && !this.caseName) {
        return
      }
      this.cppLoading = true
      likePendecNo(this.pendecNo, this.caseName).then(res => {
        this.cppenaltyList = res.data
        this.cppLoading = false
      })
    },
    refreshReasonOptions(value) {
      this.reason = ''
      if (value === '3') {
        // 法院判决默认这条
        this.reason = '2901'
      }
      this.generateDocument()
    },
    generateDocument() {
      let str = ''
      if (this.form.sourceType === '3') {
        str = '我局于   年   月   日收到法院（司法文书名称及文号） ，根据《市场监督管理严重违法失信名单管理办法》规定'
      } else {
        str = '经查，你（单位）       （事由）。依据《市场监督管理严重违法失信名单管理办法》       规定'
      }
      this.form.lostcreditexplain = str
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    // 移除文件前
    beforeRemove(file, fileList) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定移除 ${file.name} ？`)
      }
    },
    // 上传文件之前校验大小
    beforeFileUpload(file) {
      var that = this
      return validBeforeUpload(file, that)
    },
    // 计算页数
    calcPageData() {
      // 计算页数(根据后台数据的条数和每页显示数量算出一共几页,得0时设为1)
      if (this.entbase.length >= 1) {
        this.pageNum = Math.ceil(this.entbase.length / this.pageSize) || 1
      }
      // 数据分组
      for (let i = 0; i < this.pageNum; i++) {
        // 每一页都是一个数组 形如 [['第一页的数据'],['第二页的数据'],['第三页数据']]
        // 根据每页显示数量 将后台的数据分割到 每一页,假设pageSize为5， 则第一页是1-5条，即slice(0,5)，第二页是6-10条，即slice(5,10)...
        this.totalPageData[i] = this.entbase.slice(this.pageSize * i, this.pageSize * (i + 1))
      }
      // 获取到数据后显示第一页内容,数组下标是从0开始的，这里一定要减去1，不然会丢失一组数据
      this.dataShow = this.totalPageData[this.currentPage - 1]
    },
    // 每页条数发生变化
    handleSizeChange(newPageSize) {
      this.pageSize = newPageSize
      // 重新计算页数并分组
      this.calcPageData()
    },
    // 当前页码发生变化
    handleCurrentChange(newPageNum) {
      console.log('当前页码:', newPageNum)
      this.currentPage = newPageNum
      // 这里仍然不要忘记减去1
      this.dataShow = this.totalPageData[newPageNum - 1]
    },
    // 剔除主题名单
    removeEntbaseItem() {
      if (this.multipleSelection.length === 0) return this.$message.error('请至少选择一个企业从此列表中剔除')
      this.$confirm('是否确认剔除', '提示').then(() => {
        console.log(this.multipleSelection)
        // 遍历获取illegallistid 拼接成字符串形式
        let ids = ''
        this.multipleSelection.forEach(each => {
          ids += (each.illegallistid + ';')
        })
        // 调接口
        const type = 'ly'
        removeByIllegallistid(ids.substring(0, ids.length - 1), type).then(res => {
          if (res.code === 0) {
            this.multipleSelection.forEach(each => {
            // 表示先获取这个元素的下标，然后从这个下标开始计算，删除长度为1的元素
              this.entbase.splice(this.entbase.indexOf(each), 1)
            })
            let i = 1
            const pageStart = (this.currentPage - 1) * this.pageSize
            this.entbase.forEach(each => {
              each.index = pageStart + i++
            })
            // 重新计算页数
            this.calcPageData()
            this.$message.success('剔除成功')
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },

    // 上传文件预览
    previewFile(file) {
      window.open(file.url, '_blank')
    },
    // 发送提交
    submitForm() {
      this.$refs.form.validate(valid => {
        if (!this.form.reason) {
          this.$message.warning('请填写列入原因！')
        }
        if (!valid) return
        this.$confirm('是否确认发送？', '提示').then(() => {
          this.form.bizseq = this.bizseq
          this.form.workflowid = this.workflowId
          this.form.opinioncontent = this.form.opinion
          this.form.tasklistid = this.tasklistid
          this.form.lostcreditexplain = this.form.lostcreditexplain.replace(new RegExp(/( )/g), '')
          this.form.serillrea = this.reason
          this.submitLoading = true
          let nextHandleId = this.form.reviewerId
          // 属于退回区局经办
          if (this.form.nextNodeId === 'bureauExamineSuccess') {
            for (const item of this.historyLog) {
              if (item.opiniontype === '0') { // 第一次的经办人
                nextHandleId = item.handlerid
                break
              }
            }
          } else if (this.form.nextNodeId === 'examineSuccess') {
            // 市局行政处罚地直接审批通过，并且进行归档
            nextHandleId = this.user.primaryKey
          } else if (this.form.nextNodeId === 'overNullify') {
            this.form.opinion = this.form.endReason
            this.form.opinioncontent = this.form.endReason
            nextHandleId = this.user.primaryKey
          }
          const query = {
            nextNodeId: this.form.nextNodeId,
            currentLink: 'accept',
            nextHandleId
          }
          // 判断类型进行赋值
          if (this.form.sourceType === '2') {
            this.form.juddoctitle = null
            this.form.juddocno = null
            this.form.caseId = this.cppenaltyInfoGs.id
            this.form.sbookcode = this.cppenaltyInfoGs.sbookcode
            this.form.sgisttypename = this.cppenaltyInfoGs.sgisttypename
            this.form.spuntypename = this.cppenaltyInfoGs.spuntypename
            this.form.penam = this.cppenaltyInfoGs.penam
            this.form.forfam = this.cppenaltyInfoGs.forfam
            this.form.cfdjjg = this.cppenaltyInfoGs.cfdjjg
            this.form.cfjdsj = this.cppenaltyInfoGs.cfjdsj
            this.form.dsrmc = this.cppenaltyInfoGs.dsrmc
            this.form.spuncontent = this.cppenaltyInfoGs.spuncontent
            if (this.form.ishea === '0') { // 未听证
              this.form.heaop = null
              this.form.heaopinionl = null
            }
            // if (!this.form.caseId) {
            //   this.$message.warning('行政处罚文书内容不能为空！')
            //   this.submitLoading = false
            //   return
            // }
          } else if (this.form.sourceType === '3') {
            this.form.ishea = null
            this.form.heaop = null
            this.form.heaopinionl = null
          } else if (this.form.sourceType === '9') {
            this.form.ishea = null
            this.form.heaop = null
            this.form.heaopinionl = null
            this.form.juddoctitle = null
            this.form.juddocno = null
          }
          nextProcessInclude(this.form, query).then(res => {
            this.submitLoading = false
            if (res.code === 0) {
              this.$message.success(this.form.nextNodeId === 'overNullify' ? '作废办结成功' : '发送成功')
              if (this.form.nextNodeId === 'examineSuccess') {
                // 行政处罚市局经办审批成功同时进行跳转归档查看页面info
                this.$router.push({ path: '/illegal/listed/info', query: { bizseq: this.bizseq, workflowId: this.workflowId, tasklistid: this.tasklistid }})
              } else {
                if (isMenHu()) {
                  // 信创门户环境跳转回待办
                  window.location.href = '/aiccs/#/todo/list'
                } else {
                  this.$router.back()
                }
              }
            }
          })
        }).catch(() => {})
      })
    },
    uploadCallback(res, file) {
      if (res.code === 0) {
        file.id = res.data.attachmentid
        file.url = `${process.env.VUE_APP_DOWNLOAD_URL}/` + res.data.temppath
      }
    },
    // 查看异常主体名单
    showEntbaseList() {
      this.showEntbase = !this.showEntbase
    },
    // 移除文件回调
    removeFile(file) {
      if (file && file.status === 'success') {
        removeAttachementById(file.id).then(res => {
          if (res.code === 0) {
            this.$message.success('删除成功')
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    // 加载审核人
    loadReviewer() {
      getUsersWithPermission('handleSerIllegal', this.user.orgId).then(res => {
        if (res.code === 0) {
          this.reviewer = res.data
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.main-content{
  font-size: $table-content-font-size;
  padding: 10pt;
  .flex-row{
    .el-row{
      display: flex;
    }
  }
  .back-btn{
    position:absolute;
    right:40pt;
  }
  .content-header,.content-body{
    background: white;
    padding:20PX 10PX;
    border:1PX solid #eee;
  }
  .content-header{
    height:60PX;
    .title{
      font-weight: 700;
      font-size: $table-content-font-size;
    }
  }
  .content-body{
    padding:20pt;
      .tab{
        .tab-title{
          label{
            display:inline-block;
          }
        }
      }
    .form{
      margin-bottom: 20pt;
    }
  }
}
.el-row {
  border-left: 1px  solid $color-border;
}
</style>
<style lang="scss">
.main-content.abnormal{
  font-size: $table-content-font-size!important;
  .el-form-item{
    margin-bottom:0;
    background: $color-form-label;
    .el-form-item__label{
      padding-left: 10px;
      border-top: 1px solid $color-border;
      font-size: $table-content-font-size!important;

      /* border-left: 1px solid $color-border; */
    }
    .el-form-item__content{
      font-size: $table-content-font-size!important;
      background: white;
      padding: 10px;
      border-top: 1px solid $color-border;
      border-right: 1px solid $color-border;
      border-left: 1px solid $color-border;
    }
  }
  .el-form-item:last-child{
    border-bottom: 1px solid $color-border;
  }
  .form-body.history{
    padding:15px;
    border:1px solid $color-border;
  }
  .form-body.history.none{
    font-size: 14px;
  }
  .el-form-item.is-error .custom .el-input__inner{
    border-color:$color-border;
  }
  .el-table-column--selection .cell {
    padding-right: 0px;
  }
  .no {
    padding-left: 0px;
  }
  .el-table_9_column_61.is-left.is-leaf{
    .cell{
      padding-left: 0px;
      padding-right: 0px;
    }
  }
  .el-pagination{
    text-align: right;
  }
  .dialog-box{
    text-align: right;
  }
  .el-textarea.is-disabled .el-textarea__inner{
    color: #1c1e23;
  }
  .el-input__inner{
    margin-bottom: 5px;
  }
  .pub_dialog {
    display: flex;
    justify-content: center;
    align-items: Center;
    overflow: hidden;
    .el-dialog {
        margin: 0 auto !important;
        height: 80%;
        overflow: hidden;
        .el-dialog__body {
            position: absolute;
            left: 0;
            top: 54px;
            bottom: 0;
            right: 0;
            padding: 0;
            z-index: 1;
            overflow: hidden;
            overflow-y: auto;
        }
    }
  }
  .uploadFileList{
    .el-upload-list__item{
      display: inline-block;
      width: auto;
    }
  }
  .el-input__inner{
    color: #1c1e23;
  }
  .zt{
    border-bottom: 1px solid #8CC3FB;
    .zt_label{
      padding: 15px;
      text-align: right;
      border-right: 1px solid #8CC3FB;
      background: #eaf4fe;
    }
    .zt_value{
      padding: 15px;
      text-align: left;
      border-right: 1px solid #8CC3FB;
    }
  }
  .xzcf_text{
    .label{
      text-align: right;
      background: #eaf4fe;
    }
    .el-col{
      padding: 10px;
      border-bottom: 1px solid #8CC3FB;
      border-right: 1px solid #8CC3FB;
    }
  }
}
</style>
