<template>
  <a-form
    :rules="rules"
    :model="problemForm"
    :label-col="{span: 8}"
    :wrapper-col="{span: 16}"
    class="wtzgfc_add_pblm"
    ref="problemForm">
    <a-card>
      <p class="p_title">问题整改情况</p>
      <a-form-item label="问题类别" style="text-align:left">
        <a-input placeholder="请输入内容" v-model:value="problemForm.pblmType" class="w30" />
      </a-form-item>
      <a-form-item label="检查项目" style="text-align:left">
        <a-input placeholder="请输入内容" v-model:value="problemForm.pblmOption" class="w30" />
      </a-form-item>
      <a-form-item label="问题描述">
        <a-textarea placeholder="请输入内容" :rows="2" v-model:value="problemForm.pblmDesc" class="w30" />
      </a-form-item>
      <a-form-item label="问题等级" style="text-align:left">
        <a-select v-model:value="problemForm.pblmLevl" placeholder="请选择" allow-clear>
          <a-select-option v-for="item in supervisionState" :key="item.value" :value="item.value">{{ item.label }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="整改措施" style="text-align:left" required>
        <a-input placeholder="请输入内容" v-model:value="problemForm.rectMsrs" class="w30" />
      </a-form-item>
    </a-card>
    <a-card>
      <p class="p_title">佐证材料</p>
      <a-form-item v-if="!problemForm.zcOtherIsMakeFiles.length" class="zzcl_fj" >
        <uploadZz
          ref="uploadZzcl"
          :url="`/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/file/insert?bizId=${currentObjectRgstrId}&bizType=MEND_PROV`"
          accept=".pdf,.PDF,.doc,.DOC,.DOCX,.docx,.excel,.EXCEL"
          @uploadOver="removeNewSupervisionZcOtherIsMake"></uploadZz>
      </a-form-item>
      <a-form-item label="上传列表" v-if="problemForm.zcOtherIsMakeFiles.length">
        <ul v-for="(item,index) in problemForm.zcOtherIsMakeFiles" :key="index">
          <li style="list-style: none;">
            <a-button type="link" class="w300">{{ item.fileName }}</a-button>
            <a-button type="link" @click="rowPreview(item)">下载</a-button>
            <a-button type="link" @click="rowDelete(item,index,'qt')" class="font_red">删除</a-button>
          </li>
        </ul>
      </a-form-item>
    </a-card>
    <a-card style="margin-top: 20px;">
      <p class="p_title">复核情况</p>
      <a-form-item label="整改状态" style="text-align:left">
        <a-radio-group v-model:value="problemForm.revwRectConc">
          <a-radio value="1">未整改</a-radio>
          <a-radio value="2">正在整改</a-radio>
          <a-radio value="3">整改完成</a-radio>
          <br />
          <br />
          <a-radio value="4">整改不到位</a-radio>
          <a-radio value="5">上报整改情况与实际不符</a-radio>
        </a-radio-group>
      </a-form-item>
      <a-form-item :label="problemForm.revwRectConc == 3 ? '实际整改完成时间' : problemForm.revwRectConc == 2 ? '计划整改完成时间': ''" style="text-align:left" v-if="(Number(problemForm.revwRectConc) === 2 || Number(problemForm.revwRectConc) === 3) && problemForm.revwRectConc">
        <a-date-picker v-model:value="problemForm.realPlanDt" placeholder="选择日期" class="w30" v-if="(Number(problemForm.revwRectConc) === 2 || Number(problemForm.revwRectConc) === 3) && problemForm.revwRectConc"></a-date-picker>
      </a-form-item>
      <div>
        <a-form-item label="备注" v-if="problemForm.revwRectConc != 3">
          <a-textarea placeholder="请输入" v-model:value="problemForm.revwRectPblm" :rows="4" class="w30" />
        </a-form-item>
        <a-form-item label="备注" prop="revwRectPblm" v-else key="revwRectPblm">
          <a-textarea placeholder="请输入" v-model:value="problemForm.revwRectPblm" :rows="4" class="w30" />
        </a-form-item>
      </div>
    </a-card>
    <a-card>
      <p class="p_title">多媒体</p>
      <upload ref="uploadFile" :url="`/pdcApi/file/insert?bizType=MEND_EXTRA&bizId=`" @uploadOver="removeNewSupervision">
      </upload>
    </a-card>
    <a-form-item :wrapper-col="{ span: 16, offset: 8 }" style="margin-top: 50px">
      <a-button type="primary" @click="onSubmit('problemForm')" style="width: 100px;float:right" :loading="saveLoading">保存</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { hostUrl } from '../../../../utils/global_variable';
import request from '../../../../utils/gw_ajax_request';
import upload from '../../../../widgets/uploadFile.vue';
import uploadZz from '../../../../widgets/uploadPdf.vue';
export default {
  props: [
    'objId',
    'objName',
    'villType',
    'objType',
    'problemMiddleType',
    'problemSmallType',
    'engId',
    'currentObjectRgstrId',
    'problData',
    'currentProblemId',
    'currentResCode',
    'currentAdCode',
    'currentRsvrNm',
  ],
  data() {
    return {
      problemForm: {
        pblmDesc: '', // 问题描述 ,
        pblmLevl: '', // 问题等级 ,
        pblmOption: '', // 检查项目 ,
        pblmSn: '', // 问题序号 ,
        pblmType: '', // 问题类别 ,
        proName: '', // 省 ,
        realPlanDt: '', // 实际/计划整改完成时间 ,
        rectConc: '', // 整改状态(1:未整改;2:正在整改;3:已整改) ,
        rectMsrs: '', // 整改措施 ,
        revwInfo: '', // 复核情况 ,
        revwRectConc: '', // 复核整改状态(1:未整改;2:正在整改;3:整改完成;4:整改不到位;5:上报整改情况与实际不符) ,
        revwRectPblm: '', // 复核整改问题 ,
        revwState: '', // 复核填报状态(0:未填报;1:填报中;2:已填报) ,
        rgstrId: '', // 登记表ID ,
        rsCode: '', // 水库编码 ,
        rsName: '', // 水库名称 ,
        safeComment: '', // 工况总体评价 ,
        unit: '', // 管理单位 ,
        uptm: '', // 修改时间 ,
        year: '', // 年度
        gwComFiles: [],
        zcOtherIsMakeFiles: [],
        auditConc: '', // 审核状态
      },
      supervisionState: [
        {
          value: '0',
          label: '一般',
        },
        {
          value: '1',
          label: '较重',
        },
        {
          value: '2',
          label: '严重',
        },
        {
          value: '3',
          label: '特别严重',
        },
      ],
      abarbeitungStatusList: [
        {
          label: '未填写',
          value: '0',
        },
        {
          label: '未整改',
          value: '1',
        },
        {
          label: '正在整改',
          value: '2',
        },
        {
          label: '已整改',
          value: '3',
        },
      ],
      expertReviewList: [
        {
          label: '审核已整改',
          value: '1',
        },
        {
          label: '审核未整改',
          value: '2',
        },
        {
          label: '未审核',
          value: '3',
        },
        {
          label: '审核正在整改',
          value: '4',
        },
      ],
      inspPblmCate: '',
      imgList: [],
      videoList: [],
      audioList: [],
      pblmStat: '',
      gwComFiles: [],
      problemList: [],
      currentCheckPointList: [
        {
          value: '1',
          label: '质量安全',
        },
        {
          value: '2',
          label: '合同',
        },
        {
          value: '3',
          label: '资金',
        },
      ],
      currentProblemDescList: [
        {
          value: '1',
          label: '项目法人（建设单位）',
        },
        {
          value: '2',
          label: '勘察设计单位',
        },
        {
          value: '3',
          label: '监理单位',
        },
        {
          value: '4',
          label: '施工单位',
        },
        {
          value: '5',
          label: '金属结构及机电设备安装单位',
        },
        {
          value: '6',
          label: '安全监测单位',
        },
        {
          value: '7',
          label: '质量检测单位',
        },
      ],
      t1: '',
      t2: '',
      t3: '',
      xiangqingmiaoshu: '',
      wenTiLeiBie: '',
      jianChaXiangMu: '',
      rules: {
        revwRectPblm: [
          {
            required: true,
            message: '请填写备注',
            trigger: 'blur',
          },
        ],
      },
      saveLoading: false,
    };
  },
  components: {
    upload,
    uploadZz,
  },
  computed: {
    recPers() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {},
  methods: {
    async onSubmit(problemForm) {
      this.$refs[problemForm].validate((valid) => {
        if (valid) {
          this.problemForm.recPers = this.recPers;
          this.problemForm.rgstrId = this.currentObjectRgstrId;
          this.problemForm.rsName = this.currentRsvrNm;
          this.problemForm.adCode = this.currentAdCode;
          this.problemForm.rsCode = this.currentResCode;
          this.problemForm.revwState = '2'; // 只要添加问题就是已复核状态
          if (!this.problemForm.revwRectConc) {
            this.$message.warning('请选择整改状态');
            return;
          }
          if (!this.problemForm.rectMsrs) {
            this.$message.warning('请填写整改措施');
            return;
          }
          // if (!this.problemForm.auditConc) {
          //   this.$message.warning('请选择审核状态');
          //   return;
          // }
          this.$nextTick(() => {
            if (this.$refs.uploadFile.submitUpload(this.currentObjectRgstrId)) {
              this.removeNewSupervision();
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 文件上传
    submitUpload() {
      this.$refs.upload.submit();
    },
    // updatefilelist(arg) {
    //   request.post('/dc/insp/pblm/update', {
    //     pblmId: this.pblmId,
    //     gwComFiles: arg,
    //     pblmStat: this.pblmStat
    //   }).then(res => {
    //     this.removeNewSupervision()
    //   });
    // },
    removeNewSupervision(arg) {
      if (arg) {
        this.problemForm.gwComFiles = this.problemForm.gwComFiles.concat(arg);
      }
      if (!this.saveLoading) {
        this.saveLoading = true;
        this.problemForm.gwComFiles = [
          ...this.problemForm.gwComFiles,
          ...this.problemForm.zcOtherIsMakeFiles,
        ];
        delete this.problemForm.zcOtherIsMakeFiles;
        request
          .post('bis/insp/rsvr/pblm/mend/2021/update', this.problemForm)
          .then((res) => {
            if (res.success) {
              this.$message.success('保存成功');
              this.$emit('closeDialog');
              this.$refs.uploadFile.init();
            }
            this.saveLoading = false;
          })
          .catch((err) => {
            this.saveLoading = false;
          });
      }
    },
    removeNewSupervisionZcOtherIsMake(arg) {
      this.$nextTick(() => {
        if (arg.length) {
          let len = this.problemForm.zcOtherIsMakeFiles.length;
          for (var i = 0; i < arg.length; i++) {
            this.$set(this.problemForm.zcOtherIsMakeFiles, len, arg[i]);
            len++;
          }
        }
      });
    },
    rowPreview(row) {
      window.open(`${hostUrl}${row.filePath}`, '_blank');
    },
    rowDelete(row, index) {
      this.$confirm({
        title: '提示',
        content: `确定要删除'${row.fileName}', 是否继续?`,
        okType: 'warning',
        onOk: () => {
          request.post(`/file/${row.id}`).then((res) => {
            if (res.success) {
              this.$message.success('删除成功');
              this.problemForm.zcOtherIsMakeFiles.splice(index, 1);
            } else {
              this.$message.warning(res.message);
            }
          });
        },
        cancel: () => {
          this.$message.info('已取消删除');
        },
      });
    },
  },
};
</script>

<style lang='less' scoped>
.wtzgfc_add_pblm {
  .w30 {
    width: 50%;
  }

  .el-textarea {
    display: block !important;
  }

  p.p_title {
    text-align: left;
    font-weight: bold;
  }

  .el-radio {
    margin-bottom: 15px;
  }

  .zzcl_fj>div {
    margin: 0 !important;
  }

  .zzcl_fj>div>div {
    margin: 0 !important;
    display: inline-block;
    width: 80px !important;
  }

  .w300 {
    width: 180px;
    text-align: left;
  }
}
</style>
