<template>
  <a-modal
    v-model:visible="dialogVisible"
    @ok="saveRectifyInfo"
    @cancel="closeDialog"
    :confirm-loading="loadingStat"
    title="整改信息录入"
    width="60%"
    class="outerDialog custom_dialog">
    <a-form :model="RectInfo" :label-col="{span: 8}" :wrapper-col="{span: 15}" ref="RectifyInfoForm">
      <a-form-item label="整改材料" prop="fileName">
        <upload ref="uploadFile" :url="`/file/insert?bizId=`" :type="2" @uploadOver="removeNewSupervision" />
      </a-form-item>
      <a-form-item label="整改描述" prop="zgZgxx">
        <a-textarea v-model:value="RectInfo.zgZgxx" :rows="8"/>
      </a-form-item>
    </a-form>
    <span slot="okText">{{ loadingStatText }}</span>
  </a-modal>
</template>

<script>
import { hostUrl } from '../../../utils/global_variable';
import request from '../../../utils/gw_ajax_request';
import upload from '../../../widgets/uploadFileWithType';

export default {
  props: ['pblmId'],
  components: {
    upload,
  },
  data() {
    return {
      currentDate: parseInt(new Date().getDate()),
      RectInfo: {
        id: '',
        fileName: '',
        zgZgxx: '',
      },
      loadingStat: false,
      loadingStatText: '提交',
      rules: {
        zgZgxx: [
          { required: true, message: '请输入整改描述', trigger: 'blur' },
        ],
      },
      uuid: '',
      persId: localStorage.getItem('persId'),
      uploadFileUrl: '',
      dialogImageUrl: '',
      dialogVisible: true,
    };
  },
  computed: {
    hostUrl() {
      return hostUrl;
    },
  },
  created() {},
  methods: {
    saveRectifyInfo() {
      this.$refs.RectifyInfoForm.validate((valid) => {
        if (valid) {
          this.$nextTick(() => {
            this.$refs.uploadFile.submitUpload(this.pblmId);
          });
          this.$emit('saveRectifyInfo', this.RectInfo);
          this.$refs.RectifyInfoForm.resetFields();
          // if (this.RectInfo.zgZgxx){
          //   this.$emit("saveRectifyInfo", this.RectInfo);
          // }else{
          //    this.$message.warning("请填写整改描述!");
          //    return false;
          // }
        } else {
          return false;
        }
      });
    },
    closeDialog() {
      this.$emit('closePblmRectifyInfoDialog');
    },
    beforeClose(done) {
      /* this.$confirm('确认关闭？')
        .then(_ => {
          this.$emit("saveRectifyInfo", this.RectInfo);
          //sthis.dialogVisible = false;
          done();
        })
        .catch(_ => {
        }); */
      // this.dialogVisible = false;
      done();
    },
    getUUID() {
      request.get('/socket/uuid').then((res) => {
        if (res.success) {
          this.uuid = res.data.key;
          this.uploadFileUrl = `/pdcApi/dc/impExcel/imp/${this.persId}/${this.uuid}?tid=08`;
        } else {
          console.log('success不为true');
        }
      });
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    removeNewSupervision(arg) {
      if (arg) {
        console.log(arg);
        // let args = this.gwComFiles.concat(arg);
        // this.updatefilelist(args);
      }
      // this.$emit("saveRectifyInfo", this.RectInfo);
      // this.$refs.RectifyInfoForm.resetFields();
      // this.$message.success('保存成功');
      this.$refs.uploadFile.init();
    },
  },
};
</script>

<style lang='less' scoped>

</style>
