<template>
  <a-modal
    :open="dialogFormVisible"
    :title="currentObjectName + '督查填报'"
    :footer="null"
    width="100%"
    @cancel="closeDialog">
    <a-layout>
      <a-layout-content id="dxdcListMain">
        <a-tabs v-model="currentViewId" type="card" @tabClick="tabIndexChange">
          <a-tab-pane v-for="option in options" :key="option.label" :tab="option.label">
            <component
              :is="option.value"
              :currentObjectRgstrId="currentObjectRgstrId"
              :currentObjectName="currentObjectName"
              :currentResCode="currentResCode"
              :currentObjectId="currentObjectId"
              :activeLabel="activeLabel"
              :pType="pType"
              :inspType="inspType"
              :id="id"
              :prjType="prjType"
              :openType="openType"
              :labelList="signatureLabelList"
              @cancelHandler="cancelHandler"
              @addShuiKuSuccess="addShuiKuSuccess"></component>
          </a-tab-pane>
        </a-tabs>
      </a-layout-content>
    </a-layout>
  </a-modal>
</template>

<script>
import { getrgstrIdObject } from '../../api/duChaTianBao';
import request from '../../utils/gw_ajax_request';
import {
  optionsForJiangxiShuiLiTiSuNian_1,
  optionsForJiangxiShuiLiTiSuNian_2,
  optionsForJiangxiShuiLiTiSuNian_3,
  optionsForJiangxiShuiLiTiSuNian_4,
  optionsForJiangxiShuiLiTiSuNian_5,
} from './shuilitisunian/forDifferentProvince.js';
import jichuxinxi_1 from './shuilitisunian/jichuxinxi_1.vue';
import jichuxinxi_2 from './shuilitisunian/jichuxinxi_2.vue';
import jichuxinxi_3 from './shuilitisunian/jichuxinxi_3.vue';
import jichuxinxi_4 from './shuilitisunian/jichuxinxi_4.vue';
import jichuxinxi_5 from './shuilitisunian/jichuxinxi_5.vue';
import problemList from './sltsnProblemList.vue';

export default {
  components: {
    jichuxinxi_1: jichuxinxi_1,
    jichuxinxi_2: jichuxinxi_2,
    jichuxinxi_3: jichuxinxi_3,
    jichuxinxi_4: jichuxinxi_4,
    jichuxinxi_5: jichuxinxi_5,
    problemList: problemList,
  },
  props: [
    'id',
    'rowData',
    'currentObjectRgstrId',
    'currentResCode',
    'currentObjectId',
    'currentObjectName',
    'pType',
    'inspType',
    'prjType',
    'openType',
  ],
  data() {
    return {
      options: [],
      value: '',
      dialogShow: false,
      currentViewId: '基础信息纠错',
      dialogFormVisible: true,
      activeLabel: '',
      signatureLabelList: ['行政责任人', '技术责任人', '巡查责任人'],
    };
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
    currentRlcode() {
      return localStorage.getItem('currentRlcode')
        ? localStorage.getItem('currentRlcode')
        : '';
    },
  },
  mounted() {
    if (this.currentRlcode.indexOf('36') == '0') {
      // 江西省
      if (this.prjType == '1') {
        this.options = optionsForJiangxiShuiLiTiSuNian_1;
      }
      if (this.prjType == '2') {
        this.options = optionsForJiangxiShuiLiTiSuNian_2;
      }
      if (this.prjType == '3') {
        this.options = optionsForJiangxiShuiLiTiSuNian_3;
      }
      if (this.prjType == '4') {
        this.options = optionsForJiangxiShuiLiTiSuNian_4;
      }
      if (this.prjType == '5') {
        this.options = optionsForJiangxiShuiLiTiSuNian_5;
      }
    } else if (this.currentRlcode.indexOf('35') == '0' && this.pType == 1) {
      this.options = optionsForFujian;
    } else if (this.currentRlcode.indexOf('35') == '0' && this.pType == 22) {
      this.options = optionsForFujianDsk;
    } else {
      this.options = optionsForNation; // 通用
    }
  },
  created() {},
  methods: {
    submitHandler() {
      getrgstrIdObject(this.rowData.code, this.rowData.objId).then((res) => {
        if (res.data.baseStat == '0') {
          this.$message({
            message: '请填写重点环节落实情况！',
            type: 'warning',
          });
          return;
        } else if (res.data.presStat == '0') {
          this.$message({
            message: '请填写责任人状态！',
            type: 'warning',
          });
          return;
        } else if (res.data.resRunStat == '0') {
          this.$message({
            message: '请填写水库工程实体和运行管理情况！',
            type: 'warning',
          });
          return;
        } else if (res.data.viewStat == '0') {
          this.$message({
            message: '走访用户状态！',
            type: 'warning',
          });
          return;
        }
        this.$confirm({
          title: '提示',
          content: '请确认所有信息填报完毕？',
          okType: 'warning',
          onOk: () => {
            const formObj = {
              rgstrId: this.currentObjectRgstrId,
              state: '2',
            };
            request.post('/dc/insp/rsvrRgstr/update', formObj).then((res) => {
              if (res.success) {
                this.$emit('addShuiKuSuccess');
                this.$message.success('提交成功');
              } else {
                this.$emit('cancelHandler');
              }
            });
          },
        });
      });
    },
    closeHandler() {
      this.dialogShow = false;
      this.$emit('addShuiKuSuccess');
    },
    appearDialog(type) {
      this.dialogShow = true;
      // this.problemSmallType = type
    },
    closePDialog() {
      this.dialogShow = false;
    },
    showDialog() {
      this.dialogFormVisible = true;
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    addShuiKuSuccess() {
      this.$emit('addShuiKuSuccess');
    },
    closeDialog() {
      this.$confirm({
        title: '提示',
        content: '确认退出吗？',
        okType: 'warning',
        onOk: () => {
          this.$emit('cancelHandler');
        },
      });
    },
    tabIndexChange(item) {
      if (item == '问题清单') {
        this.activeLabel = item;
      } else {
        this.activeLabel = '';
      }
    },
  },
};
</script>

<style lang='less' scoped>
:deep(.ant-modal) {
  top: 0;
}
</style>
