<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">
      <a-input v-model:value="problemForm.inspPblmName" disabled></a-input>
    </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="发现问题" style="text-align:left">
      <a-select v-model:value="pblmsTypeId" placeholder="请选择" disabled>
        <a-select-option v-for="(item,index) in smallTypeList" :key="item.guid" :value="item.guid">{{ item.inspPblmsName }}
        </a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="问题描述">
      <a-textarea v-model:value="problemForm.inspPblmDesc"></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" style="width: 100px;float:right">保存</a-button>
    </a-form-item>
  </a-form>
</template>

<script>
import { getRygcPlm, submitUpload } from '../../../api/duChaAPI.js';
import request from '../../../utils/gw_ajax_request.js';
import upload from '../../../widgets/uploadFile.vue';
export default {
  props: [
    'objId',
    'objName',
    'objType',
    'villType',
    'problemMiddleType',
    'problemSmallType',
    'cwsCode',
  ],
  data() {
    return {
      problemForm: {
        t1: '',
        t2: '',
        t3: '',
        villType: '',
        objId: '',
        regid: '',
        objType: '',
        // inspPblmName: "",
        // inspPblmCate: "",
        inspPblmDesc: '',
        note: '',
        // ifCasePblm: '0',

        pblmStat: '',
        dataStat: '',
        nm: '',
        recPers: '',
        gwComFiles: [],
      },
      inspPblmCate: '',
      inspPlamCatelist: ['一般', '较重', '严重'],
      imgList: [],
      videoList: [],
      audioList: [],
      pblmStat: '',
      gwComFiles: [],
      problemList: [],
      currentCheckPointList: [],
      currentProblemDescList: [],
      t1: '',
      t2: '',
      t3: '',
      xiangqingmiaoshu: '',
      wenTiLeiBie: '',
      jianChaXiangMu: '',
      rules: {
        inspPblmDesc: [
          {
            required: true,
            message: '请输入描述',
            trigger: 'blur',
          },
        ],
      },
      problemStandard: '1',
      organId: '00',
      problemForm: {
        objId: '',
        objType: '',
        villType: '',
        villCode: '',
        inspPblmName: '',
        inspPblmsName: '',
        pblmsTypeId: '',
        inspPblmCate: '',
        inspPblmDesc: '',
        pblmStat: '',
        dataStat: '',
        nm: '',
        recPers: '',
        note: '',
        gwComFiles: [
          {
            id: '',
            filePath: '',
            bizId: '',
          },
        ],
      },
      pblmsTypeId: '',
      smallTypeList: [
        // "间断供水问题",
        // "净化设施设备问题",
        // // "消毒设备",
        // "水质报告存在问题",
        // "千顿万人水厂水质化验室问题",
        // "取水许可证问题",
        // "卫生许可证问题",
        // "自动化控制系统问题",
        // "视频安防视频问题",
        // "水费水价问题"
      ],
      pblmId: '',
      imgList: [],
      videoList: [],
      audioList: [],
      pblmStat: '',
      gwComFiles: [],
      arr1: [],
    };
  },
  components: {
    upload,
  },
  computed: {
    recPers() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.getPblmsByQuesNum();
  },
  watch: {
    pblmsTypeId(n, o) {
      this.smallTypeList.forEach((ele) => {
        if (this.pblmsTypeId == ele.guid) {
          this.problemForm.inspPblmsName = ele.inspPblmsName;
        }
      });
    },
  },
  mounted() {
    this.getType();
    this.problemForm.inspPblmsName = this.problemSmallType
      ? this.problemSmallType
      : this.smallTypeList[0].inspPblmsName;
    this.problemForm.inspPblmName = this.problemMiddleType;
  },
  methods: {
    getType() {
      request
        .get('/dc/insp/pblms/getPblmType', { params: { type: 2 } })
        .then((res) => {
          if (res.success) {
            const _this = this;
            res.data.forEach((ele) => {
              if (
                ele.inspPblmsName == '人饮工程' ||
                ele.inspPblmsName == '供水工程' ||
                ele.inspPblmsName == '农饮工程' ||
                ele.inspPblmsName == '饮水工程'
              ) {
                const pguid = ele.guid;
                request
                  .get('/dc/insp/pblms/getPblmType', {
                    params: { type: 2, pguid: pguid },
                  })
                  .then((res) => {
                    if (res.success) {
                      this.smallTypeList = res.data;
                      this.smallTypeList.forEach((ele) => {
                        if (
                          ele.inspPblmsName.indexOf(_this.problemSmallType) > -1
                        ) {
                          _this.pblmsTypeId = ele.guid;
                        }
                      });
                    }
                  });
              }
            });
          }
        });
      // request
      // .get("/dc/insp/pblms/getPblmType", { params: { type: 2,pguid:"10000000000000000000000000000133"} })
      // .then(res => {
      //   if (res.success) {
      //     this.smallTypeList = res.data;
      //   }
      // });
    },
    onSubmit() {
      this.problemForm.recPers = this.recPers;
      this.problemForm.objId = this.objId;
      this.problemForm.nm = this.objName;
      this.problemForm.objType = this.objType;
      this.problemForm.villType = this.villType;
      this.problemForm.cwsCode = this.cwsCode;
      this.problemForm.pblmsTypeId = this.pblmsTypeId;
      this.problemForm.pblmStat = '0';
      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();
          }
        }
      });
    },
    // 文件上传
    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();
    },
  },
};
</script>

<style lang='less' scoped>

</style>
