<template>
  <div id="">
    <a-layout style="height:520px;">
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;overflow: auto;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;margin-bottom: 20px">问题信息</p>
        <div style="margin-top: 10px;overflow: hidden">
          <a-button type="danger" style="float: right;" @click="confirmData">佐证材料</a-button>
          <a-button type="danger" style="float: right;margin-right: 10px;" @click="historyPic">历史图片</a-button>
        </div>
        <a-form style="padding:10px;">
          <a-form-item label="项目名称">
            <p>{{ formObj.name }}</p>
          </a-form-item>
          <a-form-item label="问题类别">
            <p>{{ formObj.pblmType | typeFormatter }}</p>
          </a-form-item>
          <a-form-item label="问题描述">
            <p>{{ formObj.pblmDesc }}</p>
          </a-form-item>
          <a-form-item label="是否销号">
            <p>{{ formObj.rectConc | rectConcFilter }}</p>
          </a-form-item>
          <a-divider />
          <a-form-item label="核实情况">
            <a-radio-group v-model:value="formObj.reviConc">
              <a-radio value="1">符合</a-radio>
              <a-radio value="2">不符合</a-radio>
              <a-icon type="plus-circle" v-if="formObj.reviConc == '2'" @click="addProblem" />
            </a-radio-group>
          </a-form-item>
          <a-form-item label="上传佐证照片" v-if="false">
            <upload ref="uploadFile" :url="`/pdcApi/file/insert`" :dcType="`siluan`" @uploadOver="removeNewSupervision"></upload>
          </a-form-item>
          <a-form-item label="佐证照片" v-if="false">
            <a-carousel autoplay style="height:350px;">
              <div v-for="(item, index) in pictureArray" :key="index">
                <a :href="`${hostUrl}/${item.filePath}`" target="_blank">
                  <img style="height:100%;" :src="`${hostUrl}/${item.filePath}`" alt>
                </a>
              </div>
              <div v-if="pictureArray.length == 0">
                <p>暂无图片信息</p>
              </div>
            </a-carousel>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 10, offset: 14 }">
            <a-button type="primary" @click="addHandler()" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <showAndUploadPic
        v-if="jqmmShow"
        @jqmmDialogClose="jqmmDialog"
        :picType="picType"
        :openType="openType"
        :jqmmShow="jqmmShow"
        :jqmmEngId="currentObjectRgstrId"
        :dialogTitle="currentObjectName"></showAndUploadPic>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objId="currentObjectId"
        :pblmDesc="formObj.pblmDesc"
        :objName="currentObjectName"
        @closeDialog="closeDialog"
        fenlei="siluan"
        :objType="18"
        :currentObjectRgstrId="currentObjectRgstrId">
      </problem-dialog></a-layout>
  </div>
</template>

<script>
import { getrgstrIdObject1 } from '../../../api/duChaTianBao';
import { hostUrl } from '../../../utils/global_variable.js';
import request from '../../../utils/gw_ajax_request';
import { dateFormat } from '../../../utils/gw_date.js';
import inputWith from '../../../widgets/inuptWith.vue';
import upload from '../../../widgets/uploadFile.vue';
import problemDialog from '../waterIntake/addProblemDialog.vue';
import showAndUploadPic from './showAndUploadPic';
export default {
  components: {
    inputWith,
    problemDialog,
    upload,
    showAndUploadPic,
  },
  props: [
    'currentObjectRgstrId',
    'currentBaseId',
    'currentObjectId',
    'currentObjectName',
    'openType',
  ],
  data() {
    return {
      formObj: {
        name: '',
        pblmType: '',
        pblmDesc: '',
        rectConc: '',
        reviConc: '',
        objId: '',
        persId: '',
      },
      dialogFormVisible: false,
      showAddProblemDialog: false,
      formLabelWidth: '160px',
      loading: true,
      operationType1: '',
      currentBaseId1: '',
      currentObjectId1: '',
      locat: {
        location: '',
        admDiv: '',
      },
      gcType: [],
      gwComFiles: [],
      pictureArray: [],
      jqmmShow: false,
      picType: 'history',
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
    hostUrl() {
      return hostUrl;
    },
  },
  mounted() {
    this.getRgstridObj();
    this.getFile();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    getRgstridObj() {
      request
        .get(`/att/jskejian/flkdis/rgstr/${this.currentObjectRgstrId}`)
        .then((res) => {
          if (res.success) {
            this.formObj = res.data;
          } else {
            this.$message.warning(res.message);
          }
        });
    },
    getFile() {
      request
        .post(`/file/findFileByBiz?bizId=${this.currentObjectRgstrId}`)
        .then((res) => {
          if (res.success) {
            this.pictureArray = res.data;
          } else {
            this.$message.warning(res.message);
          }
        });
    },
    addHandler(formName) {
      this.formObj['persId'] = this.recPersId;
      this.formObj['rgstrId'] = this.currentObjectRgstrId;
      this.formObj.objId = this.currentObjectId;
      const dataObj = {
        persId: this.recPersId,
        rgstrId: this.currentObjectRgstrId,
        objId: this.currentObjectId,
        reviConc: this.formObj.reviConc,
        id: this.formObj.id,
      };
      console.log(this.formObj);
      try {
        this.$confirm({
          title: '提示',
          content: '确认保存基础信息？',
          okType: 'warning',
          onOk: () => {
            request.post('/att/jskejian/flkdis/rgstr', dataObj).then((res) => {
              if (res.success) {
                console.log(this.currentObjectRgstrId);

                if (this.$refs.uploadFile.submitUpload(res.data.rgstrId)) {
                  this.removeNewSupervision();
                }
                this.$emit('addQiTaSuccess');
                this.getRgstridObj();
                this.$message.success('修改成功');
              } else {
                this.$emit('cancelHandler');
              }
            });
          },
        });
      } catch (e) {}
    },
    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.gwComFiles = [];
      this.$refs.uploadFile.init();
    },
    addProblem() {
      this.showAddProblemDialog = true;
    },
    closeDialog() {
      this.showAddProblemDialog = false;
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    historyPic() {
      this.jqmmShow = true;
      this.picType = 'history';
    },
    confirmData() {
      this.jqmmShow = true;
      this.picType = 'confirm';
    },
    jqmmDialog() {
      this.jqmmShow = false;
    },
  },
  filters: {
    typeFormatter(pblmType) {
      return pblmType == '1'
        ? '乱占'
        : pblmType == '2'
          ? '乱采'
          : pblmType == '3'
            ? '乱堆'
            : pblmType == '4'
              ? '乱建'
              : pblmType == '5'
                ? '其他'
                : pblmType;
    },
    rectConcFilter(rectConc) {
      return rectConc == '1' ? '已销号' : rectConc == '2' ? '未销号' : rectConc;
    },
  },
};
</script>

<style lang='less' scoped>
#dcdxHeader {
  padding: 15px 20px;
}

#dxdcFooter {
  text-align: center;
}

#dxdcAside {
  border: 1px solid #d5d5ff;
}

.el-dialog__wrapper .el-treeWhite {
  /* max-height: 260px !important; */
}

.add-problem-icon {
  font-size: 16px;
}

.el-icon-camera-solid,
.el-icon-circle-plus {
  margin-left: 20px;
  color: #00bbff;
  font-size: 18px;
  line-height: 12px;
  vertical-align: middle;
  cursor: pointer;
}

.el-icon-circle-plus {
  vertical-align: top;
}

.tip_info {
  margin-left: 20px;
  font-size: 12px;
  color: #ff0000;
}
</style>
