<template>
  <el-dialog
    width="50%"
    title="复查结果录入"
    @close="closeModal"
    :close-on-click-modal="false"
    v-model="changeSupervisionVisible" :append-to-body="true">
    <el-form ref="problemForm" :rules="rules" :model="problemForm" label-width="260px" class="wtzgfc_add_pblm">
      <el-card>
        <p class="p_title">复查情况</p>
        <el-form-item label="整改情况" required>
          <el-input type="textarea" :rows="10" placeholder="请输入内容" v-model="problemForm.pblmMendNote" class="w30">
          </el-input>
        </el-form-item>
        <el-form-item label="整改结果:" style="text-align:left" required>
          <el-radio-group v-model="problemForm.pblmMendState">
            <el-radio label="1">已整改落实</el-radio>
            <el-radio label="2">部分整改落实</el-radio>
            <br/>
            <br/>
            <el-radio label="3">未整改</el-radio>
            <el-radio label="4">不具备整改条件</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-card>
      <el-card style="margin: 20px 0;">
        <p class="p_title">佐证材料</p>
        <el-form-item class="zzcl_fj">
          <uploadZz
            ref="uploadZzcl"
            :url="`/pdcApi/file/insert?bizId=${problData.rgstrId}&bizType=MEND_PROV`"
            accept=".pdf,.PDF,.doc,.DOC,.DOCX,.docx,.excel,.EXCEL"
            @uploadOver="removeNewSupervision"
          ></uploadZz>
          <!--url="`/pdcApi/file/insert?bizId=${addObj.id}&bizType=zcWaterIsMake`"-->
          <!--<upload ref="uploadFile" :url="`/pdcApi/file/insert?bizId=`" @uploadOver="removeNewSupervision"></upload>-->
        </el-form-item>
        <el-form-item label="上传列表" v-if="problemForm.gwComFiles.length">
          <ul v-for="(item,index) in problemForm.gwComFiles" :key="index">
            <li style="list-style: none;" v-if="item.bizType == 'MEND_PROV'">
              <el-button type="text" class="w300">{{ item.fileName }}</el-button>
              <el-button type="text" @click="rowPreview(item)">下载</el-button>
              <el-button type="text" @click="rowDelete(item,index,'qt')" class="font_red">删除</el-button>
            </li>
          </ul>
        </el-form-item>
      </el-card>
      <el-row>
        <el-form-item style="margin: 20px">
          <el-button type="primary" @click="onSubmit('problemForm')" style="width: 100px;float:right"
                     :loading="saveLoading">保存
          </el-button>
        </el-form-item>
      </el-row>

    </el-form>

  </el-dialog>
</template>

<script>
  import request from '@/utils/gw_ajax_request.js'
  import {hostUrl} from '@/utils/global_variable'
  import {showDetailsXq1} from "@/api/InspectionReport.js";

  export default {
    props: ['objId', 'objName', 'villType', 'objType', 'problemMiddleType', 'problemSmallType', 'engId', 'currentObjectRgstrId', 'problData', 'currentProblemId', 'currentResCode', 'currentAdCode', 'currentRsvrNm', 'problemId'],
    data() {
      return {
        problemForm: {
          "rgstrId": this.problData.rgstrId,
          "objId": this.problData.objId,
          "id": this.problData.id,
          "taskId": "",
          "stepId": "",
          "oldPblmId": "",
          "pblmMendNote": "",
          "pblmMendState": "",
          "gwComFiles": []
        },
        inspPblmCate: "",
        imgList: [],
        videoList: [],
        audioList: [],
        pblmStat: '',
        gwComFiles: [],
        problemList: [],
        t1: '',
        t2: '',
        t3: '',
        xiangqingmiaoshu: '',
        wenTiLeiBie: "",
        jianChaXiangMu: "",
        rules: {
          inspPblmDesc: [{
            required: true,
            message: '请输入描述',
            trigger: 'blur'
          },

          ],
        },
        saveLoading: false,
        changeSupervisionVisible: true
      }
    },
    components: {
      uploadZz: resolve => {
        require(["@widget/uploadPdf.vue"], resolve);
      }
    },
    computed: {
      recPers() {
        return localStorage.getItem('userid') ? localStorage.getItem('userid') : '';
      }
    },
    mounted() {
      this.changeSup(this.problemId)
    },
    methods: {
      async onSubmit(problemForm) {
        this.$refs[problemForm].validate((valid) => {
          if (valid) {
            this.problemForm["recPers"] = this.recPers;
            if (!this.problemForm.pblmMendNote) {
              this.$message.warning('请填写整改情况');
              return;
            }
            if (!this.problemForm.pblmMendState) {
              this.$message.warning('请选择整改结果');
              return;
            }
            // 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.rectConc) {
            //   this.$message.warning('请选择整改状态');
            //   return;
            // }
            // if (!this.problemForm.rectMsrs) {
            //   this.$message.warning('请填写整改措施');
            //   return;
            // }
            // if (!this.problemForm.auditConc) {
            //   this.$message.warning('请选择审核状态');
            //   return;
            // }
            this.$nextTick(() => {
                this.removeNewSupervision();
            })

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      // 文件上传
      submitUpload() {
        this.$refs.upload.submit();
      },
      removeNewSupervision(arg) {

        if (arg) {
          let len = this.problemForm.gwComFiles.length;
          for (var i = 0; i < arg.length; i++) {
            this.$set(this.problemForm.gwComFiles, len, arg[i]);
            len++;
          }
        }
        if (!this.saveLoading) {
          this.saveLoading = true;
          request.post('/tac/province/pblm/info', this.problemForm).then(res => {
            if (res.success) {
              this.$message.success('保存成功');
              this.$emit('dialogClose');
              this.$refs.uploadZzcl.init();
            }
            this.saveLoading = false;
          }).catch(err => {
            this.saveLoading = false;
          });
        }

      },
      rowPreview(row) {
        window.open(`${hostUrl}${row.filePath}`, "_blank");
      },
      rowDelete(row, index) {
        this.$confirm(`确定要删除'${row.fileName}', 是否继续?`, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          request.post(`/file/${row.id}`)
            .then(res => {
              if (res.success) {
                this.$message.success("删除成功");
                this.problemForm.gwComFiles.splice(index, 1);
              } else {
                this.$message.warning(res.message);
              }
            })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      closeModal() {
        this.$emit('dialogClose')
      },
      // 修改弹窗显示
      changeSup(id) {
        // this.pictureArray = [];
        // this.audioArray = [];
        // this.videoArray = [];
        // this.fileArray = [];
        // this.updateIdXiuGai = id;
        showDetailsXq1(id).then(res => {

          // if(this.usersId==)
          this.problemForm = res.data;
          this.problemForm.gwComFiles = res.data.gwComFileList;
          // this.gwComFiles = res.data.gwComFileList;
          // this.keyword = this.changeSupervision.tacObjPblmstb ? this.changeSupervision.tacObjPblmstb.id : ''
          // if (this.changeSupervision.pblmSubjectList) {
          //   this.unitArray = this.changeSupervision.pblmSubjectList
          // }
          // if (this.changeSupervision.tacObjPblmstb) {
          //   this.objSubjectList = this.changeSupervision.tacObjPblmstb.objSubjectList
          //   this.cateObjList = this.changeSupervision.tacObjPblmstb.cateObjList
          //   this.changeSupervision.pblmsDesc = this.changeSupervision.tacObjPblmstb.pblmsDesc
          //   this.changeSupervision.relativeLaw = this.changeSupervision.tacObjPblmstb.relativeLaw
          //   this.changeSupervision.lawContent = this.changeSupervision.tacObjPblmstb.lawContent
          //   this.changeSupervision.note = this.changeSupervision.tacObjPblmstb.note
          // this.changeSupervision.pblmQlttvCd = this.changeSupervision.pblmQlttvCd ? this.changeSupervision.pblmQlttvCd.toString() : ''
          // this.relCode = this.changeSupervision.pblmNm.substr(0, 3)
          // if (this.unitArray.length) {
          //   this.unitArray.forEach((ele, index) => {
          //     _this.getUnitNameList(index)
          //   })
          // }
          // res.data.gwComFileList.forEach(item => {
          //   if (
          //     item.fileExt == "mp3" ||
          //     item.fileExt == "MP3" ||
          //     item.fileExt == "m4a"
          //   ) {
          //     this.audioArray.push(item);
          //   } else if (
          //     item.fileExt == "jpg" ||
          //     item.fileExt == "JPG" ||
          //     item.fileExt == "png" ||
          //     item.fileExt == "PNG" ||
          //     item.fileExt == "JPEG" ||
          //     item.fileExt == "jpeg"
          //   ) {
          //     this.pictureArray.push(item);
          //   } else if (item.fileExt == "mp4" || item.fileExt == "MP4") {
          //     this.videoArray.push({
          //       width: "130",
          //       height: "130",
          //       autoplay: false,
          //       muted: true,
          //       language: "en",
          //       playbackRates: [0.7, 1.0, 1.5, 2.0],
          //       sources: [
          //         {
          //           type: "video/mp4",
          //           src: this.hostUrl + item.filePath
          //         }
          //       ],
          //       id: item.id
          //     });
          //   } else {
          //     this.fileArray.push(item);
          //   }
          // });
          //
          // this.picturetabName = "图片资料(" + this.pictureArray.length + ")";
          // this.audiotabName = "音频资料(" + this.audioArray.length + ")";
          // this.videotabName = "视频资料(" + this.videoArray.length + ")";
          // this.filetabName = "其它资料(" + this.fileArray.length + ")";
        });
      },

    }
  }
</script>

<style >
  .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>
