<template>
  <div class="gcsthyxglqk">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">信息填报</p>
        <a-form :model="addObj" :label-col="{span: 12}" :wrapper-col="{span: 12}">
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">金结机电设备</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="闸门及启闭设施（如有）是否无法启闭">
            <a-radio-group v-model:value="addObj.zmWfqd">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('zmWfqd',addObj.zmWfqd)" type="link" v-if="addObj.zmWfqd =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="闸门及启闭设施是否锈蚀、变形">
            <a-radio-group v-model:value="addObj.zmXsbx">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('zmXsbx',addObj.zmXsbx)"
                type="link"
                v-if="addObj.zmXsbx =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="闸门主要承重件是否出现裂缝">
            <a-radio-group v-model:value="addObj.zmCxlf">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('zmCxlf',addObj.zmCxlf)" type="link" v-if="addObj.zmCxlf =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="闸门门体止水装置是否老化">
            <a-radio-group v-model:value="addObj.zmMtlh">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('zmMtlh',addObj.zmMtlh)" type="link" v-if="addObj.zmMtlh =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="闸门是否漏水">
            <a-radio-group v-model:value="addObj.zmSfls">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">是，且漏水严重</a-radio>
              <a-radio value="3">否</a-radio>
              <a-button
                @click="addProblem('zmSfls',addObj.zmSfls)"
                type="link"
                v-if="addObj.zmSfls !='3'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="钢丝绳是否锈蚀、断丝">
            <a-radio-group v-model:value="addObj.gssXsds">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('gssXsds',addObj.gssXsds)" type="link" v-if="addObj.gssXsds =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="钢丝绳或螺杆达到报废标准是否报废">
            <a-radio-group v-model:value="addObj.gssBf">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">维修良好</a-radio>
              <a-radio value="3">维修不善</a-radio>
              <a-radio value="4">泄洪建筑物且维修不善</a-radio>
              <a-button @click="addProblem('gssBf',addObj.gssBf)" type="link" v-if="addObj.gssBf !='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="电气设备及备用电源是否故障">
            <a-radio-group v-model:value="addObj.dqQjjcsb">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('dqQjjcsb',addObj.dqQjjcsb)"
                type="link"
                v-if="addObj.dqQjjcsb =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="绝缘、接地和避雷等设施是否符合要求">
            <a-radio-group v-model:value="addObj.dqDygz">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('dqDygz',addObj.dqDygz)" type="link" v-if="addObj.dqDygz =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">安全监测设备</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="是否按要求设置必要的安全监测设备设施">
            <a-radio-group v-model:value="addObj.dqJcsb">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('dqJcsb',addObj.dqJcsb)" type="link" v-if="addObj.dqJcsb =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="安全监测设备设施是否损坏、失效">
            <a-radio-group v-model:value="addObj.dqJcsbsh">
              <a-radio value="1">未公示</a-radio>
              <a-radio value="0">不落实、不明确</a-radio>
              <a-button
                @click="addProblem('dqJcsbsh',addObj.dqJcsbsh)"
                type="link"
                v-if="addObj.dqJcsbsh =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">标识、标牌</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="是否设置公示牌（检查重点）">
            <a-radio-group v-model:value="addObj.bsGsp">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('bsGsp',addObj.bsGsp)" type="link" v-if="addObj.bsGsp =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="公示牌是否存在错误或虚假信息（检查重点）" v-if="addObj.bsGsp == '1'">
            <a-radio-group v-model:value="addObj.bsGspcw">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('bsGspcw',addObj.bsGspcw)" type="link" v-if="addObj.bsGspcw =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="公示牌和重要警示标识等设置位置是否醒目" v-if="addObj.bsGsp == '1'">
            <a-radio-group v-model:value="addObj.bsGspxm">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('bsGspxm',addObj.bsGspxm)"
                type="link"
                v-if="addObj.bsGspxm =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="重要设备、设施铭牌标识是否缺失">
            <a-radio-group v-model:value="addObj.bsSbbsqs">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('bsSbbsqs',addObj.bsSbbsqs)"
                type="link"
                v-if="addObj.bsSbbsqs =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">其他</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="设备设施存在其他实体缺陷">
            <a-radio-group v-model:value="addObj.bsStqx">
              <a-radio value="1">一般缺陷</a-radio>
              <a-radio value="2">较重缺陷</a-radio>
              <a-radio value="3">严重缺陷，并影响运行安全</a-radio>
              <a-radio value="4">无缺陷</a-radio>
              <a-button @click="addProblem('bsStqx',addObj.bsStqx)" type="link" v-if="addObj.bsStqx !='4'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 12, offset: 12 }">
            <a-button type="primary" @click="makesure" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objType="pType"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'小水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"> </problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getLyjglist, getSbsslist } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'pType',
    'openType',
  ],
  data() {
    return {
      objtbStatu: {
        reverStat: '',
        rgstrId: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '350px',
      loading: true,
      addObj: {
        // 注意有几个字段无法确认，需要掉接口查看
        rgstrId: '',
        zmWfqd: '',
        zmXsbx: '',
        zmCxlf: '',
        zmMtlh: '',
        zmSfls: '',
        gssXsds: '',
        gssBf: '',
        dqQjjcsb: '',
        dqDygz: '',
        dqJcsb: '',
        dqJcsbsh: '',
        bsGsp: '',
        bsGspcw: '',
        bsGspxm: '',
        bsSbbsqs: '',
        bsStqx: '',
        recPersId: '',
        recPers2: '',
        recPersTel: '',
        createTime: '',
        updateTime: '',
        status: '',
        // 注意有几个字段无法确认，需要掉接口查看
      },
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getLyList();
    this.getformList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    // 获取流域信息
    getLyList() {
      request.get(`/dc/insp/base/getInspByPid?pid=''`).then((res) => {
        if (res.success) {
          this.lyjg = res.data;
          this.placeholder = this.lyjg[0].pnm;
          this.addObj.reverOrg = this.lyjg[0].id;
          this.getformList();
        } else {
          this.getformList();
        }
      });
    },
    getformList() {
      getSbsslist(this.currentObjectRgstrId).then((res) => {
        if (res.success) {
          if (res.data && Object.keys(res.data).length) {
            this.addObj = res.data;
            this.operationType1 = 'update';
          } else {
            this.addObj = {};
            this.operationType1 = 'add';
          }
        } else {
        }
      });
    },
    // 保存
    makesure() {
      this.addObj['rgstrId'] = this.currentObjectRgstrId;
      this.addObj['recPersId'] = this.recPersId;
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      if (
        this.addObj.reverOrg ||
        this.addObj.poorCountry ||
        this.addObj.diskRunInfo ||
        this.addObj.hasSetMainFl ||
        this.addObj.hasSetPourFl
      ) {
        this.objtbStatu.reverStat = '1';
      }
      if (
        this.addObj.reverOrg &&
        this.addObj.poorCountry &&
        this.addObj.diskRunInfo &&
        this.addObj.hasSetMainFl &&
        this.addObj.hasSetPourFl
      ) {
        this.objtbStatu.reverStat = '2';
      }
      if (
        this.addObj.reverOrg == undefined &&
        this.addObj.poorCountry == undefined &&
        this.addObj.diskRunInfo == undefined &&
        this.addObj.hasSetMainFl == undefined &&
        this.addObj.hasSetPourFl == undefined
      ) {
        this.objtbStatu.reverStat = '0';
      }

      this.$confirm({
        title: '提示',
        content: '此操作将督查对象从列表中删除，确认删除该水库吗？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            request.post('/dc/insp/xskaqSbss', this.addObj).then((res) => {
              if (res.success) {
                this.$message.success('添加成功');
                /* request
                  .post("/dc/insp/rsvrRgstr/update", _self.objtbStatu)
                  .then(res => {
                    res;
                  }); */
                this.$emit('addShuiKuSuccess');
                this.getformList();
              }
            });
          } else {
            request
              .post('/dc/insp/xskaqSbss/update', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('修改成功');
                  /* request
                    .post("/dc/insp/rsvrRgstr/update", _self.objtbStatu)
                    .then(res => {
                      res;
                    }); */
                  this.$emit('addShuiKuSuccess');
                }
              });
          }
        },
      });
    },
    // 查看
    makeshow(type, row) {
      this.dialogFormVisible = true;
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '0') {
        return '否';
      } else {
        return val;
      }
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_XSKAQ_SBSS',
        type: this.pType,
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item, iValue) {
      const rest = this.rsvrRules.filter((e) => {
        return e.iValue === iValue && e.eName === item;
      });
      if (rest[0]) {
        this.probId = rest[0].id;
      }
      this.showAddProblemDialog = true;
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
  },
};
</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;
}
</style>
