<template>
  <MOSTY.FromPage :title="props.formData.title" @closeDialog="closeDialog">
    <template #content>
      <MOSTY.Assort :title="'基础信息'" />
      <el-form :model="props.formData" ref="ruleFormRef" label-position="right" :rules="rules" label-width="200px"
        class="demo-ruleForm" :disabled='!props.formData.saveBtnShow'>
        <el-form-item label="所属场所:" prop="sitename">
          <el-input v-model="props.formData.sitename" disabled style="width: 250px" />
        </el-form-item>
        <el-form-item :label="props.formData.publicarea == '1' ? '场区名称:' : '建筑物名称:'" prop="buildingname">
          <el-input v-model="props.formData.buildingname" style="width: 250px" />
        </el-form-item>
        <el-form-item :label="props.formData.publicarea == '1' ? '场区面积:' : '建筑面积(m2):'"
          :prop="props.formData.usesate === '1'|| props.formData.publicarea == '2' ? 'area' : ''">
          <el-input v-model.number="props.formData.area" type="number" style="width: 250px">
            <template #append>平方米</template>
          </el-input>
        </el-form-item>
        <el-form-item label="占地面积:" v-if="['010100', '010200', '010300'].includes(props.formData.buildingstype)"
          prop='coverArea'>
          <el-input v-model.number="props.formData.coverArea" type="number" style="width: 250px">
            <template #append>平方米</template>
          </el-input>
        </el-form-item>
        <el-form-item label="占地面积:" v-else>
          <el-input v-model.number="props.formData.coverArea" type="number" style="width: 250px">
            <template #append>平方米</template>
          </el-input>
        </el-form-item>
        <el-form-item label="高度:" prop='high'
          v-if='props.formData.publicarea != "1" && (["010100", "010200", "010300"].includes(props.formData.buildingstype))'>
          <el-input v-model.number="props.formData.high" type="number" style="width: 250px">
            <template #append>米</template></el-input>
        </el-form-item>
        <el-form-item label="高度:"
          v-if='props.formData.publicarea != "1" && !(["010100", "010200", "010300"].includes(props.formData.buildingstype))'>
          <el-input v-model.number="props.formData.high" type="number" style="width: 250px">
            <template #append>米</template></el-input>
        </el-form-item>
        <el-form-item label="地上层数:" prop="abovegroundFloors" v-if='props.formData.publicarea != "1"'>
          <el-input v-model.number="props.formData.abovegroundFloors" type="number" style="width: 250px">
            <template #append>层</template></el-input>
        </el-form-item>
        <el-form-item label="地下层数:" prop="undergroundFloors" v-if='props.formData.publicarea != "1"'>
          <el-input v-model="props.formData.undergroundFloors" type="number" style="width: 250px" :min="0">
            <template #append>层</template></el-input>
        </el-form-item>
        <!-- v-if='props.type!="ck"' -->
        <el-form-item label="建筑物类别:" prop="buildingstype" v-if='props.formData.publicarea != "1"'>
          <MOSTY.DictTree :zdbh="'D_BZ_JZWLB'" v-model="props.formData.buildingstype" :placeholder='"请选择类别:"'
            :disabled='false' style="width: 250px;" @onChange='jzwlbchange' />
        </el-form-item>
        <!-- 建筑物类别为仓库 -->
        <el-form-item label="存储物质类别:" prop="ccwzlb" :rules="[{ required: true, message: '请选择存储物质类别', trigger: 'blur' }]"
          v-if='showcclb'>
          <MOSTY.DictRidioAndSelect
            v-if='props.formData.buildingstype == "020204" || props.formData.buildingstype == "020205"'
            :dictData="ccwzlist" v-model="props.formData.ccwzlb" selectType="select" :disabled="false"
            style="width: 250px;" @getselect='ccwzchange' />
          <MOSTY.DictTree v-else :zdbh="'D_BZ_CCWZLBSX'" v-model="props.formData.ccwzlb" :placeholder='"请选择存储物质类别"'
            :disabled='false' style="width: 250px;" @onChange='ccwzchange' />
        </el-form-item>

        <el-form-item v-if='showcclb' label="所属物流节点名称:" prop="sswljdmc"
          :rules="[{ required: true, message: '请输入所属物流节点名称', trigger: 'blur' }]">
          <el-input v-model="props.formData.sswljdmc" style="width: 250px" />
        </el-form-item>
        <el-form-item v-if='showcclb' label="仓储性质:" prop="jyckxz"
          :rules="[{ required: true, message: '请选择仓储性质', trigger: 'blur' }]">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JYCKXZ" v-model="props.formData.jyckxz" selectType="select"
              :disabled='ccxzdis' />
          </div>
        </el-form-item>
        <el-form-item v-if='showcclb' label="仓储形式:" prop="ccxs"
          :rules="[{ required: true, message: '请选择仓储形式', trigger: 'blur' }]">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JYCCXS" v-model="props.formData.ccxs" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="库容量:" prop="krl" v-if='showcclb'>
          <!-- v-if='showcclb && !(props.formData.ccwzlb == "02" || props.formData.ccwzlb == "04")'> -->
          <el-input v-model.number="props.formData.krl" type="number" style="width: 250px">
            <template #append>
              <span v-if='props.formData.ccwzlb == "10"'>担</span>

              <span v-else-if='props.formData.ccwzlb == "11"'>箱</span>
              <span
                v-else-if='props.formData.ccwzlb == "12" || props.formData.ccwzlb == "31" || props.formData.ccwzlb == "04"'>吨</span>
              <span v-else-if='props.formData.ccwzlb == "30" || props.formData.ccwzlb == "02"'>万支</span>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="建筑物结构:" prop="buildingStructure" v-if='props.formData.publicarea != "1"'>
          <MOSTY.DictTree :zdbh="'D_TB_JZWGGJG'" :type="'array'" v-model="props.formData.buildingStructure"
            :placeholder='"请选择结构:"' :disabled='false' style="width: 250px;" />
        </el-form-item>
        <el-form-item label="建筑物用途:" prop="buildingPurpose" v-if='props.formData.publicarea != "1" && !showcclb'>
          <MOSTY.DictTree :zdbh="'D_BZ_JZYTLX'" v-model="props.formData.buildingPurpose" :placeholder='"请选择用途:"'
            @onChange='nameChangeyt' :disabled='false' style="width: 250px;" />
        </el-form-item>
        <el-form-item label="复烤线数量:" prop="fkxsl" v-if='props.formData.buildingPurpose == "13"'
          :rules="[{ required: true, message: '请输入复烤线数量', trigger: 'blur' }]">
          <el-input v-model.number="props.formData.fkxsl" type="number" style="width: 250px">
            <template #append>条</template></el-input>
        </el-form-item>
        <el-form-item label="复烤线生产能力:" prop="fkxscnl" v-if='props.formData.buildingPurpose == "13"'
          :rules="[{ required: true, message: '请输入复烤线生产能力', trigger: 'blur' }]">
          <el-input v-model.number="props.formData.fkxscnl" type="number" style="width: 250px">
            <template #append>kg/h</template></el-input>
        </el-form-item>
        <!-- <el-form-item label="分拣线数量:" prop="fjxsl" v-if='props.formData.buildingPurpose == "12"'
          :rules="[{ required: true, message: '请输入分拣线数量', trigger: 'blur' }]">
          <el-input v-model.number="props.formData.fjxsl" type="number" style="width: 250px">
            <template #append>条</template></el-input>
        </el-form-item>
        <el-form-item label="分拣能力:" prop="fjnl" v-if='props.formData.buildingPurpose == "12"'
          :rules="[{ required: true, message: '请输入分拣能力', trigger: 'blur' }]">
          <el-input v-model.number="props.formData.fjnl" type="number" style="width: 250px">
            <template #append>条/小时</template></el-input>
        </el-form-item>
        <el-form-item label="笼车数量:" prop="lcsl" v-if='props.formData.buildingPurpose == "12"'
          :rules="[{ required: true, message: '请输入笼车数量', trigger: 'blur' }]">
          <el-input v-model.number="props.formData.lcsl" type="number" style="width: 250px">
          </el-input>
        </el-form-item> -->

        <el-form-item label="外墙保温材料性能:" prop="thermalMaterials" label-width="200px"
          v-if='props.formData.publicarea != "1"'>
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JZWWQBWCLXN" v-model="props.formData.thermalMaterials"
              selectType="select" :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="耐火等级:" prop="fireresisrating" v-if='props.formData.publicarea != "1"'
          :rules="[{ required: true, message: '请选择耐火等级', trigger: 'blur' }]">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_NHDJ" v-model="props.formData.fireresisrating" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <!-- 民用建筑 010000 -->
        <el-form-item label="火灾危险性分类:" v-if="props.formData.publicarea === '1'" label-width="200px">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JZWHZWXXLB" v-model="props.formData.fireLevel" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="火灾危险性分类:" v-if="props.formData.publicarea != '1'"
          :prop="['010100', '010200', '010900'].includes(props.formData.buildingstype) && props.formData.usesate != '2' ? '' : 'fireLevel'"
          label-width="200px">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JZWHZWXXLB" v-model="props.formData.fireLevel" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="土地性质:" v-if="props.formData.publicarea === '1'">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_TDXZ" v-model="props.formData.landproperty" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="土地性质:" v-if="props.formData.publicarea != '1'" prop="landproperty"
          :rules="[{ required: true, message: '请选择土地性质', trigger: 'blur' }]">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_TDXZ" v-model="props.formData.landproperty" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="房产权属:" v-if="props.formData.publicarea === '1'">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_FCQS" v-model="props.formData.houseproperty" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="房产权属:" v-if="props.formData.publicarea != '1'" prop="houseproperty">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_FCQS" v-model="props.formData.houseproperty" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="建造时间:" prop="startusetime" v-if='props.formData.publicarea != "1"'>
          <el-date-picker v-model="props.formData.startusetime" style="width: 250px" type="date"
            value-format="YYYY-MM-DD" placeholder="请选择建造时间" :disabled-date="disablednowDate1" @change='change()' />
        </el-form-item>
        <el-form-item label="使用情况:" prop="usesate">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_TB_CSZT" v-model="props.formData.usesate" selectType="select"
              :disabled="false" @onChange="usesateChange" />
          </div>
        </el-form-item>
        <el-form-item label="使用时间:" v-if="props.formData.usesate === '1'" prop="usetime">
          <el-date-picker v-model="props.formData.usetime" :disabled-date="disabledazrq" style="width: 250px"
            type="date" value-format="YYYY-MM-DD" placeholder="请选择使用时间" />
        </el-form-item>
        <el-form-item v-if="props.formData.usesate == '2' || props.formData.usesate == '3'" label="租赁时间:"
          prop="leasedate">
          <el-date-picker v-model="props.formData.leasedate" style="width: 250px" type="date" value-format="YYYY-MM-DD"
            placeholder="请选择租赁时间" />
        </el-form-item>
        <el-form-item v-if="props.formData.usesate == '2'" label="出租用途:" prop="czyt">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_JZWCZYT" v-model="props.formData.czyt" selectType="select"
              :disabled="false" />
          </div>
        </el-form-item>
        <!-- 闲置、出租面积区分一下 -->
        <el-form-item v-if="props.formData.usesate == '2'" label="出租面积:" prop="czmj">
          <el-input v-model.number="props.formData.czmj" type="number" style="width: 250px">
            <template #append>平方米</template></el-input>
        </el-form-item>
        <el-form-item v-if="props.formData.usesate == '4'" label="闲置面积:" prop="czmj">
          <el-input v-model.number="props.formData.czmj" @blur="props.formData.czmj = JEblurFn(props.formData.czmj)"
            type="number" style="width: 250px">
            <template #append>平方米</template></el-input>
        </el-form-item>

        <el-form-item label="使用状态:" prop="status" v-if="props.formData.id">
          <div style="width: 250px;">
            <MOSTY.DictRidioAndSelect :dictData="D_BZ_SYZT" v-model="props.formData.status" selectType="radio"
              :disabled="false" />
          </div>
        </el-form-item>
        <el-form-item label="是否配置消火栓系统:" prop="isConfigXhs" v-if="isShowBtn">
          <div style="width: 250px;">
            <el-select v-model="props.formData.isConfigXhs" clearable>
              <el-option label="是" :value="true" />
              <el-option label="否" :value="false" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="是否配置火灾自动报警系统:" prop="isConfigHzbj" v-if="isShowBtn">
          <div style="width: 250px;">
            <el-select v-model="props.formData.isConfigHzbj" clearable>
              <el-option label="是" :value="true" />
              <el-option label="否" :value="false" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="是否配置自动灭火系统:" prop="isConfigZdmh" v-if="isShowBtn">
          <div style="width: 250px;">
            <el-select v-model="props.formData.isConfigZdmh" clearable>
              <el-option label="是" :value="true" />
              <el-option label="否" :value="false" />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item style='width:100%;'
          v-if="props.formData.landproperty == '02' || props.formData.landproperty == '03'" label="土地证或征用收据:"
          label-width="200px">
          <MOSTY.Upload :widthNumber="800" :limit="3" :nopicer="true" :isImg="false" :ShowfileList="true"
            v-model="props.formData.landpropertyfile" :showinput="false" :delrow="delrow"></MOSTY.Upload>
        </el-form-item>
        <el-form-item style='width:100%;' v-if="props.formData.houseproperty == '01'" label="产权证明:" label-width="200px">
          <MOSTY.Upload :widthNumber="800" :limit="3" :nopicer="true" :isImg="false" :ShowfileList="true"
            v-model="props.formData.housepropertyfile" :showinput="false" :delrow="delrow"></MOSTY.Upload>
        </el-form-item>
        <el-form-item label="验收资料上传:" label-width="200px" style='width:100%;'>
          <MOSTY.Upload :widthNumber="800" :limit="20" :nopicer="true" :isImg="false" :ShowfileList="true"
            v-model="props.formData.yszlfj" :showinput="false" :delrow="delrow"></MOSTY.Upload>
        </el-form-item>
        <el-form-item :label="props.formData.publicarea == '1' ? '场区图片:' : '建筑物图片:'" label-width="200px"
          style='width:100%;'>
          <div style='display:flex;'>
            <MOSTY.Upload :width="'100%'" :limit="5" :nopicer="false" :isImg="true" :ShowfileList="false"
              v-model="props.formData.venuefile" :nameshow='true' :gsgfList="['jpg', 'png']"
              :disabled='!props.formData.saveBtnShow' @filehandleChange="changeFiles">
            </MOSTY.Upload>
          </div>
        </el-form-item>
      </el-form>
      <div v-if='props.formData.id'>
        <MOSTY.Assort :title="'关联信息(固定信息、动态信息)'" />
        <div>
          <div class='table-lable'>
            <span>固定信息</span>
            <img :src="getImgUrl('img/icon-jt.png')" style='cursor:pointer' @click='isShowgd = !isShowgd' />
          </div>
          <div v-show='isShowgd'>
            <MOSTY.TabList :tablist='tablist' :equipmentType="equipmentType" :obj='props.formData' :type='"jzw"'
              @handleChange="changelicolor" @resetChange='resetChange' />
          </div>
        </div>
        <div>
          <div class='table-lable'>
            <span>动态信息</span>
            <img :src="getImgUrl('img/icon-jt.png')" style='cursor:pointer' @click='isShowdt = !isShowdt' />
          </div>
          <div v-show='isShowdt'>
            <MOSTY.TabList :tablist='tablist2' :type='"jzw"' :obj='props.formData' @handleChange="changelicolor2" />
          </div>
        </div>
      </div>
    </template>
    <template #footer>
      <el-button type="primary" @click="saveData(ruleFormRef)" v-loading="saveloading"
        v-if='props.formData.saveBtnShow'> <el-icon>
          <DocumentChecked />
        </el-icon>保存 </el-button>
      <el-button @click="closeDialog"> <el-icon>
          <DocumentDelete />
        </el-icon>关闭</el-button>
    </template>
  </MOSTY.FromPage>

</template>

<script setup>
import { getImgUrl } from "@/utils/tools.js"
import { ref, getCurrentInstance, defineAsyncComponent, watch, onMounted, onUnmounted } from "vue";
import * as MOSTY from "@/components/MyComponents/index";
import { ElMessage } from "element-plus";
import * as rule from "@/utils/rules.js";
import { postApi, getApi } from "@/api/tobAcco_api.js";
import { Html2canvasImg } from "@/utils/html2pdf.js";
import { JEblurFn } from "@/utils/auth.js";
import { qrcodeImg, disablednowDate1 } from "@/utils/tools.js";
const { proxy } = getCurrentInstance();
const { D_TB_TDXZ, D_TB_CSZT, D_TB_FCQS, D_TB_NHDJ, D_BZ_JZWWQBWCLXN,
  D_BZ_JZWHZWXXLB, D_BZ_JYCKXZ, D_BZ_JYCCXS, D_BZ_SYZT, D_BZ_JZWCZYT,
} = proxy.$dict("D_TB_TDXZ", "D_TB_CSZT", "D_TB_FCQS", "D_TB_NHDJ", "D_BZ_JZWWQBWCLXN",
  "D_BZ_JZWHZWXXLB", "D_BZ_JYCKXZ", "D_BZ_JYCCXS", "D_BZ_SYZT",
  "D_BZ_JZWCZYT",);
const rules = {
  sitename: [{ required: true, message: "请输入场所名称", trigger: "blur" }],
  buildingname: [{ required: true, message: "请输入建筑物名称", trigger: "blur" }],
  houseproperty: [{ required: true, message: "请选择房屋结构", trigger: "blur" }],
  buildingstype: [{ required: true, message: "请选择建筑物类别", trigger: "blur" }],
  startusetime: [{ required: true, message: "请选择建造时间", trigger: "blur" }],
  usetime: [{ required: true, message: "请选择使用时间", trigger: "blur" }],
  thermalMaterials: [{ required: true, message: "请选择建筑物外墙保温材料性能", trigger: "change" }],
  buildingPurpose: [{ required: true, message: "请选择建筑用途", trigger: "change" }],
  buildingStructure: [{ required: true, message: "请选择建筑结构", trigger: "change" }],
  usesate: [{ required: true, message: "请选择使用情况", trigger: "change" }],
  isConfigXhs: [{ required: true, message: "请选择是否配置消火栓系统", trigger: "change" }],
  isConfigHzbj: [{ required: true, message: "请选择是否配置火灾自动报警系统", trigger: "change" }],
  isConfigZdmh: [{ required: true, message: "请选择是否配置自动灭火系统", trigger: "change" }],
  fireLevel: [{ required: true, message: "请选择火灾危险性分类", trigger: "change" }],
  leasedate: [{ required: true, message: "请选择租赁时间", trigger: "change" }],
  czyt: [{ required: true, message: "请选择出租用途", trigger: "change" }],
  ...rule.znumberRule({ validator: true, require: true }, "czmj"),
  publicarea: [{ required: true, message: "请选择是否为场区", trigger: "change" }],
  status: [{ required: true, message: "请选择使用状态", trigger: "change" }],
  houseproperty: [{ required: true, message: "请选择房产权属", trigger: "change" }],
  ...rule.znumberRule({ validator: true, require: true }, "area"),
  ...rule.znumberRule({ validator: true, require: true }, "coverArea"),
  ...rule.numbernineRule({ validator: true, require: true, iszs: true, firstNum: 10, lastNum: 4 }, "krl"),
  ...rule.znumberRule({ validator: true, require: true }, "high"),
  ...rule.intRule({ validator: true, require: true }, "abovegroundFloors"),
  ...rule.intfsRule({ validator: true, require: true }, "undergroundFloors"),
};

const isShowgd = ref(true)
const saveloading = ref(false)
const showcclb = ref(false)
const ccxzdis = ref(false)
const isShowdt = ref(true)
const jzwlxlist = ref([])
const ruleFormRef = ref();
const emits = defineEmits(["saveSuccess"]);
// 接收子组件传来的
const props = defineProps({
  formData: {
    type: Object,
    default: {}
  },
  type: {
    type: String,
    default: ''
  }
});
const ccwzlist = ref([
  { label: '原烟', value: '10' },
  { label: '片烟', value: '11' },
])

const tablist = ref([
  { title: '楼层', num: 0, icon: 'jianzhuwu', actives: true, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Storey.vue")) },
  { title: '安防设备设施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Security.vue")) },
  { title: '安防器材', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Apparatus.vue")) },
  { title: '消防设备设施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Security.vue")) },
  { title: '消防器材', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Apparatus.vue")) },
  // { title: '安全标识', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Safetysigns.vue")) },
  { title: '生产设备设施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Produce.vue")) },
  { title: '变配电设备设施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Distributing.vue")) },
  { title: '特种设备', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Equipment.vue")) },
])
const tablist2 = ref([
  { title: '风险清单', num: 0, icon: 'sbss2', actives: true, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Risklist.vue")) },
  { title: '隐患清单', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Pitfall.vue")) }
])
onMounted(() => {
  props.formData.area = props.formData.area ? Number(props.formData.area).toFixed(2) : null
  props.formData.coverArea = props.formData.coverArea ? Number(props.formData.coverArea).toFixed(2) : null
  props.formData.high = props.formData.high ? Number(props.formData.high).toFixed(2) : null
  props.formData.czmj = props.formData.czmj ? Number(props.formData.czmj).toFixed(2) : null
  if (props.formData.buildingstype && props.formData.buildingstype.indexOf('0202') == 0) {
    showcclb.value = true
  } else {
    showcclb.value = false
  }
  proxy.mittBus.on("mittxfss", (data) => {
    tablist.value[3].num = data
  });
  proxy.mittBus.on("mittxfqc", (data) => {
    tablist.value[4].num = data
  });
  proxy.mittBus.on("mittafss", (data) => {
    tablist.value[1].num = data
  });
  proxy.mittBus.on("mittafqc", (data) => {
    tablist.value[2].num = data
  });
  ccxzdis.value = props.formData.ccwzlb && (props.formData.ccwzlb == '12' || props.formData.ccwzlb == '30') ? true : false;
  if (props.formData.id) {
    if (props.formData.publicarea && props.formData.publicarea == '1') {
      props.formData.type = 'cq'
      tablist.value.unshift({ title: '重点部位', num: 0, icon: 'sbss2', actives: true, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Focalpoint.vue")) },
        { title: '非重点部位', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Focalpoint.vue")) })
      tablist.value = tablist.value.filter((item) => {
        return item.title !== '楼层';
      });
      getbwcount()
    } else {
      tablist.value = tablist.value.filter((item) => {
        return item.title !== '重点部位' && item.title !== '非重点部位';
      });
      getlccount()
    }
    getaqbscount()
    getscsbsscount()
    getbpdcount()
    // getaqqccount()
    gettzsbcount()
    // getaqsbsscount()
    getCount()
    if (props.formData.buildingPurpose == '0301') {
      tablist.value.push(
        { title: '防高坠措施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Falling.vue")) }
      )
      getfgzcount()
    } else {
      tablist.value = tablist.value.filter((item) => {
        return item.title !== '防高坠措施';
      });
    }
    isShowSelect()
  }
  if (props.type == 'ck') {
    getApi({ zdbh: 'D_TB_JCYWLX', dm: '0202', level: 4 }, '/mosty-base/sysDict/getJcyelxDictTree').then(res => {
      jzwlxlist.value = res[0].itemList
    })

  }

})
onUnmounted(() => {
  proxy.mittBus.off("mittxfss");
  proxy.mittBus.off("mittxfqc");
  proxy.mittBus.off("mittafss");
  proxy.mittBus.off("mittafqc");
});
function jzwlbchange(val) {
  if (val.dm.indexOf("0202") == 0) {
    showcclb.value = true
  } else {
    showcclb.value = false
  }
  if (props.formData.buildingstype == "020204" || props.formData.buildingstype == "020205") {
    props.formData.ccwzlb = null
  }
}
function ccwzchange(val) {
  if (val.dm) {
    if (val.dm == '12' || val.dm == '30') {
      props.formData.jyckxz = '1'
      ccxzdis.value = true

    } else {
      ccxzdis.value = false
    }
  } else {
    ccxzdis.value = false
  }


}
function disabledazrq(time) {
  return time.getTime() + 24 * 60 * 60 * 1000 < new Date(props.formData.startusetime).getTime() || time.getTime() > Date.now()
}
function change(type) {
  props.formData.usetime = ''
}
function nameChangeyt(val) {
  if (val.dm == '0301') {
    tablist.value.push(
      { title: '防高坠措施', num: 0, icon: 'sbss2', actives: false, components: defineAsyncComponent(() => import("@/components/MyComponents/TabList/Falling.vue")) }
    )
    getfgzcount()
  } else {
    tablist.value = tablist.value.filter((item) => {
      return item.title !== '防高坠措施';
    });

  }
  isShowSelect()
}
const usesateChange = () => {
  isShowSelect()
}
// 是否展示《是否配置消火栓系统》、《是否配置火灾自动报警系统》、《是否配置自动灭火系统》
const isShowBtn = ref(false)
const isShowSelect = () => {
  //建筑物在选择使用情况为 出租、闲置、在使用情况为使用且建筑物用途不是办公楼的时候
  if (props.formData.publicarea != '1'
    && ((props.formData.buildingPurpose != '01'
      && props.formData.usesate === '1')
      || (['2', '4'].includes(props.formData.usesate)))) {
    isShowBtn.value = true
  } else {
    isShowBtn.value = false
  }
}
//查询是否包含某个字符
function Isgetdm(str, zf) {
  if (str) {
    return str.indexOf(zf) == 0;
  }

}
//安全标识总数
function getaqbscount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sitelogo/countAllSitelogo').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '安全标识') {
        item.num = res ? res : 0
      }
    })
  })
}
//安全设备设施总数
function getaqsbsscount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sbglAqsbss/countAll').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '安防设备设施' && val === '1') {
        item.num = res ? res : 0
      }
      if (item.title == '消防设备设施' && val === '2') {
        item.num = res ? res : 0
      }
    })
  })

}
//特种设备总数
function gettzsbcount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sbglTzsb/countAll').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '特种设备') {
        item.num = res ? res : 0
      }
    })
  })
}
//安全器材总数
function getaqqccount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sbglAqqc/countAll').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '安全器材' && val === '1') {
        item.num = res ? res : 0
      }
      if (item.title == '消防器材' && val === '2') {
        item.num = res ? res : 0
      }
    })
  })
}
//生产设备设施总数
function getscsbsscount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sbglScsbss/countAll').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '生产设备设施') {
        item.num = res ? res : 0
      }
    })
  })
}
//变配电设备设施总数
function getbpdcount() {
  postApi({ buildingid: props.formData.id, type: '1' }, '/mosty-jcgl/sbglBpdsb/countAll').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '变配电设备设施') {
        item.num = res ? res : 0
      }
    })
  })
}
//获取风险清单总数
function getCount() {
  getApi({ buildingid: props.formData.id }, '/mosty-jcgl/dynamic/riskStatistics').then(res => {
    tablist2.value.forEach(item => {
      if (item.title == '风险清单') {
        item.num = res ? res.R + res.O + res.Y + res.B : 0
      }
    })
  })
}
//获取部位总数
function getbwcount() {
  getApi({ buildingid: props.formData.id }, '/mosty-jcgl/part/getCountById').then(res => {
    if (res) {
      tablist.value.forEach(item => {
        if (item.title == '重点部位') {
          item.num = res.zdbw ? res.zdbw : 0
        } else if (item.title == '非重点部位') {
          item.num = res.fzdbw ? res.fzdbw : 0
        }

      })
    }

  })
}
//楼层总数
function getlccount() {
  getApi({ id: props.formData.id }, '/mosty-jcgl/floor/countFloorByBuildId').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '楼层') {
        item.num = res ? res : 0
      }
    })

  })
}

//获取防高坠措施总数
function getfgzcount() {
  getApi({ buildid: props.formData.id }, '/mosty-jcgl/tobaccoHigh/countTobaccoHigh').then(res => {
    tablist.value.forEach(item => {
      if (item.title == '防高坠措施') {
        item.num = res ? res : 0
      }
    })
  })
}
function changelicolor2(val) {
  tablist2.value.forEach(item => {
    if (item.title == val.title) {
      item.actives = true
    } else {
      item.actives = false
    }
  })
  if (val.title == '风险清单') {
    getCount()
  }
}
// 关闭弹窗
function closeDialog() {
  if (props.formData.saveBtnShow) {
    proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
      .then(() => {
        ruleFormRef.value.clearValidate();
        ruleFormRef.value.resetFields()
        emits("saveSuccess");
      })
      .catch(() => {
        // catch error
      })
  } else {
    ruleFormRef.value.clearValidate();
    ruleFormRef.value.resetFields()
    emits("saveSuccess");
  }


}
// 保存数据
const saveData = async (formEl) => {
  saveloading.value = true
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      props.formData.venuefile = props.formData.venuefile
        ? props.formData.venuefile.toString()
        : null;
      props.formData.yszlfj = props.formData.yszlfj
        ? props.formData.yszlfj.toString()
        : null;
      props.formData.landpropertyfile = props.formData.landpropertyfile
        ? props.formData.landpropertyfile.toString()
        : null;
      props.formData.housepropertyfile = props.formData.housepropertyfile
        ? props.formData.housepropertyfile.toString()
        : null;
      props.formData.area = props.formData.area ? parseFloat(props.formData.area) : null
      props.formData.coverArea = props.formData.coverArea ? parseFloat(props.formData.coverArea) : null
      props.formData.high = props.formData.high ? parseFloat(props.formData.high) : null
      props.formData.czmj = props.formData.czmj ? parseFloat(props.formData.czmj) : null
      props.formData.numberfloors = props.formData.abovegroundFloors + props.formData.undergroundFloors
      if (props.formData.ccwzlb == "10") {
        props.formData.krldw = '1'
      } else if (props.formData.ccwzlb == "11") {
        props.formData.krldw = '2'
      } else if (props.formData.ccwzlb == "12" || props.formData.ccwzlb == "31") {
        props.formData.krldw = '4'
      } else if (props.formData.ccwzlb == "30") {
        props.formData.krldw = '3'
      }
      if (!isShowBtn.value) {
        props.formData.isConfigXhs = null
        props.formData.isConfigHzbj = null
        props.formData.isConfigZdmh = null
      }
      if (!props.formData.id) {
        props.formData.status = '01'
        postApi(props.formData, "/mosty-jcgl/building/addSceneBuildingsOne").then((res) => {
          if (res) {
            ElMessage.success("新增成功");
            emits("saveSuccess", res);
          }
        }).finally(() => {
          saveloading.value = false
        })
      } else {
        postApi(props.formData, "/mosty-jcgl/building/updateSceneBuildingsOne").then((res) => {
          ElMessage.success("修改成功");
          emits("saveSuccess");
        }).finally(() => {
          saveloading.value = false
        })
      }
    } else {
      ElMessage.warning('请输入必填项！！！')
      saveloading.value = false
    }
  })
};
const equipmentType = ref()
//分类点击事件
function changelicolor(val) {
  tablist.value.forEach(item => {
    if (item.title == val.title) {
      item.actives = true
    } else {
      item.actives = false
    }
  })
  if (val.title == '安防设备设施') {
    equipmentType.value = 1
    //  getaqsbsscount('1')
  } else if (val.title == '消防设备设施') {
    equipmentType.value = 0
    //  getaqsbsscount('2')
  } else if (val.title == '安防器材') {
    equipmentType.value = 1
    //  getaqqccount('1')
  } else if (val.title == '消防器材') {
    equipmentType.value = 0
    //  getaqqccount('2')
  }
  // else if (val.title == '安全标识') {
  //   getaqbscount()
  // }
  else if (val.title == '生产设备设施') {
    getscsbsscount()
  } else if (val.title == '变配电设备设施') {
    getbpdcount()
  } else if (val.title == '特种设备') {
    gettzsbcount()
  } else if (val.title == '楼层') {
    getlccount()
  } else if (val.title == '重点部位' || val.title == '非重点部位') {
    getbwcount()
  } else if (val.title == '年复烤量') {
    // getfklcount()
  } else if (val.title == '年配送量') {
    // getpslcount()
  } else if (val.title == '防高坠措施') {
    getfgzcount()
  } else if (val.title == '年收购量') {
    // getsglcount()
  }


}
//刷新接口
function resetChange(val) {
  if (val == 'lc') {
    getlccount()
  } else if (val == 'aqbs') {
    getaqbscount()
  } else if (val == 'bw') {
    getbwcount()
  } else if (val == 'scsb') {
    getscsbsscount()
  } else if (val == 'bpdsb') {
    getbpdcount()
  } else if (val == 'aqqc') {
    // getaqqccount()
  } else if (val == 'tzsb') {
    gettzsbcount()
  } else if (val == 'aqsbss') {
    // getaqsbsscount()
  } else if (val == 'nfkl') {
    // getfklcount()
  } else if (val == 'fgzcs') {
    getfgzcount()
  } else if (val == 'nsgl') {
    // getsglcount()
  } else if (val == 'npsl') {
    // getpslcount()
  }
}


</script>

<style lang="scss" scoped>
/* 隐藏Vuetify数字输入组件中的增减按钮 */
//去掉number输入框的上下箭头
::v-deep .no_number input::-webkit-inner-spin-button,
::v-deep .no_number input::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
}

::v-deep .no_number input[type="number"] {
  -moz-appearance: textfield;
}

::v-deep .el-form-item__content {
  margin-left: 0px !important;
}

::v-deep .el-form {
  // width: 1580px;
  margin: auto;
  padding: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: start;
  // padding: 10px 56px !important;
}

.table-lable {
  margin: 10px;
  color: var(--el-color-primary);
}

::v-deep ::-webkit-scrollbar {
  display: none !important;
}



::v-deep .el-pagination {
  justify-content: center !important;
}
</style>
