<template>
  <a-form :model="problemForm" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" :rules="rules" ref="problemForm">
    <a-form-item label="问题描述">
      <a-textarea v-model:value="problemForm.inspPblmDesc" placeholder="请输入内容" :row="2" required></a-textarea>
    </a-form-item>
    <a-form-item label="意见">
      <a-textarea v-model:value="problemForm.pblmSggtn" placeholder="请输入内容" :row="2" required></a-textarea>
    </a-form-item>
    <a-form-item label="上传照片">
      <upload ref="uploadFile" :url="`/pdcApi/file/insert?bizId=`" @uploadOver="removeNewSupervision"></upload>
    </a-form-item>
    <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
      <a-button type="primary" @click="onSubmit('problemForm')" style="width: 100px;float:right">保存</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { submitUpload } from '../../../api/duChaAPI.js';
import request from '../../../utils/gw_ajax_request.js';
import upload from '../../../widgets/uploadFile.vue';
import pblmEascader from '../../duChaTianBao/project/pblmEascadert';
export default {
  props: [
    'objId',
    'objName',
    'villType',
    'objType',
    'problemMiddleType',
    'problemSmallType',
    'engId',
    'currentObjectRgstrId',
    'newModelData',
    'pblmDesc',
    'prjType',
  ],
  data() {
    return {
      problemForm: {
        t1: '',
        t2: '',
        t3: '',
        villType: '',
        objId: '',
        regid: '',
        objType: '',
        inspPblmCate: '',
        inspPblmDesc: '',
        pblmDesc: '',
        pblmReason: '',
        pblmSggtn: '',
        ifCasePblm: '0',
        pblmStat: '',
        dataStat: '',
        nm: '',
        recPers: '',
        note: '',
        gwComFiles: [
          {
            id: '',
            filePath: '',
            bizId: '',
          },
        ],
      },
      inspPblmCate: '',
      inspPlamCatelist: ['一般', '较重', '严重'],
      imgList: [],
      videoList: [],
      audioList: [],
      pblmStat: '',
      gwComFiles: [],
      problemList: [],
      currentCheckPointList: [],
      currentProblemDescList: [],
      t1: '',
      t2: '',
      t3: '',
      xiangqingmiaoshu: '',
      wenTiLeiBie: '',
      jianChaXiangMu: '',
      rules: {
        inspPblmDesc: [
          {
            required: true,
            message: '请输入描述',
            trigger: 'blur',
          },
        ],
      },
      pblmEascaderVisible: false,
      newPblmValue: [],
    };
  },
  components: {
    upload,
    pblmEascader,
  },
  computed: {
    recPers() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  mounted() {
    this.problemForm.inspPblmDesc = this.pblmDesc;
  },
  methods: {
    onSubmit(problemForm) {
      this.$refs[problemForm].validate((valid) => {
        if (valid) {
          this.problemForm.villType = '18';
          this.problemForm.recPers = this.recPers;
          this.problemForm.objId = this.objId;
          this.problemForm.regid = this.currentObjectRgstrId;
          this.problemForm.nm = this.objName;
          this.problemForm.objType = this.objType;
          this.problemForm.pblmStat = '0';
          this.problemForm['inspPblmDesc'] = this.problemForm.inspPblmDesc;
          request.post('/dc/insp/pblm', this.problemForm).then((res) => {
            if (res.success) {
              this.pblmId = res.data.pblmId;
              this.gwComFiles = [];
              this.pblmStat = res.data.pblmStat;
              if (this.$refs.uploadFile.submitUpload(res.data.pblmId)) {
                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) {
        console.log(arg);
        var args = this.gwComFiles.concat(arg);
        this.updatefilelist(args);
      }
      this.$message.success('保存成功');
      this.$emit('closeDialog');
      this.gwComFiles = [];
      this.$refs.uploadFile.init();
    },
    problemListChange: function (item) {
      this.currentCheckPointList = item.checkPoints;
    },
    currentCheckPointListChange: function (item) {
      this.currentProblemDescList = item.pblmDescs;
    },
    // currentProblemDescListChange: function (item) {
    //     console.log(item);
    // },
    selectPblm() {
      this.pblmEascaderVisible = true;
    },
    submitEascader() {
      if (!this.newPblmValue.model.length) {
        this.$message.warning('问题不能为空');
        return;
      }
      this.pblmEascaderVisible = false;
    },
  },
  watch: {},
};
</script>

<style lang='less' scoped>

</style>
