<template>
  <div class="main-content abnormal">
    <div class="content-header">
      <img src="../../../../assets/images/icon-text.png" alt="" style="width:24px;margin-left:10px">
      <span class="title">查询结果</span>
    </div>
    <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.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-row>
              <el-form-item label="列异日期" style="border-bottom: 0">
                {{ tsBizDissentModel.abnTime }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="列异原因" style="border-bottom: 0">
                {{ tsBizDissentModel.abnReaCn }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="决定文书号" prop="wrirsno" style="border-bottom: 0;">
                {{ wrirsno }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="联系人" prop="contacts" style="border-bottom: 0;">
                {{ tsBizDissentModel.contacts }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="电话" prop="telephone" style="border-bottom: 0;">
                {{ tsBizDissentModel.telephone }}
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="备注" prop="applyRemark" style="border-bottom: 0;">
                <span style="word-break:normal;display:block;word-wrap:break-word;overflow: hidden;">{{ tsBizDissentModel.applyRemark ==='null' ? '' : tsBizDissentModel.applyRemark }}</span>
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="材料查看">
                <ul style="list-style:none;padding:0;margin:5px">
                  <li v-for="item in fileList" :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>
          </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="acceptstat">
                <span v-if="tsBizDissentModel.acceptstat === '1'">拟受理</span>
                <span v-if="tsBizDissentModel.acceptstat === '0'">拟不予受理</span>
              </el-form-item>
            </el-row>
            <el-row>
              <el-form-item label="是否受理" prop="nextNode" class="bt0">
                <el-radio v-model="form.nextNodeID" label="approveDissent">受理</el-radio>
                <el-radio v-model="form.nextNodeID" label="endDissent">不予受理</el-radio>
                <el-radio v-model="form.nextNodeID" label="acceptDissentEnter">回退</el-radio> <!--回退至受理经办 -->
              </el-form-item>
            </el-row>
            <el-row class="opinion">
              <el-form-item label="审核意见" prop="opinion" class="bt0">
                <el-col :span="24" style="margin-bottom:10px">
                  <el-input v-model="form.opinion" type="textarea" placeholder="请输入审核意见" :autosize="{ minRows: 2, maxRows: 6 }" />
                </el-col>
                <el-col :span="24">
                  <label>常用语</label>
                  <el-select v-model="opinion" placeholder="请选择" clearable class="custom" style="margin-left: 10px">
                    <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-form-item v-if="form.nextNodeID == 'approveDissent'" label="后续处理人" prop="reviewerId">
              <el-select v-model="form.reviewerId" clearable filterable placeholder="请选择后续处理人" class="custom">
                <el-option
                  v-for="item in reviewer"
                  :key="'reviewer'+item.primaryKey"
                  :label="item.name"
                  :value="item.primaryKey"
                />
              </el-select>
            </el-form-item> -->
          </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 { 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: {
  },
  data() {
    return {
      submitLoading: false,
      tsBizDissentModel: '',
      wrirsno: '',
      bizseq: '',
      workflowId: '',
      uploadPath: `${process.env.VUE_APP_BASE_API}/attachment/uploadAdvance`,
      showEntbase: false,
      batchId: this.$route.query.batch,
      form: {
        enterType: 'company',
        nextNodeID: 'approveDissent',
        spereasons: '',
        opinion: ''
      },
      formRules: {
        opinion: [
          { required: true, message: '请输入经办意见', trigger: ['blur', 'change'] }
        ],
        reviewerId: [
          { required: true, message: '请选择审核人' }
        ]
      },
      opinion: '',
      reasonOptions: [],
      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.wrirsno = res.data.wrirsno
      }
    })

    // 加载处办记录
    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
          }
          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 = '1'
          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.form.nextNodeID === 'approveDissent' ? '1' : this.nextNodeID === 'endDissent' ? '0' : '2'
          this.form.tasklistid = this.tasklistid
          this.form.nextPerformerids = this.form.reviewerId
          this.form.acceptstat = this.form.nextNodeID === 'approveDissent' ? '1' : '0' // 受理状态 "0不受理"
          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(() => {})
      })
    },
    // 移除文件回调
    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;
  padding: 10pt;
  .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:  $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;
}
.bt0 {
  /deep/.el-form-item__label{
      border-top:0!important;
    }
  /deep/.el-form-item__content{
    border-top:0!important;
  }
}
/deep/.opinion .el-form-item__content{
 padding: 10px;
}
</style>
<style lang="scss">
.main-content.abnormal{

  .el-form-item{
    margin-bottom:0;
    background: $color-form-label;
    .el-form-item__label{
      padding-left:  20px;
      border-top: 1px solid $color-border;
      font-size:  $table-content-font-size;
    }
    .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>
