<template>
  <div class="main-content abnormal m20">
    <!-- <DetailHead /> -->
    <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">
            <el-row>
              <el-form-item label="主体名称">
                {{ tsBizDissentModel.entname }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="统一社会信用代码/注册号" class="bt0">
                {{ tsBizDissentModel.uniscid || tsBizDissentModel.regno }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="法定代表人" class="bt0">
                {{ tsBizDissentModel.lerepname }}
              </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">
            <el-table :data="tsAbnList" border style="width: 100%">
              <el-table-column prop="abntime" label="列入日期" min-width="100" />
              <el-table-column prop="spereasons" :show-overflow-tooltip="true" label="列入原因" min-width="200" />
              <el-table-column prop="intoDecorg" label="列入决定机关" min-width="100" />
              <el-table-column prop="writsno" label="列入决定书文号" min-width="100" />
              <el-table-column prop="remdate" label="移出日期" min-width="100" />
              <el-table-column prop="remreasons" :show-overflow-tooltip="true" label="移出原因" min-width="200" />
              <el-table-column prop="reDecorg" label="移出决定机关" min-width="100" />
            </el-table>
          </div>
        </div>

        <div class="form">
          <div class="tab">
            <div class="tab-title"><label>异议信息</label></div>
          </div>
          <el-row v-if="tsAbnModel.operatestatus === '0'">
            <el-form-item label="提示" class="pd0" prop="contacts" style="border-bottom: 0">
              <div style="color: red">该经营异常记录已移出</div>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="联系人" class="pd0" prop="contacts" style="border-bottom: 0">
              {{ tsBizDissentModel.contacts }}
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="联系电话" class="pd0" prop="telephone" style="border-bottom: 0;">
              {{ tsBizDissentModel.telephone }}
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="备注" class="pd0" prop="applyRemark" style="border-bottom: 0;">
              {{ tsBizDissentModel.applyRemark }}
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="材料上传" class="upload">
              <el-upload
                :action="uploadPath"
                :data="{ bizseq: bizseq }"
                :on-remove="removeFile"
                :on-success="uploadCallback"
                :on-preview="previewFile"
                :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>
            </el-form-item>
          </el-row>
          <el-row class="p10">
            <el-form-item label="异议核实情况" prop="situation" class="bt0">
              <el-input v-model="form.situation" disabled type="textarea" placeholder="请输入异议核实情况" style="display:inline-block;width:100%" :autosize="{ minRows: 3, maxRows: 6 }" maxlength="500" show-word-limit />
            </el-form-item>
          </el-row>
        </div>

        <!--        <div class="form">-->
        <!--          <div class="tab">-->
        <!--            <div class="tab-title"><label>异议信息</label></div>-->
        <!--          </div>-->
        <!--          <div class="form-body">-->
        <!--            &lt;!&ndash; <el-form-item label="材料查看">-->
        <!--              <el-upload-->
        <!--                :action="uploadPath"-->
        <!--                :data="{bizseq:bizseq}"-->
        <!--                :on-remove="removeFile"-->
        <!--                :on-success="uploadCallback"-->
        <!--                :on-preview="previewFile"-->
        <!--                multiple-->
        <!--                :file-list="fileList"-->
        <!--                style="max-width:500px;"-->
        <!--              >-->
        <!--              </el-upload>-->
        <!--            </el-form-item> &ndash;&gt;-->
        <!--            <el-row>-->
        <!--              <el-form-item label="受理环节材料列表" class="upload">-->
        <!--                <ul style="list-style:none;padding:0;margin:5px">-->
        <!--                  <li v-for="item in applyFileList" :key="item.id" style="line-height: 30px">-->
        <!--                    <el-link :href="item.url" target="_blank">{{ item.name }}</el-link>-->
        <!--                  </li>-->
        <!--                </ul>-->
        <!--              </el-form-item>-->
        <!--            </el-row>-->
        <!--            <el-row>-->
        <!--              <el-form-item label="核准环节材料列表" class="upload bt0">-->
        <!--                <ul style="list-style:none;padding:0;margin:5px">-->
        <!--                  <li v-for="item in approvalFileList" :key="item.id" style="line-height: 30px">-->
        <!--                    <el-link :href="item.url" target="_blank">{{ item.name }}</el-link>-->
        <!--                  </li>-->
        <!--                </ul>-->
        <!--              </el-form-item>-->
        <!--            </el-row>-->

        <!--            <el-row class="p10">-->
        <!--              <el-form-item label="核实情况" prop="situation" class="bt0">-->
        <!--                <el-col :span="24">-->
        <!--                  <el-input v-model="tsBizDissentModel.situation" disabled type="textarea" style="width:99%;margin:5px 5px 5px 0" :autosize="{ minRows: 3, maxRows: 6 }" />-->
        <!--                </el-col>-->
        <!--              </el-form-item>-->
        <!--            </el-row>-->
        <!--            <el-row class="p10">-->
        <!--              <el-form-item label="备注" prop="approvalRemark" class="bt0">-->
        <!--                <el-col :span="24">-->
        <!--                  <el-input v-model="tsBizDissentModel.approvalRemark" disabled type="textarea" style="width:99%;margin:5px 5px 5px 0" :autosize="{ minRows: 3, maxRows: 6 }" />-->
        <!--                </el-col>-->
        <!--              </el-form-item>-->

        <!--            </el-row>-->

        <!--            &lt;!&ndash; <el-row>-->
        <!--                <el-col :span="12">-->
        <!--                <el-form-item label="决定文书号" prop="writsno">-->
        <!--                   {{wrirsno}}-->
        <!--                </el-form-item>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12">-->
        <!--                <el-form-item label="联系人" prop="contacts">-->
        <!--                    {{tsBizDissentModel.contacts}}-->
        <!--                </el-form-item>-->
        <!--                </el-col>-->
        <!--            </el-row>-->
        <!--            <el-row>-->
        <!--                <el-col :span="12">-->
        <!--                <el-form-item label="电话" prop="telephone">-->
        <!--                  {{tsBizDissentModel.telephone}}-->
        <!--                </el-form-item>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12">-->
        <!--                <el-form-item label="备注">-->
        <!--                   {{tsBizDissentModel.remarks}}-->
        <!--                </el-form-item>-->
        <!--                </el-col>-->
        <!--            </el-row> &ndash;&gt;-->
        <!--          </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.step +'日期：' + 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="nextNode">
                <el-radio v-model="form.nextNodeID" label="endDissent">通过</el-radio>
                <el-radio v-model="form.nextNodeID" label="overDissent">不通过</el-radio>
                <el-radio v-model="form.nextNodeID" label="approveDissentAccept">回退</el-radio>
              </el-form-item>
            </el-row>

            <el-row class="p10">
              <el-form-item label="审批意见" prop="opinion" class="bt0">
                <el-col :span="24">
                  <el-input v-model="form.opinion" style="width:99%" type="textarea" placeholder="请输入审批意见" :autosize="{ minRows: 2, maxRows: 6 }" />
                </el-col>
                <el-col :span="12">
                  <label>常用语</label>
                  <el-select v-model="opinion" clearable 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>

          </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>
  </div>
</template>

<script>
import DetailHead from '@/components/DetailHead'
import { removeAttachementById, listAttachmentByModelParam } from '@/api/attachment'
import { updatebizDissent, getBizDissentAndWrirsno } from '@/api/abnormal'
import { getUsersWithPermission } from '@/api/user'
import { taskOpinion } from '@/api/task'
import { isMenHu } from '@/utils/utils'

export default {
  components: {
    DetailHead
  },
  data() {
    return {
      tsAbnModel: '',
      tsAbnList: [],
      submitLoading: false,
      tsBizDissentModel: '',
      bizseq: '',
      wrirsno: '',
      workflowId: '',
      uploadPath: `${process.env.VUE_APP_BASE_API}/attachment/uploadAdvanceWithAttachtype`,
      showEntbase: false,
      batchId: this.$route.query.batch,
      form: {
        enterType: 'company',
        nextNodeID: 'endDissent',
        spereasons: '',
        opinion: ''
      },
      formRules: {
        opinion: [
          { required: true, message: '请输入经办意见', trigger: ['blur', 'change'] }
        ]
      },
      opinion: '',
      reasonOptions: [],
      approvalFileList: [],
      applyFileList: [],
      opinionOptions: [{
        value: 0,
        label: '同意。'
      }, {
        value: 1,
        label: '不同意，回退至审核人。'
      }, {
        value: 2,
        label: '不同意。'
      }],
      historyLog: [],
      exmainerOptions: [],
      fileList: [],
      user: JSON.parse(sessionStorage.getItem('user')),
      reviewer: [{
        primaryKey: 0,
        name: '陈彦宇'
      }, {
        primaryKey: 1,
        name: '郭翊'
      }, {
        primaryKey: 2,
        name: '陈文云'
      }, {
        primaryKey: 3,
        name: '王东'
      }]
    }
  },
  watch: {
    // 意见渲染
    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
    this.workflowId = this.$route.query.workflowId
    this.tasklistid = this.$route.query.tasklistid

    // 加载常用语
    this.opinionOptions = this.$util.getCommonWords(this.user.primaryKey)

    getBizDissentAndWrirsno(this.bizseq).then(res => {
      if (res.code === 0) {
        this.tsBizDissentModel = res.data.tsBizDissentModel
        // this.tsBizDissentModel.approvalRemark = res.data.tsBizDissentModel.approvalRemark === null ? '' : res.data.tsBizDissentModel.approvalRemark
        this.wrirsno = res.data.wrirsno
        this.form.situation = this.tsBizDissentModel.situation
        this.form.applyRemark = this.tsBizDissentModel.applyRemark === null ? '' : this.tsBizDissentModel.applyRemark
        this.tsAbnModel = res.data.tsAbnList
        this.tsAbnList.push(res.data.tsAbnList)
      }
    })
    // 加载处办记录
    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
            case '4': each.step = '异议审核'
              break
            case '5': each.step = '异议审批'
              break
          }
          this.historyLog.push(each)
        })
      } else {
        this.$message.error('加载处办记录失败')
      }
    })
    // 加载审核人
    // this.loadReviewer()

    // 加载受理环节附件清单
    listAttachmentByModelParam({ bizseq: 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: {
    // 上传文件预览
    previewFile(file) {
      window.open(file.url, '_blank')
    },
    // 发送提交
    submitForm() {
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.$confirm('是否确认提交？', '提示').then(() => {
          this.submitLoading = true
          this.form.bizseq = this.bizseq
          this.form.workflowid = this.workflowId
          this.form.opiniontype = '5' // 要改
          this.form.handler = this.user.username
          this.form.handlerid = this.user.primaryKey
          this.form.opinioncontent = this.form.opinion
          // 意见： 同意1 不同意0 回退2
          this.form.isagree = this.nextNodeID === 'endDissent' ? '1' : this.nextNodeID === 'overDissent' ? '0' : '2'
          this.form.tasklistid = this.tasklistid
          this.form.nextPerformerids = ''
          this.form.nextPerformerNames = this.user.username
          // for (const i in this.reviewer) {
          //   if (this.reviewer[i].primaryKey === this.form.reviewerId) {
          //     this.form.nextPerformerNames = this.reviewer[i].name
          //   }
          // }
          updatebizDissent(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) {
      if (res.code === 0) {
        file.id = res.data.attachmentid
      }
    },
    // 移除文件前
    beforeRemove(file, fileList) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定移除 ${file.name} ？`)
      }
    },
    // 移除文件回调
    removeFile(file) {
      removeAttachementById(file.id).then(res => {
        if (res.code === 0) {
          this.$message.success('删除成功')
        } else {
          this.$message.error(res.msg)
        }
      })
    }
    // 加载审核人
    // loadReviewer() {
    //   getUsersWithPermission('abnormalReview', 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;
  .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{
  .el-form-item{
    margin-bottom:0;
    background: $color-form-label;
    .el-form-item__label{
      padding-left:  20px;
      font-size: $table-content-font-size;
      border-top: 1px solid $color-border;
    }
    .el-form-item__content{
      font-size: unset;
      background: white;
      padding-left: 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;
    }
  }
  .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-textarea.is-disabled .el-textarea__inner{
    color: #1c1e23;
  }
  .el-step__description{
    font-size: 18px;
  }
}
</style>
