<template>
  <div>
    <MOSTY.FromPage :title="data.config.title" @closeDialog="black">
      <template #content>
        <div class="fromBoxs pb20">
          <el-form ref="ruleFormRef" :model="data.fromObj" :rules="rules" label-width="140px" label-suffix="："
            status-icon :inline="true" :disabled="!props.editObj.saveBtnShow && !props.editObj.pingGSaveBtnShow">
            <el-form-item label="预案名称" prop="planname" @click="clickYaInput">
              <el-input v-model="data.fromObj.planname" readonly placeholder="请选择预案名称"
                :disabled="!props.editObj.saveBtnShow" style="width:250px"></el-input>
            </el-form-item>
            <el-form-item label="部门负责人" prop="jhdeptusername">
              <el-input v-model="data.fromObj.jhdeptusername" placeholder="请选择部门负责人" readonly style="width:250px"
                :disabled="!props.editObj.saveBtnShow">
                <template #append>
                  <el-button class='cursor' @click="chooseUserOrDept('01')">选择</el-button></template>
              </el-input>
            </el-form-item>
            <el-form-item label="业务分管领导" prop="jhfgldname">
              <el-input v-model="data.fromObj.jhfgldname" readonly placeholder="请输入业务分管领导" style="width:250px"
                :disabled="!props.editObj.saveBtnShow">
                <template #append>
                  <el-button class='cursor' @click="chooseUserOrDept('02')">选择</el-button></template>
              </el-input>
            </el-form-item>
            <el-form-item label="预计参演人数" prop="yjcyrs">
              <el-input v-model="data.fromObj.yjcyrs" type="number" placeholder="预计参演人数" style="width:250px"
                :disabled="props.editObj.type == 'ss' || !props.editObj.saveBtnShow"></el-input>
            </el-form-item>
            <el-form-item label="演练方式" prop="plantype">
              <el-select v-model="data.fromObj.plantype" placeholder="请选择演练方式" style="width:250px"
                :disabled="props.editObj.type == 'ss' || !props.editObj.saveBtnShow">
                <el-option v-for="item in D_TB_YLFS" :key="item.value" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="实施次数" prop="frequency" v-if="props.editObj.type == 'add'">
              <el-select v-model="data.fromObj.frequency" placeholder="请选择实施次数" style="width:250px"
                :disabled="!props.editObj.saveBtnShow">
                <el-option label="一次" value="1"></el-option>
                <el-option label="两次" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="演练日期" prop="playdate">
              <el-date-picker v-model="data.fromObj.playdate" type="date" placeholder="请选择演练日期" style="width:250px"
                :disabled="!props.editObj.saveBtnShow" value-format="YYYY-MM-DD" />
            </el-form-item>
            <el-form-item label="演练评估次数" prop="emergencyDrillEvaluationQty">
              <el-input-number v-model="data.fromObj.emergencyDrillEvaluationQty" :min="0" :max="99999"
                style="width: 250px;" :disabled="!props.editObj.saveBtnShow" />
              <!-- <el-input v-model="data.fromObj.emergencyDrillEvaluationQty" type="number" min="0" max="99999" step="1" placeholder="演练评估次数" style="width: 250px"></el-input> -->
            </el-form-item>
            <el-form-item label="演练评估次数" style="opacity: 0;">
              <el-input style="width: 250px" :disabled="!props.editObj.saveBtnShow"></el-input>
            </el-form-item>
            <el-form-item label="投入经费" prop="outlay" v-if="props.editObj.type == 'ss' || data.fromObj.state == '01'">
              <el-input v-model="data.fromObj.outlay" type="number" placeholder="投入经费" style="width:250px"
                :disabled="!props.editObj.saveBtnShow">
                <template #append>元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="第二次演练日期" prop="playdate2"
              v-if="data.fromObj.frequency == '2' && props.editObj.type == 'add'">
              <el-date-picker v-model="data.fromObj.playdate2" type="date" placeholder="请选择第二次演练日期" style="width:250px"
                :disabled="!props.editObj.saveBtnShow" value-format="YYYY-MM-DD" :disabled-date="disabledecyl" />
            </el-form-item>
            <el-form-item label="参演部门" prop="cydepnames" style="width:100%">
              <el-input type="text" readonly autosize v-model="data.fromObj.cydepnames" placeholder="请输入参演部门"
                :disabled="!props.editObj.saveBtnShow" style="width:100%">
                <template #append>
                  <el-button class='cursor' @click="chooseUserOrDept('03')"
                    :disabled="!props.editObj.saveBtnShow">选择</el-button>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="演练计划" style="width:100%">
              <MOSTY.Upload :isAutoWidth="true" :limit="1" :nopicer="true" :isImg="false" :ShowfileList="true"
                :disabled="!data.config.saveBtnShow" v-model="data.fromObj.file0" :showinput="true" :delrow="delrow"
                :placeholder="'请上传演练计划附件（pdf,ofd,doc,docx,xls,xlsx,wps）'"
                :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']">
              </MOSTY.Upload>
            </el-form-item>
            <el-form-item label="演练地点" prop="address" v-if="props.editObj.type == 'ss' || data.fromObj.state == '01'"
              style="width:100%">
              <el-input v-model="data.fromObj.address" type="textarea" autosize placeholder="请输入演练地点" maxlength="500"
                :disabled="!props.editObj.saveBtnShow"></el-input>
            </el-form-item>
            <el-form-item label="演练主要内容" prop="content" style="width:100%">
              <el-input type="textarea" v-model="data.fromObj.content" :autosize="{ minRows: 2, maxRows: 5 }"
                placeholder="请输入演练主要内容" show-word-limit maxlength="500"
                :disabled="!props.editObj.saveBtnShow"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="bz" style="width:100%">
              <el-input v-model="data.fromObj.bz" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" show-word-limit
                maxlength="500" :disabled="!props.editObj.saveBtnShow" />
            </el-form-item>
            <div v-if="props.editObj.type == 'show' && data.fromObj.state == '01'" style="width:100%">
              <MOSTY.Assort :title="'签到二维码'" />
              <MOSTY.ErwmImg :url="qrcodepxImg(data.fromObj.id, 'paln_yl', '')" :filename='data.fromObj.planname'
                :id='"htmlsmewm1"' />
            </div>
            <div v-if="props.editObj.type == 'ss' || data.fromObj.state == '01'" style="width:100%">
              <MOSTY.Assort :title="'制定演练方案'" />
              <div class='flex' style='flex-wrap:wrap;'>
                <el-form-item label="部门负责人" prop="yldeptusername">
                  <el-input v-model="data.fromObj.yldeptusername" placeholder="请选择部门负责人" readonly style="width:250px"
                    :disabled="!props.editObj.saveBtnShow">
                    <template #append>
                      <el-button class='cursor' @click="chooseUserOrDept('04')"
                        :disabled="!props.editObj.saveBtnShow">选择</el-button></template>
                  </el-input>
                </el-form-item>
                <el-form-item label="业务分管领导" prop="ylfgldname">
                  <el-input v-model="data.fromObj.ylfgldname" readonly placeholder="请输入业务分管领导" style="width:250px"
                    :disabled="!props.editObj.saveBtnShow">
                    <template #append>
                      <el-button class='cursor' @click="chooseUserOrDept('05')"
                        :disabled="!props.editObj.saveBtnShow">选择</el-button></template>
                  </el-input> </el-form-item>
                <el-form-item label="演练方案" style="width:100%">
                  <MOSTY.Upload :isAutoWidth="true" :limit="1" :nopicer="true" :isImg="false" :ShowfileList="true"
                    :disabled="!data.config.saveBtnShow" v-model="data.fromObj.file1" :showinput="true" :delrow="delrow"
                    :placeholder="'请上传演练方案附件（pdf,ofd,doc,docx,xls,xlsx,wps）'"
                    :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']">
                  </MOSTY.Upload>
                </el-form-item>
              </div>

            </div>

            <div v-if="props.editObj.type == 'ss' || data.fromObj.state == '01'" style="width:100%">
              <MOSTY.Assort :title="'演练准备'" />
              <el-form-item label="演练准备资料" style="width:100%">
                <MOSTY.Upload :widthNumber="1090" :limit="1" :nopicer="true" :isImg="false" :ShowfileList="true"
                  :disabled="!data.config.saveBtnShow" v-model="data.fromObj.file2" :showinput="true" :delrow="delrow"
                  :placeholder="'请上传演练准备资料（pdf,ofd,doc,docx,xls,xlsx,wps）'"
                  :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']">
                </MOSTY.Upload>
              </el-form-item>
            </div>
            <el-divider v-if="props.editObj.type == 'update'">演练评估资料</el-divider>
            <div v-if="props.editObj.type == 'ss' || data.fromObj.state == '01'" style="width:100%">
              <MOSTY.Assort :title="'演练评估'" />
              <div class='flex' style='flex-wrap:wrap;'>
                <el-form-item label="演练评估人" prop="yljpgusername">
                  <el-input v-model="data.fromObj.yljpgusername" placeholder="请选择演练评估人" readonly style="width:250px"
                    :disabled="!props.editObj.pingGSaveBtnShow">
                    <template #append>
                      <el-button class='cursor' @click="chooseUserOrDept('06')"
                        :disabled="!props.editObj.pingGSaveBtnShow">选择</el-button></template>
                  </el-input>
                </el-form-item>
                <el-form-item label="演练评估资料" style="width:100%">
                  <MOSTY.Upload :widthNumber="1090" :limit="1" :nopicer="true" :isImg="false" :ShowfileList="true"
                    :disabled="!props.editObj.pingGSaveBtnShow" v-model="data.fromObj.file3" :showinput="true"
                    :delrow="delrow" :placeholder="'请上传演练评估资料（pdf,ofd,doc,docx,xls,xlsx,wps）'"
                    :gsgfList="['pdf', 'ofd', 'doc', 'docx', 'xls', 'xlsx', 'wps']">
                  </MOSTY.Upload>
                </el-form-item>
              </div>

            </div>
          </el-form>
          <div v-if="['show', 'ss'].includes(props.editObj.type) && data.fromObj.state" style="width:100%">
            <MOSTY.Assort :title="'参演人员'" />
            <div class="flex" style="justify-content: space-between;">
              <div></div>
              <div>
                <el-button type="danger" @click="delCanYanUser">删除人员{{ `（${chooseCanYan?.length || 0}）` }}</el-button>
                <el-button v-if="props.editObj.saveBtnShow" type="primary" @click="addCanYanUser('10')">添加人员</el-button>
                <!-- <el-button type="primary" @click="initMan">重置人员</el-button> -->
              </div>
            </div>
            <MyTable :tableData="peopleData.tableData" :tableColumn="peopleData.tableColumn"
              :tableConfiger="peopleData.tableConfiger" selectable class="mt10" @chooseData="chooseData">
              <!-- 自定义插槽 -->
              <template #status="{ row }">
                {{ showStatus(row.status) }}
              </template>
              <!-- 操作 -->
              <template #controls="{ row }">
                <span class="operesee" @click="signIn(row)"
                  v-if="row.status == '0' && props.editObj.type != 'ss'"><el-icon>
                    <DocumentChecked />
                  </el-icon>签到</span>
                <span span class="operdel" @click="delSignIn(row)"><el-icon>
                    <Delete />
                  </el-icon>删除</span>
              </template>
            </MyTable>
          </div>

        </div>
      </template>
      <template #footer>

        <el-button type="primary" v-if="props.editObj.saveBtnShow || props.editObj.pingGSaveBtnShow"
          v-loading='loadingshow' @click="submit(ruleFormRef)"><el-icon>
            <DocumentChecked />
          </el-icon>保存</el-button>
        <el-button @click="black"><el-icon>
            <DocumentDelete />
          </el-icon>关闭</el-button>
      </template>
    </MOSTY.FromPage>


    <!-- 选择预案 -->
    <el-dialog v-model="yaShow" title="选择预案" width="1000px" :show-close="false">
      <el-table ref="multipleTableRef" stripe v-loading="yaLoading" :data="yaList" style="width: 100%" border
        @row-click="yaRowClick">
        <el-table-column width="55" #default="{ row }">
          <el-radio v-model="radioIndex" :label="row.id"></el-radio>
        </el-table-column>
        <el-table-column label="所属单位" show-overflow-tooltip property="orgname"></el-table-column>
        <el-table-column label="预案名称" show-overflow-tooltip property="planname"></el-table-column>
        <el-table-column label="预案类型" show-overflow-tooltip property="plantype">
          <template #default="{ row }">
            <dict-tag :options="D_TB_YALX" :value="row.plantype" :tag="false" />
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 10px">
        <el-pagination class="pagination" @current-change="handleCurrentChange" :current-page="listQuery.pageCurrent"
          :page-size="listQuery.pageSize" layout="total, prev, pager, next, jumper" :total="yaTotal"></el-pagination>
      </div>
      <template #footer>
        <span class="dialog-footer">

          <el-button type="primary" @click="submitYa">确定</el-button>
          <el-button type="warning" @click="
            yaShow = false;
          radioIndex = null;
          ">取消</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 选择人员 -->
    <ChooseUser v-model="chooseUserValue" :Single="singleShow" :titleValue="chooseUserTitle" :leaderid="chooseUserId"
      @choosedUsers="getUserOrDept" :deptId="data.deptId"></ChooseUser>
    <!-- 选择参演部门 -->
    <ChooseDept v-if="showDept" :formInfo="cybmList" :showDdld="showDept" @closezzjg="closeDept"
      @listdata="getUserOrDept" :Isstrictly='false' />
  </div>
</template>

<script setup>
import { qrcodepxImg } from "@/utils/tools.js";
import {
  reactive,
  ref,
  onMounted,
  watchEffect,
  getCurrentInstance,
  watch,
  nextTick
} from "vue";
import PageTitle from "@/components/PageTitle/PageTitle.vue";
import ChooseUser from "@/components/MyComponents/ChooseUser/Leader.vue";
import * as rule from "@/utils/rules.js";
import * as MOSTY from "@/components/MyComponents/index";
import MyTable from "@/components/aboutTable/MyTable/index.vue";
import { getApi, postApi } from "@/api/tobAcco_api.js";
import { ElMessage, ElMessageBox } from "element-plus";
import { getErrMsg } from "@/utils/tools.js"

const { proxy } = getCurrentInstance();
const { D_TB_YLFS, D_TB_YALX } = proxy.$dict("D_TB_YLFS", "D_TB_YALX");
import ChooseDept from "@/components/MyComponents/ChooseDept/Depart.vue";
import { Html2canvasImg } from "@/utils/html2pdf.js";
const loadingshow = ref(false)
const peopleData = reactive({
  tableData: [],
  tableColumn: [
    {
      label: "人员姓名",
      prop: "signusername",
      showOverflowTooltip: true,
      sortable: false
    },
    // {
    //   label: "签到时间",
    //   prop: "signtime",
    //   showOverflowTooltip: true,
    //   sortable: false
    // },
    {
      label: "签到状态",
      prop: "status",
      showOverflowTooltip: true,
      sortable: false,
      showSolt: true
    }
  ],
  tableConfiger: {
    showIndex: true,
    loading: true,
    height: 500,
    showSelectType: "checkBox",
  }
});
const props = defineProps({
  editObj: {
    type: Object,
    default: () => { }
  }
});
const singleShow = ref(true);
// 预案弹窗
const yaShow = ref(false);
// 预案列表
const yaList = ref([]);
// 预案总数
const yaTotal = ref(0);
// 预案单选下标
const radioIndex = ref(null);
const chooseUserTitle = ref("选择用户");
// 预案查询
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 10
});
const activeName = ref(["1", "2", "3", "4", "5", "6"]);
// 已选择的参训部门列表
const cybmList = ref([]);
const yaLoading = ref(false);
const emit = defineEmits("changePage");
const ruleFormRef = ref();
// 表单数据
const data = reactive({
  fromObj: {}, // state: undefined新增 01已实施 00未实施
  treeConfiger: {
    showCheckbox: false,
    isHavePeople: 0,
    defaultCheckedKeys: []
  },
  pageConfiger: {
    pageTitle: "选择部门",
    pageWith: "50%",
    rightVal: []
  }
});
// 校验
const rules = reactive({
  planname: [{ required: true, message: "请选择预案", trigger: "change" }],
  jhdeptusername: [
    { required: true, message: "请选择部门负责人", trigger: "change" }
  ],
  jhfgldname: [
    { required: true, message: "请选择业务分管领导", trigger: "change" }
  ],
  ...rule.intRule({ validator: true, require: true, message: "预计参演人数格式错误" }, "yjcyrs"),
  ...rule.numbernineRule({ validator: true, require: true, iszs: true, firstNum: 6, lastNum: 2, message: "投入经费最多输入6位整数，2位小数" }, "outlay"),
  ylfs: [{ required: true, message: "请选择演练方式", trigger: "change" }],
  frequency: [{ required: true, message: "请选择实施次数", trigger: "blur" }],
  emergencyDrillEvaluationQty: [{ required: true, message: "请输入演练评估次数", trigger: "blur" }],
  playdate: [{ required: true, message: "请选择实施日期", trigger: "change" }],
  playdate2: [
    { required: true, message: "请选择第二次实施日期", trigger: "change" }
  ],
  address: [{ required: true, message: "请输入演练地点", trigger: "blur" }],
  cydepnames: [
    { required: true, message: "请选择参演部门", trigger: "change" }
  ],
  yldeptusername: [
    { required: true, message: "请选择部门负责人", trigger: "blur" }
  ],
  ylfgldname: [
    { required: true, message: "请选择部门分管领导", trigger: "blur" }
  ]
});
// 负责人弹窗显示
const chooseUserValue = ref(false);
// 标记当前选择的是负责人还是分管领导
const chooseType = ref("");
// 用户选择框的id
const chooseUserId = ref("");
// 参训部门弹窗
const showDept = ref(false);
/** 选中的参演人（列表） */
const chooseCanYan = ref([]);
onMounted(() => {
  // 获取预案信息列表
  getYaPage();
  // 查看详情
  getData();
});

function disabledecyl(time) {
  return time.getTime() + 24 * 60 * 60 * 1000 < new Date(data.fromObj.playdate).getTime()
}
// 删除签到人员
const delSignIn = (row) => {
  ElMessageBox.confirm("确定删除该人员", "删除人员").then(() => {
    // 实施阶段 仅行内删除
    if (props.editObj.type == 'ss') {
      peopleData.tableData = peopleData.tableData.filter((item) => {
        return item.signuserid != row.signuserid;
      });
    } else {

      postApi({}, "/mosty-jcgl/responsePlanYlPerson/deleteResponsePlanYlPersonOne/" + row.id)
        .then((res) => {
          ElMessage.success("删除成功");
          getPeopleList(props.editObj.id);
        })
        .catch((err) => { });

    }

  })
};
// PC签到
const signIn = (row) => {
  ElMessageBox.confirm("确定在PC端对该人员进行签到？", "签到").then(() => {
    getApi({}, "/mosty-jcgl/responsePlanYlPerson/signPersonById?id=" + row.id)
      .then((res) => {
        ElMessage.success("签到成功");
        getPeopleList(props.editObj.id);
      })
      .catch((err) => {

      });
  });
};
const chooseData = (val) => {
  chooseCanYan.value = val;
};
// 格式化签到状态
const showStatus = (status) => {
  return status == "1" ? "已签到" : "未签到";
};
// 关闭部门弹窗
const closeDept = () => {
  showDept.value = false;
};
// 查询详情
const getData = () => {
  if (props.editObj.id) {
    getApi({}, "/mosty-jcgl/yjyl/queryYjylById?id=" + props.editObj.id)
      .then((res) => {
        data.fromObj = res;
        getPeopleList(res.id);
      })
      .catch((err) => {

      });
  }
};
/** 重置人员 */
const initMan = () => {
  const id = data.fromObj.id
  if (id) getPeopleList(id);
};
// 查询参与人员
const getPeopleList = (id) => {
  if (props.editObj.type == 'ss') {
    getCanYanByDept(data.fromObj.cydepids);
  }
  // 只有查看已实施的才来查询人员信息
  if (props.editObj.type == "show" && data.fromObj.state == "01") {
    getApi(
      {},
      "/mosty-jcgl/responsePlanYlPerson/listResponsePlanYlPersonById?planid=" +
      id
    )
      .then((res) => {
        peopleData.tableData = res;
      })
      .catch((err) => {

      });
  }
};
const addCanYanToList = (val) => {
  const arr = val.map((item) => {
    return {
      signuserid: item.id,
      signusername: item.userName,
    };
  });
  // 去重 peopleData.tableData 没有的才添加
  const newArr = arr.filter((item) => {
    return !peopleData.tableData.some((item2) => {
      return item2.signuserid == item.signuserid;
    });
  });
  if (newArr.length < arr.length) {
    ElMessage.warning('重复人员已自动去除');
  }
  peopleData.tableData = [...peopleData.tableData, ...newArr];
};
// 确认负责人
const getUserOrDept = (val) => {
  // 计划部门负责人
  if (chooseType.value == "01") {
    data.fromObj.jhdeptuserid = val[0].id;
    data.fromObj.jhdeptusername = val[0].userName;
  } else if (chooseType.value == "02") {
    // 计划分管领导
    data.fromObj.jhfgldid = val[0].id;
    data.fromObj.jhfgldname = val[0].userName;
  } else if (chooseType.value == "04") {
    // 实施部门负责人
    data.fromObj.yldeptuserid = val[0].id;
    data.fromObj.yldeptusername = val[0].userName;
  } else if (chooseType.value == "05") {
    // 实施分管领导
    data.fromObj.ylfgldid = val[0].id;
    data.fromObj.ylfgldname = val[0].userName;
  } else if (chooseType.value == "06") {
    // 演练评估人
    data.fromObj.yljpguserid = val[0].id;
    data.fromObj.yljpgusername = val[0].userName;
  } else if (chooseType.value == "03") {
    // 计划参与部门
    if (val && val.length > 0) {
      data.fromObj.cydepids = val
        .map((item) => {
          return item.id;
        })
        .join(",");
      data.fromObj.cydepnames = val
        .map((item) => {
          return item.orgName;
        })
        .join(",");
    }
    getCanYanByDept(data.fromObj.cydepids);
    // 添加参演人员
  } else if (chooseType.value == "10") {
    if (val && val.length > 0) addCanYanToList(val);
  }
};
const delCanYanUser = () => {
  if (!chooseCanYan.value?.length) return ElMessage.warning("请选择要删除的人员");
  ElMessageBox.confirm("确定删除选中的人员", "删除人员").then(() => {
    if (props.editObj.type === 'ss') {
      peopleData.tableData = peopleData.tableData.filter((item) => {
        return !chooseCanYan.value.some((item2) => {
          return item2.signuserid == item.signuserid;
        });
      });
    } else {
      const ids = chooseCanYan.value.map((item) => item.id);
      postApi(ids, "/mosty-jcgl/responsePlanYlPerson/delBatch")
        .then(() => {
          ElMessage.success("删除成功");
          getPeopleList(props.editObj.id);
        })
        .catch((err) => { });
    }

  });
};
/**添加参演人员 */
const addCanYanUser = (val = '10') => {
  chooseType.value = val;
  chooseUserId.value = undefined;
  data.deptId = undefined;
  chooseUserTitle.value = "选择参演人员";
  singleShow.value = false;

  chooseUserValue.value = true; // 显示选择人员弹窗
}
// 选择负责人、分管领导、部门
const chooseUserOrDept = (val) => {
  chooseType.value = val;
  // 人员
  if (val == "01" || val == "02" || val == "04" || val == "05" || val == "06") {
    chooseUserValue.value = true;
    data.deptId = undefined;
    singleShow.value = true;
    if (val == "01") {
      chooseUserId.value = data.fromObj.jhdeptuserid;
      chooseUserTitle.value = "选择部门负责人";
    } else if (val == "02") {
      chooseUserId.value = data.fromObj.jhfgldid;
      chooseUserTitle.value = "选择部门分管领导";
    } else if (val == "04") {
      chooseUserId.value = data.fromObj.yldeptusername;
      chooseUserTitle.value = "选择部门部门负责人";
    } else if (val == "05") {
      chooseUserId.value = data.fromObj.ylfgldname;
      chooseUserTitle.value = "选择部门分管领导";
    } else if (val == "06") {
      chooseUserId.value = data.fromObj.yljpgusername;
      chooseUserTitle.value = "选择演练评估人";
    }
  } else if (val == "03") {
    showDept.value = true;
  }
};
// 保存
const submit = async (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      loadingshow.value = true
      if (props.editObj.type === 'update') {
        const params = {
          id: data.fromObj.id, // 主键ID
          yljpguserid: data.fromObj.yljpguserid, // 演练及评估人 ID
          yljpgusername: data.fromObj.yljpgusername, // 演练及评估人
          file3: data.fromObj.file3 ? data.fromObj.file3.toString() : null // 演练评估资料
        }
        postApi(params, "/mosty-jcgl//yjyl/updatePgFile")
          .then(() => {
            ElMessage.success("评估资料修改成功");
            emit("changePage", "Main");
            loadingshow.value = false
          }).catch((err) => {
            loadingshow.value = false
          })
      } else if (props.editObj.type != "ss") {
        data.fromObj.file0 = data.fromObj.file0 ? data.fromObj.file0.toString() : null;
        if (!data.fromObj.id) {
          postApi(data.fromObj, "/mosty-jcgl/yjyl/addYjylOne")
            .then(() => {
              ElMessage.success("新增成功");
              emit("changePage", "Main");
              loadingshow.value = false
            }).catch((err) => {
              loadingshow.value = false
            })

        } else {
          postApi(data.fromObj, "/mosty-jcgl/yjyl/updateYjylOne")
            .then(() => {
              ElMessage.success("修改成功");
              emit("changePage", "Main");
              loadingshow.value = false
            }).catch((err) => {
              loadingshow.value = false
            })

        }
      } else {

        data.fromObj.file0 = data.fromObj.file0 ? data.fromObj.file0.toString() : null;
        data.fromObj.file1 = data.fromObj.file1 ? data.fromObj.file1.toString() : null;
        data.fromObj.file2 = data.fromObj.file2 ? data.fromObj.file2.toString() : null;
        data.fromObj.file3 = data.fromObj.file3 ? data.fromObj.file3.toString() : null;
        const params = {
          ...data.fromObj,
          userList: peopleData.tableData, // 格式：[{signusername:'李四',signuserid:'2345'}]
        }
        postApi(params, "/mosty-jcgl/yjyl/addYjylSsOne")
          .then(() => {
            ElMessage.success("实施成功");
            emit("changePage", "Main");
            loadingshow.value = false
          }).catch((err) => {
            loadingshow.value = false
          })

      }
    } else {
      const errMsg = getErrMsg(fields)
      ElMessage.warning(errMsg || '请检查表单!')
    }
  });
};
/** 根据部门或者并设置参演人员 */
const getCanYanByDept = (val) => {
  if (!val) return;
  getApi({ deptids: val }, "/mosty-base/userDeptFeign/getUserByDeptids")
    .then((res) => {
      console.log('res: ', res);
      // addCanYanToList(res);
      res = Array.isArray(res) ? res : [];
      peopleData.tableData = res.map((item) => {
        return {
          signuserid: item.id,
          signusername: item.userName,
        };
      });
    })
    .catch((err) => {

    });
};
const yaRowClick = (row) => {
  radioIndex.value = row.id;
};
// 确认预案
const submitYa = () => {
  data.fromObj.planid = radioIndex.value;
  yaList.value.forEach((ya) => {
    if (ya.id == radioIndex.value) {
      data.fromObj.planname = ya.planname;
    }
  });
  yaShow.value = false;
};
// 切换页码
const handleCurrentChange = (val) => {
  listQuery.pageCurrent = val;
  getYaPage();
};
// 点击预案弹窗
const clickYaInput = () => {
  if (props.editObj.saveBtnShow && props.editObj.type != "ss") {
    yaShow.value = true;
  }
};
// 获取预案信息列表
const getYaPage = () => {
  yaLoading.value = true;
  getApi(listQuery, "/mosty-jcgl/yabz/queryYabzByOrgcode").then((res) => {
    if (res) {
      yaTotal.value = res.total;
      yaList.value = res.records;
    }
    yaLoading.value = false;
  });
};
// 返回主页
const black = () => {
  if (props.editObj.saveBtnShow) {
    proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
      .then(() => {
        emit("changePage", "Main");
        emit("changeShowPage", true);
      })
      .catch(() => {
        // catch error
      })
  } else {
    emit("changePage", "Main");
    emit("changeShowPage", true);
  }

};
watchEffect(() => {
  if (props.editObj) {
    data.config = props.editObj;
  }
});
</script>

<style lang="scss" scoped>
::v-deep .el-radio__label {
  display: none !important;
}

.Box {
  height: calc(100vh - 15vh);
  overflow-y: scroll;
  box-sizing: border-box;
}

.fromBoxs {
  width: 100%;
  margin: 20px auto;
  box-sizing: border-box;
}

.el-form {
  width: 100%;
  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-radio__label {
  display: none;
}

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