<template>
  <div class="bigBox" :style="{ height: bigHeight }">

    <div class="right">
      <!-- 头部 -->
      <div class="titleBox">
        <div class="title">{{ props.title }}</div>
        <div class="btnBox">
          <el-button style="margin-left: 10px" type="primary" @click="handlSave(ruleFormRef)" v-if="otherBtn">
            <el-icon>
              <DocumentChecked />
            </el-icon>
            <span>保存</span>
          </el-button>

          <el-button style="margin-left: 10px" type="primary" @click="handleSave(ruleFormRef)"
            v-if="props.saveBtnShow && !otherBtn">
            <el-icon>
              <DocumentChecked />
            </el-icon>
            <span>保存</span>
          </el-button>
          <el-button type="primary" @click="back" v-if="otherBtn">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
          <el-button type="primary" @click="CloseEvent" v-if="!otherBtn">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </div>
      </div>
      <div class="box_cont">
        <div class="searchBox" ref="searchBox">
          <el-form class="mosty-from-wrap" ref="ruleFormRef" label-width="130px" :model="fromObj" :inline="true"
            :rules="rules" :disabled="!props.saveBtnShow">
            <el-form-item label="设备名称:" prop="name">
              <el-input v-model="fromObj.name" maxlength="20" autosize type="textarea" show-word-limit
                placeholder="不能超过20个字" style="width: 250px" />
            </el-form-item>
            <el-form-item label="电气设备类型:" v-if="otheroptionshow">
              <el-select :disabled="disabled" v-model="fromObj.zdname" :disable="otherBtn" style="width: 250px"
                clearable placeholder="请选择">
                <el-option v-for="item in D_BZ_DQSBLX" :key="item" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="电气设备类型:" v-if="!otheroptionshow">
              <el-select :disabled="disabled" v-model="fromObj.zdname" :disable="otherBtn" style="width: 250px"
                clearable placeholder="请选择：">
                <el-option v-for="item in options" :key="item" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="场所名称:" prop="placename">
              <el-select v-model="placename" style="width: 250px" @change="cahngecsmc" clearable placeholder="请选择">
                <el-option v-for="item in csmclist" :key="item" :label="item.placename" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="部位名称:">
              <el-select v-model="allname" style="width: 250px" @change="cahngebw" clearable placeholder="请选择">
                <el-option v-for="item in bwlist" :key="item" :label="item.allname" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="品牌:">
              <el-input v-model="fromObj.brand" maxlength="20" type="textarea" show-word-limit placeholder="不能超过20个字"
                style="width: 250px" />
            </el-form-item>
            <el-form-item label="型号:">
              <el-input v-model="fromObj.model" clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="功率:">
              <el-input v-model="fromObj.power" clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="内部编号:">
              <el-input v-model="fromObj.innerno" clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="安装时间:">
              <el-date-picker v-model="fromObj.installtime" style="width: 250px" type="date" value-format="YYYY-MM-DD"
                placeholder="请选择安装时间" />
            </el-form-item>
            <div class="ld_box">
              <el-form-item label="责任人:" prop="responsibilitypersonname">
                <el-input v-model="fromObj.responsibilitypersonname" disabled style="width: 170px" />
              </el-form-item>
              <el-button type="primary" @click="ChooesDdld('01')">选择</el-button>
            </div>
            <el-form-item label="责任部门:">
              <el-input v-model="fromObj.responsibilitydeptname" maxlength="20" type="textarea" show-word-limit
                placeholder="不能超过20个字" disabled clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="状态:">
              <el-select v-model="fromObj.state" style="width: 250px" clearable placeholder="请选择状态：">
                <el-option v-for="item in D_BZ_SBSSZT" :key="item" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="投资金额(万元):">
              <el-input v-model="fromObj.money" type="number" clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="检查标准:">
              <el-select v-model="fromObj.checkstandard" style="width: 250px" clearable placeholder="请选择检查标准：">
                <el-option v-for="item in D_TB_JCBZLB" :key="item" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>

            <el-form-item label="单位:">
              <el-select v-model="fromObj.unit" style="width: 250px" clearable placeholder="请选择单位：">
                <el-option v-for="item in D_BZ_WPDW" :key="item" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="装置数量:">
              <el-input v-model="fromObj.number" type="number" clearable style="width: 250px" />
            </el-form-item>
            <el-form-item label="安装位置:">
              <el-input v-model="fromObj.installlocation" clearable style="width: 700px" />
            </el-form-item>

            <el-collapse v-model="activeNames" :disabled="true" style="width: 100%;">
              <el-collapse-item title="电气设备二维码" name="1" v-if="fromObj.id">
                <el-form-item label="" label-width="30px !important">
                  <MOSTY.ErwmImg
                    :url="qrcodeImg(fromObj.id, '102', placename, allname, `${fromObj.name}(${fromObj.innerno})`)"
                    :filename='"电气设备二维码"' :id='"htmlsmewmdqsb"' />
                </el-form-item>
              </el-collapse-item>
              <el-collapse-item title="电器设备附件信息列表" name="2">
                <div class="mt7">
                  <el-button class="addbtn" type="primary" @click="addShowinput">
                    <el-icon>
                      <CirclePlus />
                    </el-icon>
                    <span>新增</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="submittab">
                    <el-icon>
                      <Select />
                    </el-icon>
                    <span>保存</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="deletetab">
                    <el-icon>
                      <DeleteFilled />
                    </el-icon>
                    <span>删除</span>
                  </el-button>
                </div>
                <div class="tabbox">
                  <el-table :data="fromObj.tbSbglElectricEquipmentAttas" border stripe style="width: 100%"
                    :height="tableHeight" :key="keyCount" @current-change="handleCurrentChange">
                    <el-table-column sortable prop="userName" align="center" label="设备名称">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="50" v-model="row.name" />
                        <span v-else>{{ row.name }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="brand" label="品牌">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="50" v-model="row.brand" />
                        <span v-else>{{ row.brand }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="model" align="center" label="型号">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="50" v-model="row.model" />
                        <span v-else>{{ row.model }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="installtime" align="center" label="安装时间">
                      <template #default="{ row }">
                        <el-date-picker v-if="row.input == true" v-model="row.installtime" style="width: 100%"
                          value-format="YYYY-MM-DD" type="date" />
                        <span v-else>{{ row.installtime }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="number" align="center" label="数量">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="number" v-model="row.number" />
                        <span v-else>{{ row.number }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="unit" align="center" label="单位">
                      <template #default="{ row }">
                        <el-select v-if="row.input == true" v-model="row.unit" style="width: 100%" clearable
                          placeholder="请选择单位：">
                          <el-option v-for="item in D_BZ_WPDW" :key="item" :label="item.label" :value="item.value" />
                        </el-select>
                        <dict-tag v-else :options="D_BZ_WPDW" :value="row.unit" :tag="false" />
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="bz" align="center" label="备注">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="500" v-model="row.bz" />
                        <span v-else>{{ row.bz }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>
              <el-collapse-item title="检测记录信息列表" name="3">
                <div class="mt7">
                  <el-button class="addbtn" type="primary" @click="addjcinput">
                    <el-icon>
                      <CirclePlus />
                    </el-icon>
                    <span>新增</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="submitjctab">
                    <el-icon>
                      <Select />
                    </el-icon>
                    <span>保存</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="deletejctab">
                    <el-icon>
                      <DeleteFilled />
                    </el-icon>
                    <span>删除</span>
                  </el-button>
                </div>
                <div class="tabbox">
                  <el-table :data="fromObj.tbInspectionrecords" border stripe style="width: 100%" :height="tableHeight"
                    :key="keyCount" @current-change="handlecheckChange">
                    <el-table-column sortable prop="detectionmechanism" align="center" label="检测机构">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="50" v-model="row.detectionmechanism" />
                        <span v-else>{{ row.detectionmechanism }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="testdescription" label="检测描述">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="200" v-model="row.testdescription" />
                        <span v-else>{{ row.testdescription }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="expirationdate" align="center" label="有限期限">
                      <template #default="{ row }">
                        <el-date-picker v-if="row.input == true" v-model="row.expirationdate" style="width: 100%"
                          type="date" value-format="YYYY-MM-DD" />
                        <span v-else>{{ row.expirationdate }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="status" align="center" label="检测状态">
                      <template #default="{ row }">
                        <el-select v-if="row.input == true" v-model="row.status" style="width: 100%" clearable>
                          <el-option v-for="item in D_BZ_JCZT" :key="item" :label="item.label" :value="item.value" />
                        </el-select>
                        <dict-tag v-else :options="D_BZ_JCZT" :value="row.status" :tag="false" />
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="file" align="center" label="检测报告">
                      <template #default="scope">
                        <span class="operate" style="color: yellowgreen"
                          @click="handleChangefj(scope.$index, scope.row)">附件</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>
              <el-collapse-item title="维保记录列表" name="4" v-if="props.wbjlShow">
                <div class="mt7">
                  <el-button class="addbtn" type="primary" @click="addwbinput">
                    <el-icon>
                      <CirclePlus />
                    </el-icon>
                    <span>新增</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="submitwbtab">
                    <el-icon>
                      <Select />
                    </el-icon>
                    <span>保存</span>
                  </el-button>
                  <el-button class="addbtn" type="primary" @click="deletewbtab">
                    <el-icon>
                      <DeleteFilled />
                    </el-icon>
                    <span>删除</span>
                  </el-button>
                </div>
                <div class="tabbox">
                  <el-table :data="fromObj.tbMaintenanceRecords" border stripe style="width: 100%" :height="tableHeight"
                    :key="keyCount" @current-change="handlewbChange">
                    <el-table-column sortable prop="maintenanceorg" align="center" label="维保单位">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="50" v-model="row.maintenanceorg" />
                        <span v-else>{{ row.maintenanceorg }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="maintenancepeople" label="维保人">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="200" v-model="row.maintenancepeople" />
                        <span v-else>{{ row.maintenancepeople }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="maintenancetel" label="维保电话">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="number" v-model="row.maintenancetel" />
                        <span v-else>{{ row.maintenancetel }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="maintenancedescription" label="维保描述">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="200"
                          v-model="row.maintenancedescription" />
                        <span v-else>{{ row.maintenancedescription }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="maintenancetime" align="center" label="维保时间">
                      <template #default="{ row }">
                        <el-date-picker v-if="row.input == true" v-model="row.maintenancetime" style="width: 100%"
                          type="date" value-format="YYYY-MM-DD" />
                        <span v-else>{{ row.maintenancetime }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column sortable prop="bz" label="备注">
                      <template #default="{ row }">
                        <input v-if="row.input == true" type="text" maxlength="200" v-model="row.bz" />
                        <span v-else>{{ row.bz }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>
              <el-collapse-item title="检查日志列表" name="5" v-if="props.jcrzShow">
                <div class="tabbox">
                  <el-table :data="fromObj.tbTaskcheckLogs" border stripe style="width: 100%" :height="tableHeight"
                    :key="keyCount">
                    <el-table-column sortable prop="checkuser" align="center" show-overflow-tooltip label="检查人">
                    </el-table-column>
                    <el-table-column sortable prop="checktime" label="检查日期">
                    </el-table-column>
                    <el-table-column sortable prop="checkdescription" align="center" show-overflow-tooltip label="检查描述">
                    </el-table-column>
                    <el-table-column sortable prop="quantityofpitfall" align="center" label="隐患数量">
                    </el-table-column>
                  </el-table>
                </div>
              </el-collapse-item>
            </el-collapse>
          </el-form>
        </div>
      </div>
    </div>
    <!-- 选择带队领导 -->
    <ChooseUser v-model="chooseUserVisible" :Single="singleShow" :data="memberList" :leaderid="leaderid"
      :deptId="fromObj.responsibilitydept" @choosedUsers="getSonValue"></ChooseUser>
    <!-- 附件弹出框 -->
    <MOSTY.FileTable v-model="dialogVisible" :fileId="fjidlist.fileId" @closedialog="closedialog" @savefile="savefile"
      :showBtn="props.saveBtnShow"></MOSTY.FileTable>

  </div>
</template>

<script setup>
import {
  ref,
  onMounted,
  defineProps,
  defineEmits,
  computed,
  reactive,
  watch,
  watchEffect,
  getCurrentInstance
} from "vue";
import { filterYear } from "@/utils/auth.js";
import * as MOSTY from "@/components/MyComponents/index";
import { ElMessage } from "element-plus";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
import ChooseUser from "@/components/MyComponents/ChooseUser/Leader.vue";
import { useRouter } from "vue-router";
import { keysOf } from "element-plus/lib/utils";
import { qrcodeImg, createAndClickLink } from "@/utils/tools.js";
import { Html2canvasImg } from "@/utils/html2pdf.js";

const router = useRouter();
const { proxy } = getCurrentInstance();
const { D_BZ_SBSSZT, D_BZ_WPDW, D_TB_JCBZLB, D_BZ_DQSBLX, D_BZ_JCZT } =
  proxy.$dict(
    "D_BZ_SBSSZT",
    "D_BZ_WPDW",
    "D_TB_JCBZLB",
    "D_BZ_DQSBLX",
    "D_BZ_JCZT"
  );
// import Addaqry from "./addaqry.vue";
const rules = reactive({
  name: [{ required: true, message: "设备名称不能为空", trigger: "blur" }],
  placename: [{ required: true, message: "场所名称不能为空", trigger: "blur" }],
  allname: [{ required: true, message: "部位名称不能为空", trigger: "blur" }],
  responsibilitypersonname: [
    { required: true, message: "责任人不能为空", trigger: "blur" }
  ],
  type1: [{ required: true, message: "类型不能为空", trigger: "blur" }]
});
const props = defineProps({
  addDiaShow: {
    type: Boolean,
    default: false
  },
  rowid: {
    type: String,
    default: null
  },
  otherObj: {
    type: Object,
    default: () => { }
  },
  otherBtn: {
    default: false,
    type: Boolean
  },
  deptname: {
    type: Object,
    default: () => { }
  },
  title: String,
  saveBtnShow: {
    default: true,
    type: Boolean
  },
  wbjlShow: {
    default: false,
    type: Boolean
  },
  jcrzShow: {
    default: false,
    type: Boolean
  }
});
const csId = ref(null)
const ruleFormRef = ref();
const placename = ref("");
const allname = ref("");
const activeNames = ref(1);
const emits = defineEmits(["close"]);
const dialogVisible = ref(false);
const delrow = ref({});
const currentRow = ref(); //选中的表格数据
const currentRowjc = ref(); //选中的表格数据
const chooseUserVisible = ref(false); //选择领导弹窗
const singleShow = ref(true); //单选多选
const memberList = ref([]); //成员选择的id回显
const leaderid = ref("");
const zzlx = ref(null);
const fileindex = ref(0);
const fjtableData = ref([]);
const bwlist = ref([]);
const fjidlist = reactive({});
const CloseEvent = () => {
  // 关闭上一次的表单校验
  ruleFormRef.value.clearValidate();
  emits("close");
};
const fromObj = ref({})
const csmclist = ref([]);
//点击带队领导选择按钮
function ChooesDdld(val) {
  zzlx.value = val;
  leaderid.value = "";
  if (val == "01") {
    leaderid.value = fromObj.value.responsibilityperson;
  }
  singleShow.value = true;
  chooseUserVisible.value = true;
}
const isDisabled = ref(false);
const otheroptionshow = ref(true);
const disabled = computed(() => isDisabled.value);
const options = reactive([
  {
    value: "1",
    label: "高压变压器"
  },
  { value: "2", label: "低压变压器" }
]);

onMounted(() => {
  if (props.rowid) {
    getxqData(props.rowid)
  } else {
    fromObj.value = {}
  }
  if (props.otherObj) {
    if (props.otherObj.zdname == "13") {
      isDisabled.value = true;
      fromObj.value.zdname = props.otherObj.zdname;
    }
    if (props.otherObj.zdname == "14") {
      otheroptionshow.value = false;
    }
  }
  activeNames.value = ["1", "2", '3', '4', '5'];
  getcsData();
});
//获取详情
function getxqData(id) {
  getApi({ id: id }, "/mosty-jcgl/dqsb/querySbglDqsbById").then((res) => {
    if (res) {
      fromObj.value = res;
      allname.value = fromObj.value.partname;
      placename.value = fromObj.value.placename;
      if (fromObj.value.files) {
        if (fromObj.value.files.index0f("[") != -1) {
          fromObj.value.files = JSON.parse(fromObj.value.files)
        } else {
          fromObj.value.files = fromObj.value.files.split(",");
        }
      }
    }
  });
}
//根据操作人 查询 场所
function getcsData() {
  getApi({}, "/mosty-jcgl/site/getSiteListByUser").then((res) => {
    csmclist.value = res;
  });
}

//获取场所选择
const cahngecsmc = (val) => {
  csmclist.value.forEach((item) => {
    if (item.id == val) {
      fromObj.value.placeid = item.id;
      fromObj.value.placename = item.placename;
      csId.value = item.id
    }
  });
  getbwdata(csId.value)
};
//根据操作人 获取部位信息
function getbwdata(id) {
  getApi({ partId: id }, "/mosty-jcgl/part/getpartListByUser").then((res) => {
    bwlist.value = res;
  });
}
//获取当前部位
const cahngebw = (val) => {
  bwlist.value.forEach((item) => {
    if (item.id == val) {
      fromObj.value.partid = item.id;
      fromObj.value.partname = item.areaname;
    }
  });
};
const getSonValue = (value) => {
  if (zzlx.value == "01") {
    fromObj.value.responsibilitypersonname = value[0].userName;
    fromObj.value.responsibilityperson = value[0].id;
    fromObj.value.responsibilitydept = value[0].deptId;
    fromObj.value.responsibilitydeptname = value[0].deptName;
  }
};
//新增电气设备表格
function addShowinput() {
  let tab = {
    name: "",
    brand: "",
    model: "",
    installtime: "",
    number: "",
    unit: "",
    bz: "",
    input: true
  };
  if (fromObj.value.tbSbglElectricEquipmentAttas) {
    fromObj.value.tbSbglElectricEquipmentAttas.push(tab);
  } else {
    let arr = [];
    arr.push(tab);
    fromObj.value.tbSbglElectricEquipmentAttas = arr;
  }
}
//保存表格数据
function submittab() {
  fromObj.value.tbSbglElectricEquipmentAttas.forEach((el) => {
    el.input = false;
  });
}
//删除表格数据
function deletetab() {
  fromObj.value.tbSbglElectricEquipmentAttas.forEach((item, index) => {
    if (currentRow.value == item) {
      fromObj.value.tbSbglElectricEquipmentAttas.splice(index, 1);
    }
  });
}
//选中当前表格行
function handleCurrentChange(val) {
  currentRow.value = val;
  if (props.saveBtnShow) {
    fromObj.value.tbSbglElectricEquipmentAttas.forEach((el) => {
      if (el == val) {
        el.input = true;
      } else {
        el.input = false;
      }
    });
  }

}
function handlecheckChange(val) {
  currentRowjc.value = val;
  if (props.saveBtnShow) {
    fromObj.value.tbInspectionrecords.forEach((el) => {
      if (el == val) {
        el.input = true;
      } else {
        el.input = false;
      }
    });
  }

}

//新增检测记录表格
function addjcinput() {
  let tab = {
    detectionmechanism: "",
    testdescription: "",
    expirationdate: "",
    status: "",
    file: "",
    input: true
  };
  if (fromObj.value.tbInspectionrecords) {
    fromObj.value.tbInspectionrecords.push(tab);
  } else {
    let arr = [];
    arr.push(tab);
    fromObj.value.tbInspectionrecords = arr;
  }
}
//保存表格数据
function submitjctab() {
  fromObj.value.tbInspectionrecords.forEach((el) => {
    el.input = false;
  });
}
//删除表格数据
function deletejctab() {
  fromObj.value.tbInspectionrecords.forEach((item, index) => {
    if (currentRowjc.value == item) {
      fromObj.value.tbInspectionrecords.splice(index, 1);
    }
  });
}
const currentRowwb = ref(); //选中的表格数据
//新增维保记录表格
function addwbinput() {
  let tab = {
    maintenanceorg: "",
    maintenancepeople: "",
    maintenancetel: "",
    maintenancedescription: "",
    maintenancetime: "",
    bz: "",
    input: true
  };
  if (fromObj.value.tbMaintenanceRecords) {
    fromObj.value.tbMaintenanceRecords.push(tab);
  } else {
    let arr = [];
    arr.push(tab);
    fromObj.value.tbMaintenanceRecords = arr;
  }
}
//保存表格数据
function submitwbtab() {
  fromObj.value.tbMaintenanceRecords.forEach((el) => {
    el.input = false;
  });
}
//删除表格数据
function deletewbtab() {
  fromObj.value.tbMaintenanceRecords.forEach((item, index) => {
    if (currentRowwb.value == item) {
      fromObj.value.tbMaintenanceRecords.splice(index, 1);
    }
  });
}
//选中当前表格行
function handlewbChange(val) {
  currentRowwb.value = val;
  if (props.saveBtnShow) {
    fromObj.value.tbMaintenanceRecords.forEach((el) => {
      if (el == val) {
        el.input = true;
      } else {
        el.input = false;
      }
    });
  }
}
const savefile = (val) => {
  fromObj.value.tbInspectionrecords[fileindex.value].file =
    val.toString();
  dialogVisible.value = false;
};
function closedialog(val) {
  dialogVisible.value = val;
}
//附件详情弹窗
function handleChangefj(index, row) {
  fjidlist.fileId = row.file ? row.file.split(",") : null;
  fileindex.value = index;
  dialogVisible.value = true;
}
const handlSave = async (ruleFormRef) => {
  if (!ruleFormRef) return;
  await ruleFormRef.validate((valid) => {
    if (valid) {
      fromObj.value.orgcode = props.otherObj.parentId;
      if (fromObj.value.tbInspectionrecords) {
        fromObj.value.tbInspectionrecords.forEach((e) => {
          if (e.file) {
            e.file = e.file.toString();
          }
        });
      } else {
        fromObj.value.tbInspectionrecords = [];
      }
      fromObj.value.tbMaintenanceRecords
        ? fromObj.value.tbMaintenanceRecords
        : (fromObj.value.tbMaintenanceRecords = []);
      fromObj.value.tbSbglElectricEquipmentAttas
        ? fromObj.value.tbSbglElectricEquipmentAttas
        : (fromObj.value.tbSbglElectricEquipmentAttas = []);
      fromObj.value.tbTaskcheckLogs
        ? fromObj.value.tbTaskcheckLogs
        : (fromObj.value.tbTaskcheckLogs = []);
      if (fromObj.value) {
        if (props.title == "烟叶站电气设备新增") {
          postApi(fromObj.value, "/mosty-jcgl/dqsb/addSbglDqsbOne")
            .then((res) => {
              ElMessage.success("新增成功");
              router.push({
                path: props.otherObj.routepath,
                query: props.otherObj
              });
            })

        } else if (props.title == "烟叶站电气设备修改") {
          postApi(fromObj.value, "/mosty-jcgl/dqsb/updateSbglDqsbOne")
            .then((res) => {
              ElMessage.success("修改成功");
              router.push({
                path: props.otherObj.routepath,
                query: props.otherObj
              });
            })

        }
      }
    } else {
      ElMessage.error("表单验证失败，请检查输入内容");
    }
  });
};
const back = () => {
  router.push({
    path: props.otherObj.routepath,
    query: props.otherObj
  });
};
// 保存
const handleSave = async (ruleFormRef) => {
  if (!ruleFormRef) return;
  await ruleFormRef.validate((valid) => {
    if (valid) {
      if (fromObj.value.tbInspectionrecords) {
        fromObj.value.tbInspectionrecords.forEach((e) => {
          if (e.file) {
            e.file = e.file.toString();
          }
        });
      } else {
        fromObj.value.tbInspectionrecords = [];
      }
      fromObj.value.tbMaintenanceRecords
        ? fromObj.value.tbMaintenanceRecords
        : (fromObj.value.tbMaintenanceRecords = []);
      fromObj.value.tbSbglElectricEquipmentAttas
        ? fromObj.value.tbSbglElectricEquipmentAttas
        : (fromObj.value.tbSbglElectricEquipmentAttas = []);
      fromObj.value.tbTaskcheckLogs
        ? fromObj.value.tbTaskcheckLogs
        : (fromObj.value.tbTaskcheckLogs = []);
      if (fromObj.value) {
        if (props.title == "电气设备新增") {
          postApi(fromObj.value, "/mosty-jcgl/dqsb/addSbglDqsbOne")
            .then((res) => {
              ElMessage.success("新增成功");
              emits("close");
            })

        } else if (props.title == "电气设备编辑") {
          postApi(fromObj.value, "/mosty-jcgl/dqsb/updateSbglDqsbOne")
            .then((res) => {
              ElMessage.success("修改成功");
              emits("close");
            })

        }
      }
    } else {
      ElMessage.error("请输入必填项");
    }
  });
};
</script>

<style lang="scss" scoped>
::v-deep .el-collapse {
  width: 100% !important;
}

.box_cont {
  height: calc(100vh - 15vh);
  overflow-y: scroll;
}

.searchBox {
  width: 1333px;
  margin: 20px auto;
}

.ld_box {
  display: flex;
  margin-right: 20px;
}



.el-form {
  width: 100%;
  align-items: center;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.el-form-item {
  display: flex;
  margin-right: 20px;
}

.addbtn {
  margin-bottom: 10px;
}

.bigBox {
  display: block !important;
  padding: 0 14px;
  box-sizing: border-box;
}

.tabbox {
  max-height: 300px;
  overflow-y: scroll;

  .input {
    width: 100%;
    height: 100%;
  }
}

::v-deep .el-table .cell {
  padding: 0 0 !important;
}

::v-deep .el-table--border .el-table__cell .cell {
  padding-left: 0px !important;

  >input {
    width: 100%;
    height: 33px;
  }
}

::v-deep .el-upload-list {
  width: 50%;
}
</style>