<template>
  <div class="main-content abnormal m20" v-loading.fullscreen.lock="fullscreenLoading">
    <DetailHead result="业务信息" />
    <div class="content-body">
      <el-form ref="form" :model="IlcPunInfo" label-width="230px" label-position="right">
        <div class="form">
          <div class="tab">
            <div class="tab-title">
              <label>行政处罚信息</label>
            </div>
          </div>
          <div class="form-body">
            <el-row class="flex-row">
              <el-col :span="12">
                <el-form-item label="统一社会信用代码/注册号">
                  <span class="span-content">{{ IlcPunInfo.uniscid || IlcPunInfo.zch }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="主体名称">
                  <span style="color: #8cc3fb;cursor: pointer;" @click="toEntDetail" class="span-content">{{ IlcPunInfo.dsrmc }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0 flex-row">
              <el-col :span="12">
                <el-form-item label="决定文书编号">
                  <span class="span-content">{{ IlcPunInfo.sbookcode }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="违法行为类型">
                  <span class="span-content">{{ IlcPunInfo.sgisttypename }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0 flex-row">
              <el-col :span="12">
                <el-form-item label="决定机关名称">
                  <span class="span-content">{{ IlcPunInfo.cfdjjg }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="处罚决定日期">
                  <span class="span-content">{{ $utils.parseTime(IlcPunInfo.cfjdsj, "{yyyy}年{mm}月{dd}日") }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="行政处罚内容">
                <span class="span-content">{{ IlcPunInfo.spuncontent }}</span>
              </el-form-item>
            </el-row>
          </div>
        </div>
      </el-form>
    </div>

    <DetailHead result="业务办理" />
    <div class="content-body">
      <el-form ref="form" :model="punishInfo" label-width="230px" 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 class="flex-row">
              <el-col :span="12">
                <el-form-item label="主体申请修复日期" prop="applyDate">
                  <el-date-picker
                    v-model="punishInfo.applyDate"
                    type="date"
                    :disabled="onlyShow"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="准予修复决定书文号" prop="repairNo">
                  <el-input :readonly="onlyShow" v-model="punishInfo.repairNo"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0 flex-row">
              <el-col :span="12">
                <el-form-item label="信用修复决定时间" prop="repairDate">
                  <el-date-picker
                    v-model="punishInfo.repairDate"
                    type="date"
                    :disabled="onlyShow"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="作出信用修复决定机关" prop="repairOrgCn">
                  <el-input :readonly="true" v-model="punishInfo.repairOrgCn"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row class="bt0">
              <el-form-item label="信用修复决定审批表" class="upload" prop="files_1">
                <el-upload
                  :action="uploadPath"
                  :data="uploadBodyData('1')"
                  :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,.png"
                  multiple
                  :disabled="onlyShow"
                  name="files"
                  ref="files_1"
                  :file-list="fileListDyn('1')"
                  style="max-width:800px;display: inline-block"
                  class="uploadFileList"
                  :class="{disabled: onlyShow}"
                >
                  <div v-if="!onlyShow" style="display: inline-block;">
                    <el-button style="display: inline-block;" size="mini" 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="bt0">
              <el-form-item label="准予信用修复决定文书" class="upload" prop="files_2">
                <el-upload
                  :action="uploadPath"
                  :data="uploadBodyData('2')"
                  :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,.png"
                  multiple
                  :disabled="onlyShow"
                  name="files"
                  :file-list="fileListDyn('2')"
                  ref="files_2"
                  style="max-width:800px;display: inline-block"
                  class="uploadFileList"
                  :class="{disabled: onlyShow}"
                >
                  <div v-if="!onlyShow" style="display: inline-block;">
                    <el-button style="display: inline-block;" size="mini" 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="bt0">
              <el-form-item label="补充材料" class="upload" prop="files_3">
                <el-upload
                  :action="uploadPath"
                  :data="uploadBodyData('3')"
                  :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,.png"
                  multiple
                  :disabled="onlyShow"
                  name="files"
                  ref="files_3"
                  :file-list="fileListDyn('3')"
                  style="max-width:800px;display: inline-block"
                  class="uploadFileList"
                  :class="{disabled: onlyShow}"
                >
                  <div v-if="!onlyShow" style="display: inline-block;">
                    <el-button style="display: inline-block;" size="mini" 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>
          </div>
        </div>
      </el-form>
      <div class="submit-box">
        <template v-if="!onlyShow">
          <el-button type="primary" @click="submit">提交</el-button>
        </template>
        <el-button @click="$router.back()">返回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import DetailHead from '@/components/DetailHead'
import { validBeforeUpload } from '@/api/fileUpload'
import { removeAttachementById } from '@/api/attachment'
import { getInfo, listFile, submitTask } from '@/api/remPunish'
export default {
  data() {
    return {
      fullscreenLoading: false,
      user: JSON.parse(sessionStorage.getItem('user')),
      bizSeq: this.$route.query.bizSeq,
      punishInfo: {},
      IlcPunInfo: {},
      uploadPath: `${process.env.VUE_APP_BASE_API}/punishment/tBizRemPunishment/upload`,
      onlyShow: this.$route.query.onlyShow === '1',
      fileList: [],
      formRules: {
        applyDate: [
          { required: true, message: '请选择主体申请修复日期', trigger: 'blur' }
        ],
        repairNo: [
          { required: true, message: '请录入准予修复决定书文号', trigger: 'blur' }
        ],
        repairDate: [
          { required: true, message: '请选择信用修复决定时间', trigger: 'blur' }
        ],
        repairOrgCn: [
          { required: true, message: '请录入作出信用修复决定机关', trigger: 'blur' }
        ],
        files_1: [
          { required: true, message: '请上传信用修复决定审批表', validator: this.validateFile }
        ],
        files_2: [
          { required: true, message: '请上传准予信用修复决定文书', validator: this.validateFile }
        ],
        files_3: [
          { required: true, message: '请上传补充材料', validator: this.validateFile }
        ]
      }
    }
  },
  computed: {
    uploadBodyData() {
      return (attachType) => {
        return {
          attachType,
          id: this.bizSeq
        }
      }
    },
    fileListDyn() {
      return (attachType) => {
        return this.fileList.filter(item => item.attachtype === attachType)
      }
    }
  },
  mounted() {
    this.fullscreenLoading = true
    getInfo(this.bizSeq).then(res => {
      this.punishInfo = res.data.punishInfo
      this.IlcPunInfo = res.data.IlcPunInfo

      this.punishInfo.repairOrg = this.user.orgCode
      this.punishInfo.repairOrgCn = this.user.orgName

      this.initFileList()
    }).finally(() => {
      this.fullscreenLoading = false
    })
  },
  methods: {
    toEntDetail() {
      this.$router.push({
        path: '/comprehensive/details',
        query: {
          pripid: this.punishInfo.pripid
        }
      })
    },
    validateFile(rule, value, callback) {
      const files = this.$refs[rule.field].uploadFiles
      if (!files.length) {
        callback(new Error(rule.message))
      }
      callback()
    },
    submit() {
      this.$refs.form.validate((valid, rules) => {
        if (!valid) {
          this.$message.warning(rules[Object.keys(rules)[0]][0].message)
          return
        }
        this.$confirm('确定提交后，上述行政处罚信息将从国家企业信用信息公示系统撤下，不再对外公示。').then(() => {
          submitTask(this.punishInfo).then(res => {
            if (res.code === 0) {
              this.$message.success('提交成功')
              this.$router.back()
            }
          })
        })
      })
    },
    initFileList() {
      listFile({ id: this.bizSeq }).then(({ data }) => {
        if (data.length !== 0) {
          this.fileList = data.map((item) => {
            return {
              ...item,
              id: item.attachmentid,
              name: item.filename,
              attachtype: item.attachtype,
              url: `${process.env.VUE_APP_BASE_API}/attachment/download?id=${item.id}`
            }
          })
        }
      })
    },
    // 移除文件前
    beforeRemove(file, fileList) {
      if (file && file.status === 'success') {
        return this.$confirm(`确定移除 ${file.name} ？`)
      }
    },
    // 上传文件之前校验大小
    beforeFileUpload(file) {
      const that = this
      return validBeforeUpload(file, that)
    },
    // 上传文件预览
    previewFile(file) {
      window.open(`${process.env.VUE_APP_BASE_API}/attachment/download?id=${file.id}`, '_blank')
    },
    uploadCallback(res, file) {
      if (res.code === 0) {
        // file.id = res.data[0].attachmentid
        // file.name = res.data[0].filename
        // file.url = `${process.env.VUE_APP_BASE_API}/attachment/download?id=${res.data[0].id}`
        this.$message.success('上传成功')
        this.initFileList()
      }
    },
    // 移除文件回调
    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)
          }
        })
      }
    }
  },
  components: {
    DetailHead
  }
}
</script>

<style lang="scss" scoped>
.el-row.flex-row{
  display: flex;
  .el-col{
    display: flex;
    .el-form-item{
      width: 100%;
      display: flex;
      /deep/ .el-form-item__label{
        flex-shrink: 0;
      }
      /deep/ .el-form-item__content{
        width: 100%;
        min-height: 60px;
        margin-left: 0px!important;
      }
    }
  }
}
.uploadFileList.disabled{
  /deep/ .el-upload{
    display: none;
  }
}
.main-content{
  font-size: $table-content-font-size;
  /deep/ .el-form-item__content{
    padding: 5px;
  }
  .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: $font-size-sub-title;
    }
  }
  .content-body{
    padding:20pt;
    .tab{
      .tab-title{
        text-align: left;
        padding-left: 20px;
        label{
          color: #000;
          font-weight: bold;
          display:inline-block;
        }
      }
    }
    .form{
      margin-bottom: 20pt;
    }
  }
  .span-content{
    display: block;
    text-indent: 1em;
  }
}
.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;
  }
}

.main-content.abnormal{
  .el-form-item{
    margin-bottom:0;
    background: $color-form-label;
    .el-form-item__label{
      padding: 10px;
      border-top: 1px solid $color-border;
      font-size: $table-content-font-size;
    }
    .el-form-item__content{
      font-size: 16px;
      background: white;
      font-size: $table-content-font-size;
      border-top: 1px solid $color-border;
      border-right: 1px solid $color-border;
      border-left: 1px solid $color-border;
      padding: 10px;
    }
  }
  .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.is-disabled .el-input__inner

  .el-input__inner{
    width: 50%;
  }
  .uploadFileList{
    .el-upload-list__item{
      display: inline-block;
      width: auto;
    }
  }
}
@media print{
  /* 浏览区域 */
  .preview-box{
    background-color:#e6e6e6;
    text-align:center;
    border:1PX solid #eee;
    min-height:800PX;
    overflow: hidden;
  }
  .paper-box{
    display: inline-block;
    margin-top:10PX
  }
  .paper{
    width:630PX;
    min-height:891PX;
    background:white;
    padding:40PX 50PX;

  }
  /* 表格 */
  .paper-table>div{border:1PX solid black;border-bottom: none;}
  .paper-table>div:last-child{border-bottom:1PX solid black}
  .row-field:not(:first-child){border-top:1PX solid black}
  .field{min-height: 45PX;border-left:1PX solid black}
  .paper-table td,.paper-table th{
    .right{
      text-align: right;
    }
    font-weight: normal;
    padding: 5PX 5PX;
  }
  /* 标题 */
  .paper-header{text-align: center; line-height: 35PX;}
  .paper-header>h3{font-weight:600;margin:0}
  /* 换行 */
  .enter{margin-top:20PX}
  .enter:before{content:''}
  .right_down{
    text-align: right;
    line-height: 30px;
  }
  .printPaper{
    width:700PX;
    min-height:891PX;
    background:white;
    padding:40PX 50PX;
  }
  .line2{
    border-top: 0px;
    td,th{
      .right{
        text-align: right;
      }
      font-weight: normal;
      padding: 15PX 5PX;
    }
    .mr20 {
      margin-right: 20px;
    }
  }
  .paper-content{
    .firstLine{
      text-align: left;
    }
    .name{
      display: inline-block;
    }
    .downLine{
      border-bottom: solid 1px;
    }
  }
  p {
    // text-indent: 2em;
    text-align: left;
    line-height: 40px; //行间距
    font-size: 24px
  }
  .mr20 {
    margin-right: 20px;
  }
  .printPaper{
    min-height:891PX;
    background:white;
    padding:40PX 50PX;
    .el-divider--horizontal {
      margin: 8px 0;
      background: 0 0;
      border-top: 1px dashed #18191a;
    }
  }
  @page {
    size: auto;
    margin: 0mm;
  }
}
</style>
