<template>
  <a-modal
    v-model="dialogVisible"
    @ok="saveRectifyInfo"
    @cancel="closeDialog"
    :confirm-loading="loadingStat"
    title="编辑信息"
    width="60%"
    class="outerDialog custom_dialog">
    <a-form :model="RectInfo" :rules="rules" :label-col="{span: 10}" :wrapper-col="{span: 14}" ref="RectifyInfoForm">
      <a-form-item label="问题编码" prop="fileNoNumber">
        <a-input v-model:value="RectInfo.fileNoNumber" disabled/>
      </a-form-item>
      <a-form-item label="问题" prop="inspPblmDesc">
        <a-input v-model:value="RectInfo.inspPblmDesc" />
      </a-form-item>
      <a-form-item label="问题详情" prop="problemDetails">
        <a-input v-model:value="RectInfo.problemDetails" />
      </a-form-item>
      <a-form-item label="问题来源" prop="pblmSource">
        <a-input v-model:value="RectInfo.pblmSource" />
      </a-form-item>
      <a-form-item label="工程名称" prop="nm">
        <a-input v-model:value="RectInfo.nm" />
      </a-form-item>
      <a-form-item label="县（市、区）" prop="adName">
        <a-tree-select
          v-model:value="RectInfo.adName"
          :tree-data="treeData"
          :fieldNames="defaultProps"
          show-search
          :dropdown-style="{ maxHeight: '300px', overflow: 'auto' }"
          @select="addvTreeNodeClick"
          allow-clear />
        <!-- <a-input v-model:value="RectInfo.adName" @focus="showSelet()" @clear="clearEvent()"/>
        <addvSearch
          ref="myAddvcd"
          :maxHeight="300"
          :maxWidth="250"
          @addvTreeNodeClick="addvTreeNodeClick"
          :rootAddCode="curAdcode_long"
          :level="&quot;3&quot;"
          :nameOrCode="''"></addvSearch> -->
      </a-form-item>
      <a-form-item label="设区市/直管县" prop="upAdName">
        <a-input v-model:value="RectInfo.upAdName" />
      </a-form-item>
      <a-form-item label="问题印发文件名" prop="zgMemo">
        <a-input v-model:value="RectInfo.zgMemo" />
      </a-form-item>
      <a-form-item label="问题来源时间" prop="pblmSourceTm">
        <a-input v-model:value="RectInfo.pblmSourceTm" />
      </a-form-item>
      <a-form-item label="问题印发文号" prop="zgWjName">
        <a-input v-model:value="RectInfo.zgWjName" />
      </a-form-item>
      <a-form-item label="问题印发时间" prop="issuedTm">
        <a-input v-model:value="RectInfo.issuedTm" />
      </a-form-item>
      <a-form-item label="责任处室（单位）">
        <a-input v-model:value="RectInfo.dutyDept" />
      </a-form-item>
      <a-form-item label="问题归类">
        <a-select v-model:value="RectInfo.objType" placeholder="问题归类" allow-clear>
          <a-select-option v-for="item in duChaTypes" :key="item.NM" :value="item.NM">{{ item.NM }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="问题是否已销号">
        <a-select v-model:value="RectInfo.isPblmDel" placeholder="请选择" allow-clear>
          <a-select-option value="1">是</a-select-option>
          <a-select-option value="0">否</a-select-option>
          <!-- <a-select-option value="2">已立行立改</a-select-option> -->
        </a-select>
      </a-form-item>
      <a-form-item label="是否进入稽察流程">
        <a-select v-model:value="RectInfo.isJcFlow" placeholder="请选择" allow-clear>
          <a-select-option value="1">是</a-select-option>
          <a-select-option value="0">否</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="整改要求" prop="pblmSggtn">
        <a-textarea v-model:value="RectInfo.pblmSggtn" />
      </a-form-item>
      <a-form-item label="销号时间" prop="isPdTm">
        <a-date-picker v-model:value="RectInfo.isPdTm" placeholder="选择日期" format="YYYY-MM-DD" style="width: 100%;" />
      </a-form-item>
      <a-form-item label="调度年份" prop="schdYear">
        <a-date-picker
          v-model:value="RectInfo.schdYear"
          :open="isOpen"
          @change="onChange"
          @panelChange="panelYearChange"
          @openChange="handYearChange"
          mode="year"
          placeholder="选择日期"
          format="YYYY"
          style="width: 100%;" />
      </a-form-item>
      <a-form-item label="初始整改时限" prop="firstZgTm">
        <a-date-picker v-model:value="RectInfo.firstZgTm" format="YYYY-MM-DD" placeholder="选择日期" style="width: 100%;" />
      </a-form-item>
      <a-form-item label="年度初始整改时限" prop="nlZgDate">
        <a-date-picker v-model:value="RectInfo.nlZgDate" format="YYYY-MM-DD" placeholder="选择日期" style="width: 100%;" />
      </a-form-item>
      <a-form-item label="当前要求整改完成时限" prop="issuedTm">
        <a-date-picker v-model:value="RectInfo.zgDate" format="YYYY-MM-DD" placeholder="选择日期" style="width: 100%;" />
      </a-form-item>
      <a-form-item label="申请销号时间" prop="applyPdTm">
        <a-date-picker v-model:value="RectInfo.applyPdTm" format="YYYY-MM-DD" placeholder="选择日期" style="width: 100%;" />
      </a-form-item>
      <a-form-item label="是否按期销号" prop="isPdSche">
        <a-input v-model:value="RectInfo.isPdSche" />
      </a-form-item>
      <a-form-item label="最新申请延期月份" prop="psDlyTm">
        <a-input v-model:value="RectInfo.psDlyTm" />
      </a-form-item>
      <a-form-item label="整改工作进展情况" prop="zgDevelopment">
        <a-textarea v-model:value="RectInfo.zgDevelopment" />
      </a-form-item>
      <a-form-item label="是否申请销号" prop="isApplyPd">
        <a-input v-model:value="RectInfo.isApplyPd" />
      </a-form-item>
      <a-form-item label="责任处室（单位）是否同意销号" prop="isDeptagePd">
        <a-input v-model:value="RectInfo.isDeptagePd" />
      </a-form-item>
      <a-form-item label="责任处室（单位）不同意销号原因" prop="deptagePdEln">
        <a-textarea v-model:value="RectInfo.deptagePdEln" />
      </a-form-item>
      <a-form-item label="进一步明确整改要求" prop="zgRedefineReq">
        <a-textarea v-model:value="RectInfo.zgRedefineReq" />
      </a-form-item>
      <a-form-item label="整改描述">
        <a-textarea v-model:value="RectInfo.zgZgxx" />
      </a-form-item>
      <a-form-item label="整改时限延期说明" prop="zgDelayEln">
        <a-textarea v-model:value="RectInfo.zgDelayEln" />
      </a-form-item>
      <a-form-item label="问题被通报次数" prop="informedNum">
        <a-input v-model:value="RectInfo.informedNum" />
      </a-form-item>
      <a-form-item label="整改文件" prop="fileName">
        <upload ref="uploadFile" :url="`/file/insert?bizId=`" :type="2" @uploadOver="removeNewSupervision" />
      </a-form-item>
    </a-form>
    <span slot="okText">{{ loadingStatText }}</span>
  </a-modal>
</template>

<script>
import moment from 'moment';
import { getAddTree } from '../../../api/duChaAPI';
import {
  curAdcode_long,
  curAdcode_short,
  hostUrl,
} from '../../../utils/global_variable';
import request from '../../../utils/gw_ajax_request';
import addvSearch from '../../../widgets/addvSearchCon.vue';
import upload from '../../../widgets/uploadFileWithType';
import { getDuChaResource } from '../Common/rectify_api.js';
export default {
  props: ['pblmId', 'curData'],
  components: {
    upload,
    addvSearch,
  },
  data() {
    return {
      moment,
      duChaTypes: [
        // { name: '全选', id: '' },
        // { name: '堤防', id: '堤防' },
        // { name: '防汛', id: '防汛' },
        // { name: '河道疏浚沙石综合利用类', id: '河道疏浚沙石综合利用类' },
        // { name: '河湖卫士监督执法', id: '河湖卫士监督执法' },
        // { name: '农村水电', id: '农村水电' },
        // { name: '农村饮水', id: '农村饮水' },
        // { name: '水库', id: '水库' },
        // { name: '水系联通', id: '水系联通' },
        // { name: '水闸', id: '水闸' },
        // { name: '水资源管理', id: '水资源管理' },
        // { name: '项目建设提速类', id: '项目建设提速类' },
        // { name: '中小河流治理', id: '中小河流治理' },
        // { name: '重点山洪沟治理', id: '重点山洪沟治理' }
      ],
      ywcsList: [
        { name: '防御处', value: '防御处' },
        { name: '规计处', value: '规计处' },
        { name: '监督处', value: '监督处' },
        { name: '建管处', value: '建管处' },
        { name: '农水处', value: '农水处' },
        { name: '省河湖局', value: '省河湖局' },
        { name: '省农电局', value: '省农电局' },
        { name: '省水政总队', value: '省水政总队' },
        { name: '水资源处', value: '水资源处' },
      ],
      sourceList: [],
      RectInfo: {
        isJcFlow: '',
        fileNoNumber: '',
        problemDetails: '',
        inspPblmDesc: '',
        pblmSource: '',
        nm: '',
        adName: '',
        upAdName: '',
        zgMemo: '',
        pblmSourceTm: '',
        zgWjName: '',
        issuedTm: '',
        dutyDept: '',
        objType: '',
        zgDate: null,
        applyPdTm: null,
        isPblmDel: '',
        pblmSggtn: '',
        isPdTm: null,
        firstZgTm: null,
        nlZgDate: null,
        schdYear: null,
        isPdSche: '',
        zgDevelopment: '',
        isApplyPd: '',
        isDeptagePd: '',
        deptagePdEln: '',
        zgRedefineReq: '',
        zgZgxx: '',
        zgDelayEln: '',
        informedNum: '',
        expectedZgDate: '',
        psDlyTm: '',
      },
      isOpen: false,
      isYear: null,
      loadingStat: false,
      loadingStatText: '提交',
      rules: {
        zgZgxx: [
          { required: true, message: '请输入整改描述', trigger: 'blur' },
        ],
      },
      uuid: '',
      persId: localStorage.getItem('persId'),
      uploadFileUrl: '',
      dialogImageUrl: '',
      dialogVisible: true,
      treeData: [],
      defaultProps: {
        children: 'children',
        title: 'nm',
        key: 'id',
        value: 'nm',
      },
    };
  },
  computed: {
    hostUrl() {
      return hostUrl;
    },
    curAdcode_long() {
      return curAdcode_long;
    },
  },
  created() {
    this.getDuChaTypes();
    this.getAdDataList();
  },
  mounted() {
    this.getDuChaResource();
    this.RectInfo = this.curData;
    this.RectInfo.isPdTm = this.curData.isPdTm
      ? moment(this.curData.isPdTm)
      : null;
    this.RectInfo.schdYear = this.curData.schdYear
      ? moment(this.curData.schdYear)
      : null;
    this.RectInfo.firstZgTm = this.curData.firstZgTm
      ? moment(this.curData.firstZgTm)
      : null;
    this.RectInfo.nlZgDate = this.curData.nlZgDate
      ? moment(this.curData.nlZgDate)
      : null;
    this.RectInfo.zgDate = this.curData.zgDate
      ? moment(this.curData.zgDate)
      : null;
    this.RectInfo.applyPdTm = this.curData.applyPdTm
      ? moment(this.curData.applyPdTm)
      : null;
  },
  methods: {
    getDuChaTypes() {
      request.get('/dc/insp/pblm/getListType').then((res) => {
        if (res.success) {
          this.duChaTypes = res.data;
        }
      });
    },
    onChange() {
      this.isOpen = false;
      this.isYear = null;
    },
    handYearChange(open) {
      if (open) {
        this.isOpen = true;
      } else {
        this.isOpen = false;
      }
    },
    panelYearChange(value) {
      this.RectInfo.schdYear = value;
      this.isYear = moment(value).format('YYYY');
      this.isOpen = false;
    },
    // 获取行政区划树结构数据
    getAdDataList: function (node, resolve) {
      try {
        getAddTree(this.curAdcode_long, '3').then((res) => {
          if (res.data) {
            this.treeData = res.data.children;
            this.treeData.forEach((item) => {
              item.pName = '';
              item.children.forEach((item1) => {
                item1.pName = item.nm;
                item1.children.forEach((item2) => {
                  item2.pName = item1.nm;
                });
              });
            });
          }
        });
      } catch (e) {}
    },
    addvTreeNodeClick(value, node, extra) {
      this.RectInfo.adName = node.dataRef.nm;
      this.RectInfo.adCode = node.dataRef.id;
      this.RectInfo.upAdName = node.dataRef.pName;
    },
    getDuChaResource() {
      getDuChaResource().then((res) => {
        this.sourceList = res.data;
      });
    },
    saveRectifyInfo() {
      this.$refs.RectifyInfoForm.validate((valid) => {
        if (valid) {
          this.RectInfo.schdYear = this.isYear;
          this.RectInfo.isPdTm = this.RectInfo.isPdTm
            ? moment(this.RectInfo.isPdTm).format('YYYY-MM-DD')
            : '';
          this.RectInfo.firstZgTm = this.RectInfo.firstZgTm
            ? moment(this.RectInfo.firstZgTm).format('YYYY-MM-DD')
            : '';
          this.RectInfo.nlZgDate = this.RectInfo.nlZgDate
            ? moment(this.RectInfo.nlZgDate).format('YYYY-MM-DD')
            : '';
          this.RectInfo.zgDate = this.RectInfo.zgDate
            ? moment(this.RectInfo.zgDate).format('YYYY-MM-DD')
            : '';
          this.RectInfo.applyPdTm = this.RectInfo.applyPdTm
            ? moment(this.RectInfo.applyPdTm).format('YYYY-MM-DD HH:mm:ss')
            : '';
          this.RectInfo.checkPsNull = 'Y';
          request.post('/bis/insp/zg/pblm', this.RectInfo).then((res) => {
            if (res.success) {
              if (this.$refs.uploadFile.submitUpload(this.pblmId)) {
                this.$emit('closePblmRectifyEditDialog');
              }
            } else {
              this.$message.warning(res.message);
            }
          });
        } else {
          return false;
        }
      });
    },
    closeDialog() {
      this.$emit('closePblmRectifyEditDialog');
    },
    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) {
        this.$emit('closePblmRectifyEditDialog');
        // let args = this.gwComFiles.concat(arg);
        // this.updatefilelist(args);
      }
      this.$refs.RectifyInfoForm.resetFields();
      // this.$message.success('保存成功');
      this.$refs.uploadFile.init();
    },
  },
};
</script>

<style lang='less' scoped>

</style>
