<template>
  <div class="main-content abnormal">
    <DetailHead result="查询结果" />
    <div class="content-body">
      <el-form ref="form" :model="form" label-width="200px" label-position="right" :rules="formRules">
        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>严重违法主体信息</label></div>
          </div>
          <div class="form-body">
            <el-row>
              <el-col :span="12">
                <el-form-item label="当事人">
                  <span>{{ dissentModel.entName }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="统一社会信用代码/身份证号码">
                  <span>{{ dissentModel.regNO }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="住所（经营场所）">
                  <span>{{ eBaseinfo.dom }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="法定代表人（负责人、经营者）姓名">
                  <span>{{ eBaseinfo.lerep }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-col :span="12">
                <el-form-item label="联系人" prop="contacts">
                  <el-input v-model="form.contacts" type="textarea" style="width:99%;margin:5px 0 5px 0" :autosize="{ minRows: 1 }" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系方式" prop="telephone">
                  <el-input v-model="form.telephone" type="textarea" style="width:99%;margin:5px 0 5px 0" :autosize="{ minRows: 1 }" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="审批事项">
                <el-input v-model="exmainematter" type="textarea" style="width:99%;margin:5px 0 5px 0" :autosize="{ minRows: 1 }" />
              </el-form-item>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="列入严重违法名单决定书文号">
                <span>{{ wrirsno }}</span>
              </el-form-item>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="异议主要事实和法律依据">
                <el-input v-model="dissentExplain" type="textarea" style="width:99%;margin:5px 0 5px 0" :autosize="{ minRows: 4 }" />
              </el-form-item>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="材料清单">
                <el-row style="border-left: hidden">
                  <div :span="4" style="padding:0 10px">（1）撤销列入严重违法失信名单申请书<span style="color:red">*</span></div>
                  <div :span="20" style="padding:0 10px">
                    <el-upload
                      ref="fileUpload"
                      :action="uploadPath"
                      :data="{bizseq:bizseq,attachtype:'1'}"
                      :on-remove="removeFile"
                      :on-success="uploadCallback"
                      :on-preview="previewFile"
                      multiple
                      :file-list="sqsfileList"
                      style="max-width:600px"
                    >
                      <el-button type="primary" size="small">上传</el-button>
                      <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
                    </el-upload>
                  </div>
                </el-row>
                <el-row style="border-left: hidden">
                  <div :span="4" style="padding:0 10px">（2）其他</div>
                  <div :span="20" style="padding:0 10px">
                    <el-upload
                      ref="fileUpload"
                      :action="uploadPath"
                      :data="{bizseq:bizseq,attachtype:'2'}"
                      :on-remove="removeFile"
                      :on-success="uploadCallback"
                      :on-preview="previewFile"
                      multiple
                      :file-list="qtfileList"
                      style="max-width:600px"
                    >
                      <el-button type="primary" size="small">上传</el-button>
                    </el-upload>
                  </div>
                </el-row>
              </el-form-item>
            </el-row>

            <!--            <el-row class="p0">-->
            <!--              <el-form-item label="移出主体信息">-->
            <!--                &lt;!&ndash; <el-button type="primary" size="mini" @click="showEntbaseList">查看主体名单<i class="el-icon el-icon-s-order" style="margin-left:5px" /></el-button> &ndash;&gt;-->
            <!--                <label>统一社会信用代码/注册号：</label><span>{{ dissentModel.regNO }}</span><br>-->
            <!--                <label>企业名称：</label><span>{{ dissentModel.entName }}</span><br>-->
            <!--                <label>法人：</label><span>{{ dissentModel.leRepName }}</span>-->
            <!--              </el-form-item>-->
            <!--            </el-row>-->
            <!--            <el-row>-->
            <!--              <el-form-item label="移出违法失信企业名单的证据材料" class="upload padding0 bt0">-->
            <!--                <el-row class="p0">-->
            <!--                  <el-col :span="4" style="padding:0 10px">一、必备证据材料<span style="color:red">*</span></el-col>-->
            <!--                  <el-col :span="20" class="border-left" style="padding:0 10px">-->
            <!--                    1、国家企业信用信息公示系统上企业的历年年报记录截图<br>2、《严重违法失信企业信用修复申请表》扫描件<br>3、《严重违法失信企业信用修复审批表》扫描件-->
            <!--                  </el-col>-->
            <!--                </el-row>-->
            <!--                <el-row class="border-top p0">-->
            <!--                  <el-col :span="4" style="padding:0 10px">二、补充证据材料<span style="color:red">*</span></el-col>-->
            <!--                  <el-col :span="20" class="border-left" style="padding:0 10px">-->
            <!--                    <el-upload-->
            <!--                      ref="fileUpload"-->
            <!--                      :action="uploadPath"-->
            <!--                      :data="{bizseq:bizseq}"-->
            <!--                      :on-remove="removeFile"-->
            <!--                      :on-success="uploadCallback"-->
            <!--                      :on-preview="previewFile"-->
            <!--                      multiple-->
            <!--                      :file-list="fileList"-->
            <!--                      style="max-width:600px"-->
            <!--                    >-->
            <!--                      <el-button type="primary" size="small">点击上传</el-button>-->
            <!--                    &lt;!&ndash; <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> &ndash;&gt;-->
            <!--                    </el-upload>-->
            <!--                  </el-col>-->
            <!--                </el-row>-->
            <!--              </el-form-item>-->
            <!--            </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>
              <el-form-item label="是否受理" prop="acceptStat">
                <el-radio v-model="acceptStat" label="1">拟受理</el-radio>
                <el-radio v-model="acceptStat" label="0">拟不予受理</el-radio>
                <el-radio v-model="acceptStat" label="2">结束流程</el-radio>
              </el-form-item>
            </el-row>
            <el-row v-if="acceptStat !== '2'" class="bt0">
              <el-form-item label="经办意见" prop="opinion">
                <el-col :span="24">
                  <el-input v-model="form.opinion" style="width:100%" type="textarea" placeholder="请输入经办意见" />
                </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-row>
            <el-row v-if="acceptStat !== '2'">
              <el-form-item label="审核人" prop="reviewerId" class="bt0">
                <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>

            <el-row v-if="acceptStat === '2'">
              <el-form-item label="结束原因" prop="endReason">
                <el-col :span="24">
                  <el-input v-model="form.endReason" style="width:100%" type="textarea" placeholder="请输入结束原因" />
                </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>
    <HandleDialog :show.sync="showEntbase" title="严重违法企业名单" style="width:50vw" @close="showEntbase = false">
      <el-table
        :data="entbase"
        tooltip-effect="dark"
        style="width: 1200px"
        :fit="true"
        height="500px"
        :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
        :row-class-name="tableRowClassName"
      >
        <el-table-column prop="regNO" label="统一社会信用代码/注册号" min-width="150" align="left" show-overflow-tooltip />
        <el-table-column prop="entName" label="名称" min-width="150" align="left" show-overflow-tooltip />
        <el-table-column prop="leRepName" label="法定代表人" align="left" show-overflow-tooltip />
      </el-table>
    </HandleDialog>
  </div>
</template>

<script>
import HandleDialog from '@/components/HandleDialog'
import { delFile, listAttachmentByBizseq } from '@/api/attachment'
import { illegalDissNext, startIllegalDissent } from '@/api/illegal'
import { getUsersWithPermission } from '@/api/user'
import { taskOpinion } from '@/api/task'
import { getConstant } from '@/api/system'
import { isMenHu } from '@/utils/utils'

export default {
  components: {
    HandleDialog: HandleDialog
  },
  data() {
    return {
      acceptStat: '1', // 是否受理
      sqsfileList: [], // 撤销申请书
      qtfileList: [], // 其他材料
      wrirsno: '', // 列入严重违法名单决定书文号
      dissentExplain: '', // 异议主要事实和法律法规依据
      exmainematter: '撤销严重违法失信名单', // 审批事项
      eBaseinfo: {}, // 主体详情
      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: {
        enterType: 'company',
        lostcreditexplain: '',
        reason: '',
        opinion: '',
        exmainematter: '',
        dissentExplain: '',
        contacts: '',
        telephone: '',
        endReason: ''
      },
      formRules: {
        endReason: [
          { required: true, message: '请输入结束原因', trigger: ['blur', 'change'] }
        ],
        contacts: [
          { required: true, message: '请输入联系人', trigger: ['blur', 'change'] }
        ],
        telephone: [
          { required: true, message: '请输入联系方式', trigger: ['blur', 'change'] }
        ],
        opinion: [
          { required: true, message: '请输入经办意见', trigger: ['blur', 'change'] }
        ],
        reviewerId: [
          { required: true, message: '请选择审核人' }
        ]
      },
      reason: '',
      opinion: '',
      reasonOptions: [],
      opinionOptions: [{
        value: 0,
        label: '拟同意'
      }, {
        value: 1,
        label: '同意'
      }, {
        value: 2,
        label: '不同意'
      }],
      historyLog: [],
      exmainerOptions: [],
      fileList: [],
      user: JSON.parse(sessionStorage.getItem('user')),
      reviewer: [],
      submitLoading: false,
      currentNode: '', // 当前节点
      currentNodeName: '', // 当前节点名称
      dissentModel: {} // 异议主体信息
    }
  },
  watch: {
    // 原因渲染
    reason() {
      this.form.specause = 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)

    // 加载异议申请信息
    startIllegalDissent({ tasklistid: this.tasklistid }).then(res => {
      if (res.code === 0) {
        // 添加分页index
        const data = res.data
        this.dissentModel = data.tsBizDissentModel
        this.entbase.push(data.tsBizDissentModel)
        this.eBaseinfo = data.eBaseinfo
        this.exmainematter = this.$util.isNotEmpty(data.tsBizDissentModel.exmainematter) ? data.tsBizDissentModel.exmainematter : '撤销严重违法失信名单'
        if (this.$util.isNotEmpty(data.tsBizDissentModel.dissentExplain)) {
          this.dissentExplain = data.tsBizDissentModel.dissentExplain
        }
        this.wrirsno = data.wrirsno
        this.form.contacts = this.$util.isNotEmpty(data.tsBizDissentModel.contacts) ? data.tsBizDissentModel.contacts : ''
        this.form.telephone = this.$util.isNotEmpty(data.tsBizDissentModel.telephone) ? data.tsBizDissentModel.telephone : ''
        this.acceptStat = this.$util.isNotEmpty(data.tsBizDissentModel.acceptStat) ? data.tsBizDissentModel.acceptStat : '1'
      } else {
        this.$message.error('加载异议信息失败')
      }
    })
    // 加载处办记录
    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 '3': each.step = '核准审批人'; break
          }
          this.historyLog.push(each)
        })
      } else {
        this.$message.error('加载处办记录失败')
      }
    })

    // 加载企业列入原因
    getConstant('CD73').then(res => {
      if (res.code === 0) {
        const list = []
        res.data.forEach(each => {
          list.push({
            value: each.code,
            label: each.name
          })
        })
        this.reasonOptions = list
      }
    })

    // 加载审核人
    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
        if (each.attachtype === '1') {
          this.sqsfileList.push(each)
        } else {
          this.qtfileList.push(each)
        }
      })
      // this.fileList = data
    })
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    // 上传文件预览
    previewFile(file) {
      window.open(file.url, '_blank')
    },
    // 发送提交
    submitForm() {
      if (this.$util.isEmpty(this.exmainematter)) return this.$message.error('请填写审批事项')
      if (this.$util.isEmpty(this.dissentExplain)) return this.$message.error('请填写异议主要事实和法律法规依据')
      if (this.sqsfileList.length === 0) return this.$message.error('请上传申请材料')
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.$confirm('是否确认发送？', '提示').then(() => {
          this.form.bizseq = this.bizseq
          this.form.workflowid = this.workflowId
          this.form.opiniontype = '0'
          this.form.handler = this.user.username
          this.form.handlerid = this.user.primaryKey
          this.form.opinioncontent = this.form.opinion
          this.form.tasklistid = this.tasklistid
          this.form.nextPerformerids = this.form.reviewerId
          this.form.exmainematter = this.exmainematter
          this.form.dissentExplain = this.dissentExplain
          this.form.acceptStat = this.acceptStat
          for (const i in this.reviewer) {
            if (this.reviewer[i].primaryKey === this.form.reviewerId) {
              this.form.nextPerformerNames = this.reviewer[i].name
            }
          }
          for (const key in this.dissentModel) {
            if (this.form[key] || key === 'lauptime' || !this.dissentModel[key]) continue
            this.form[key] = this.dissentModel[key]
          }
          if (this.form.acceptStat === '2') {
            this.form.nextNodeID = 'overFinish'
            this.form.opinioncontent = this.form.endReason
          } else {
            this.form.nextNodeID = 'handleDissentAccept'
          }
          this.submitLoading = true
          illegalDissNext(this.form).then(res => {
            this.submitLoading = false
            if (res.code === 0) {
              this.$message.success('发送成功')
              if (isMenHu()) {
                // 信创门户环境跳转回待办
                window.location.href = '/aiccs/#/todo/list'
              } else {
                this.$router.back()
              }
            }
          })
        }).catch(() => {})
      })
    },
    uploadCallback(res, file, fileList) {
      if (res.code === 0) {
        file.id = res.data.attachmentid
        file.url = `${process.env.VUE_APP_DOWNLOAD_URL}/` + res.data.temppath
        if (res.data.attachtype === '1') {
          this.sqsfileList = fileList
        } else {
          this.qtfileList = fileList
        }
        this.fileList = fileList
      }
    },
    // 查看异常主体名单
    showEntbaseList() {
      this.showEntbase = !this.showEntbase
    },
    // 移除文件回调
    removeFile(file, fileList) {
      if (file && file.status === 'success') {
        delFile(file.id).then(res => {
          if (res.code === 0) {
            this.$message.success('删除成功')
          } else {
            this.$message.error(res.msg)
          }
        })
      }
    },
    // 加载审核人
    loadReviewer() {
      getUsersWithPermission('illegalDissentApplyExamine', 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;
  .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;
    display: flex;
    align-items: center;
    .title{
      font-weight: 700;
      font-size: $font-size-sub-title;
    }
  }
  .content-body{
    padding:20pt;
      .tab{
        .tab-title{
          label{
            display:inline-block;
          }
        }
      }
    .form{
      margin-bottom: 20pt;
    }
  }
}
.el-row {
  border-left: 1px  solid $color-border;
}
.bt0 {
  /deep/.el-form-item__label{
    border-top:0!important;
  }
  /deep/.el-form-item__content{
    border-top:0!important;
  }
}
</style>
<style lang="scss">
.main-content.abnormal{
  font-size: $table-content-font-size;
  .el-form-item{
    height: 100%;
    width: 100%;
    margin-bottom:0;
    background: $color-form-label;
    .el-form-item__label{
      font-size: $table-content-font-size;
      padding-left: 10px;
      border-top: 1px solid $color-border;
      /* border-left: 1px solid $color-border; */
    }
    .el-form-item__content{
      height: 100%;
      background: white;
      padding: 10px;
      font-size: $table-content-font-size;
      border-top: 1px solid $color-border;
      border-right: 1px solid $color-border;
      border-left: 1px solid $color-border;
    }

    .border-left{
      border-left: 1px solid $color-border;
    }
    .border-top{
      border-top: 1px solid $color-border;
    }
  }
  .padding0{
    .el-form-item__content{
      padding: 0;
      border-left: 0;
    }
  }
  .el-form-item:last-child{
    border-bottom: 1px solid $color-border;
  }
  .form-body.history{
    padding:15px;
    border:1px solid $color-border;
  }
  .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;
  }
  .upload .el-form-item__label::after{
    content: '(单个文件不能超过20M)';
    color: #F56C6C;
  }
  .el-textarea.is-disabled .el-textarea__inner{
    color: #1c1e23;
  }
  .el-input__inner{
    margin-bottom: 5px;
  }
}
</style>
