<template>
  <a-form :model="problemForm" :label-col="{span: 10}" :wrapper-col="{span: 14}" :rules="rules" ref="form">
    <a-form-item label="问题类别" style="text-align:left">
      <span>{{ problemForm.inspPblmName }}</span>
    </a-form-item>
    <a-form-item label="检查事项" style="text-align:left">
      <a-select v-model:value="t3" placeholder="请选择" @change="currentProblemDescListChange" style="max-width: 500px">
        <a-select-option
          v-for="(item,index) in currentProblemDescList"
          :key="item.guid"
          :value="item.pblmDesc"
          style="max-width: 500px">{{ item.pblmDesc }}
        </a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="详细描述" prop="inspPblmDesc">
      <a-textarea v-model:value="problemForm.inspPblmDesc" :rows="2" placeholder="请输入内容"></a-textarea>
    </a-form-item>
    <a-form-item label="典型问题" style="text-align:left">
      <a-radio-group v-model:value="problemForm.ifCasePblm">
        <a-radio :value="1">是</a-radio>
        <a-radio :value="0">否</a-radio>
      </a-radio-group>
    </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" style="width: 100px;float:right">保存</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { getXskBzhProblemList, submitUpload } from '../../../api/duChaAPI.js';
import { getXskBzhPblm } from '../../../api/fujian_api';
import request from '../../../utils/gw_ajax_request.js';
import upload from '../../../widgets/uploadFile.vue';
export default {
  props: [
    'objId',
    'objName',
    'villType',
    'objType',
    'problemMiddleType',
    'problemSmallType',
    'engId',
    'currentObjectRgstrId',
    'problData',
    'currentGroupId',
    'szRuls',
  ],
  data() {
    return {
      problemForm: {
        inspPblmName: '小水库标准化管理情况',
        t3: '',
        villType: '',
        objId: '',
        regid: '',
        objType: '',
        inspPblmDesc: '',
        ifCasePblm: '0',
        pblmStat: '',
        dataStat: '',
        nm: '',
        recPers: '',
        note: '',
        gwComFiles: [
          {
            id: '',
            filePath: '',
            bizId: '',
          },
        ],
      },
      inspPblmCate: '',
      inspPlamCatelist: ['一般', '较重', '严重', '特别严重'],
      imgList: [],
      videoList: [],
      audioList: [],
      pblmStat: '',
      gwComFiles: [],
      problemList: [],
      currentCheckPointList: [],
      currentProblemDescList: [],
      t3: '',
      t1: '',
      xiangqingmiaoshu: '',
      wenTiLeiBie: '',
      jianChaXiangMu: '',
      rules: {
        inspPblmDesc: [
          {
            required: true,
            message: '请输入描述',
            trigger: 'blur',
          },
        ],
      },
    };
  },
  components: {
    upload,
  },
  computed: {
    recPers() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  mounted() {
    this.getproblemSmallType();
  },
  methods: {
    // getproblemSmallType() {
    //     getXskBzhPblm().then(res =>{
    //         this.$nextTick(()=>{
    //             if(res.success){
    //                 this.currentProblemDescList = res.data;
    //                 this.t3 = this.currentProblemDescList[0];
    //             }
    //         })
    //
    //     })
    // },
    getproblemSmallType() {
      if (this.problData) {
        getXskBzhProblemList(this.problData).then((res) => {
          if (res.success) {
            this.problemList = res.data;
            this.t1 = this.problemList[0];
            this.currentCheckPointList = this.problemList[0].items;
            this.t2 = this.currentCheckPointList[0];
            this.currentProblemDescList = this.problemList[0].items[0].items;
            this.t3 = this.currentProblemDescList[0];
          }
        });
      } else {
        getXskBzhPblm().then((res) => {
          this.$nextTick(() => {
            if (res.success) {
              this.currentProblemDescList = res.data;
            }
          });
        });
      }
    },
    getYanZhongChengDu() {
      this.inspPblmCate = this.t3.inspPblmCate;
    },
    onSubmit(problemForm) {
      this.$refs[problemForm].validate((valid) => {
        if (valid) {
          this.problemForm.villType = '24';
          this.problemForm.recPers = this.recPers;
          this.problemForm.objId = this.objId;
          this.problemForm.regid = this.currentObjectRgstrId;
          this.problemForm.nm = this.objName;
          this.problemForm.inspPblmsName = this.t3.inspPblmsName
            ? this.t3.inspPblmsName
            : this.t1.inspPblmsName;
          // this.problemForm['inspPblmDesc'] = this.problemForm.inspPblmDesc;
          this.problemForm['inspPblmCode'] = this.t3.sn;
          this.problemForm.objType = '24';
          this.problemForm.pblmStat = '0';
          this.problemForm['pblmsTypeId'] = this.t3.guid;
          this.problemForm['inspGroupId'] = this.currentGroupId;
          if (!this.problemForm.inspPblmsName) {
            this.$message.info('请选择检查项目');
            return;
          }
          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);
        return;
      }
      this.$message.success('保存成功');
      this.$emit('closeDialog');
      this.gwComFiles = [];
      this.$refs.uploadFile.init();
    },
    problemListChange: function (item) {
      this.t1 = item;
      this.currentCheckPointList = item.checkPoints;
      this.currentProblemDescList = item.checkPoints[0].pblmDescs;
    },
    // problemListChange: function (item) {
    //     this.currentCheckPointList = item.items;
    // },
    currentCheckPointListChange: function (item) {
      this.currentProblemDescList = item.items;
    },
    currentProblemDescListChange: function (item) {
      console.log(item);
      this.t3 = item;
    },
  },
};
</script>

<style lang='less' scoped>

</style>
