<template>
  <div class="content-box">
    <div class="left">
      <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
      <span class="cameratxt">床位信息管理</span>
    </div>
    <div class="scroll">
      <div class="middle">
        <div class="filter">
          <div class="condition">
            <span>校区名称 :</span>
            <el-select
              clearable
              @change="schoolChange"
              v-model="searchInput.schoolId"
              placeholder="请选择校区名称"
            >
              <el-option
                v-for="i in schoolData"
                :key="i.id"
                :label="i.school"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>楼栋名称 :</span>
            <el-select
              clearable
              v-model="searchInput.buildId"
              placeholder="请选择楼栋名称"
              @change="buildChange"
            >
              <el-option
                v-for="i in buildData"
                :key="i.id"
                :label="i.build"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>寝室号 :</span>
            <el-select
              v-model="searchInput.dormitoryId"
              placeholder="请选择寝室号"
              clearable
            >
              <el-option
                v-for="i in dormitoryData"
                :key="i.id"
                :label="i.dormitory"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>床位性别 :</span>
            <el-select
              clearable
              v-model="searchInput.sex"
              placeholder="请选择床位性别"
            >
              <el-option label="男" value="男" />
              <el-option label="女" value="女" />
            </el-select>
          </div>

          <div class="condition">
            <span>所属学院 :</span>
            <el-select
              @change="collegeChange"
              v-model="searchInput.collegeId"
              placeholder="请选择所属学院"
              clearable
            >
              <el-option
                v-for="i in collegeData"
                :key="i.id"
                :label="i.name"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>专业 :</span>
            <el-select
              @change="majorChange"
              clearable
              v-model="searchInput.majorId"
              placeholder="请选择专业"
            >
              <el-option
                v-for="i in majorData"
                :key="i.id"
                :label="i.name"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>所属班级 :</span>
            <el-select
              clearable
              v-model="searchInput.classstrId"
              placeholder="请选择所属班级"
            >
              <el-option
                v-for="i in classstrData"
                :key="i.id"
                :label="i.name"
                :value="i.id"
              />
            </el-select>
          </div>
          <div class="condition">
            <span>是否入住 :</span>
            <el-select
              v-model="searchInput.isCheck"
              placeholder="请选择入住情况"
            >
              <el-option label="是" value="1" />
              <el-option label="否" value="0" />
            </el-select>
          </div>
          <div class="condition">
            <span>是否保留 :</span>
            <el-select
              clearable
              v-model="searchInput.retentionState"
              placeholder="请选择是否保留"
            >
              <el-option label="是" value="2" />
              <el-option label="否" value="1" />
            </el-select>
          </div>
          <el-button
            style="margin-left: 20px"
            color="rgba(38, 151, 255, 1)"
            type="primary"
            class="search"
            @click="searchBtn"
            ><span>查询</span></el-button
          >
          <el-button @click="resetBtn" plain color="rgba(43, 153, 255, 1)"
            >重置</el-button
          >
        </div>
        <!-- 按钮列表 -->
        <div class="gongneng">
          <el-button
            v-if="store.BtnRole('bedManagementSetting1')"
            type="primary"
            color="rgba(38, 151, 255, 1)"
            @click="buildImportBtn"
            >导入</el-button
          >
          <el-button
            v-if="store.BtnRole('bedManagementSetting2')"
            type="primary"
            style="margin-left: 0"
            color="rgba(48, 201, 191, 1)"
            @click="buildExportbtn"
            >导出</el-button
          >
          <el-button
            v-if="store.BtnRole('bedManagementSetting3')"
            type="primary"
            style="margin-left: 0"
            color="rgba(38, 151, 255, 1)"
            @click="addlist"
            >新增</el-button
          >
          <el-button
            v-if="store.BtnRole('bedManagementSetting4')"
            type="primary"
            style="margin-left: 0"
            color="rgba(38, 151, 255, 1)"
            @click="batchRetainS('批量保留', 2)"
            >批量保留</el-button
          >
          <el-button
            v-if="store.BtnRole('bedManagementSetting5')"
            type="primary"
            style="margin-left: 0"
            color="rgba(38, 151, 255, 1)"
            @click="batchRetainS('批量开放', 1)"
            >批量开放</el-button
          >
        </div>
      </div>
      <div class="footer" v-loading="loading">
        <el-table
          :row-class-name="tableRowClassName"
          :data="tableData.list"
          @selection-change="handleSelectionChange"
          style="width: 100%"
          :header-cell-style="{
            background: 'rgba(240, 243, 247, 1)',
            height: '50px',
            border: 0,
          }"
        >
          <el-table-column
            fixed="left"
            type="selection"
            align="center"
            width="55"
          />
          <el-table-column
            align="center"
            prop="school"
            width="120"
            label="校区名称"
          />
          <el-table-column
            align="center"
            prop="build"
            width="140"
            label="楼栋名称"
          />
          <el-table-column
            align="center"
            prop="dormitory"
            width="120"
            label="寝室号"
          />
          <el-table-column align="center" prop="number" label="床位号" />
          <el-table-column
            align="center"
            prop="sex"
            width="100"
            label="床位性别"
          />
          <el-table-column
            align="center"
            prop="college"
            width="160"
            label="所属学院"
          />
          <el-table-column align="center" prop="major" width="220" label="专业">
          </el-table-column>
          <el-table-column
            align="center"
            prop="classstr"
            width="220"
            label="所属班级"
          />

          <el-table-column
            align="center"
            prop="instructor"
            width="120"
            label="辅导员"
          />
          <el-table-column
            align="center"
            prop="isCheck"
            width="100"
            label="是否入住"
          >
            <template #default="{ row }">
              <span>{{ row.isCheck == 0 ? "否" : "是" }}</span>
            </template>
          </el-table-column>

          <el-table-column align="center" prop="name" label="姓名" />
          <el-table-column
            align="center"
            prop="cardNum"
            width="180"
            label="录取号"
          />
          <el-table-column
            align="center"
            prop="retentionState"
            width="100"
            label="是否保留"
          >
            <template #default="{ row }">
              <span v-if="row.retentionState == 2">是</span>
              <span v-if="row.retentionState == 1">否</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            prop="remark"
            width="200"
            label="备注"
          />
          <el-table-column
            align="center"
            label="操作"
            fixed="right"
            width="300"
          >
            <template #default="{ row }">
              <div class="options">
                <span
                  class="open"
                  v-if="
                    row.retentionState == 1 &&
                    store.BtnRole('bedManagementSetting6')
                  "
                  @click="retainS(row, 2)"
                  >保留</span
                >
                <span
                  class="open"
                  v-if="
                    row.retentionState == 2 &&
                    store.BtnRole('bedManagementSetting7')
                  "
                  @click="retainS(row, 1)"
                  >开放</span
                >
                <span
                  v-if="
                    row.isCheck == 0 &&
                    row.retentionState == 1 &&
                    store.BtnRole('bedManagementSetting8')
                  "
                  class="open"
                  @click="checkClick(row)"
                  >入住</span
                >
                <span
                  v-if="
                    row.isCheck == 1 &&
                    row.retentionState == 1 &&
                    store.BtnRole('bedManagementSetting9')
                  "
                  class="open"
                  @click="outDormitory(row)"
                  >退宿</span
                >
                <!-- <span
                  v-if="
                    row.isCheck == 1 &&
                    row.retentionState == 1 &&
                    store.BtnRole('bedManagementSetting10')
                  "
                  class="open"
                  @click="changeBedClick(row, '换床')"
                  >换床</span
                >
                <span
                  v-if="
                    row.isCheck == 1 &&
                    row.retentionState == 1 &&
                    store.BtnRole('bedManagementSetting11')
                  "
                  class="open"
                  @click="changeBedClick(row, '床位对调')"
                  >床位对调</span
                > -->
                <span
                  class="edit"
                  v-if="store.BtnRole('bedManagementSetting14')"
                  @click="updateS(row)"
                  >编辑</span
                >
                <span
                  class="delete"
                  v-if="store.BtnRole('bedManagementSetting12')"
                  @click="deleteS(row)"
                  >删除</span
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <div class="pageSize">
          <span></span>
          <el-pagination
            background
            :current-page="currentPage"
            :page-size="pageSize"
            :page-sizes="[10, 20, 30, 40]"
            layout="total,sizes, prev, pager, next, jumper, slot"
            :total="total"
            @size-change="handleSizeChange"
            @update:current-page="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 添加账号弹窗 -->
    <el-dialog
      class="addStaff"
      v-model="addDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="dialongTitle"
      align-center
      width="560"
      :before-close="cancelAdd"
      destroy-on-close
      draggable
    >
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="right"
        status-icon
      >
        <el-form-item label="校区名称 :" prop="school">
          <el-select
            :disabled="dialongTitle == '编辑床位信息'"
            @change="schoolFormChange"
            v-model="ruleForm.school"
            placeholder="请选择校区名称"
            clearable
          >
            <el-option
              v-for="i in schoolData"
              :key="i.id"
              :label="i.school"
              :value="`${i.school},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="楼栋名称 :" prop="build">
          <el-select
            clearable
            :disabled="dialongTitle == '编辑床位信息'"
            @change="buildFormChange"
            v-model="ruleForm.build"
            placeholder="请选择楼栋名称"
          >
            <el-option
              v-for="i in buildFormData"
              :key="i.id"
              :label="i.build"
              :value="`${i.build},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="寝室号 :" prop="dormitory">
          <el-select
            clearable
            v-model="ruleForm.dormitory"
            @change="dormitoryFormChange"
            placeholder="请选择寝室号"
          >
            <el-option
              v-for="i in dormitoryFormData"
              :key="i.id"
              :label="i.dormitory"
              :value="`${i.dormitory},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="床位性别 :" prop="sex">
          <el-select
            disabled
            clearable
            v-model="ruleForm.sex"
            placeholder="请选择床位性别"
          >
            <el-option label="男" value="男" />
            <el-option label="女" value="女" />
          </el-select>
        </el-form-item>
        <el-form-item label="床位号 :" prop="number">
          <el-input
            v-model.trim="ruleForm.number"
            placeholder="请输入床位号"
            clearable
          />
        </el-form-item>
        <el-form-item label="所属学院 :" prop="college">
          <el-select
            @change="collegeFormChange"
            v-model="ruleForm.college"
            clearable
            placeholder="请选择所属学院"
          >
            <el-option
              v-for="i in useCollegeData"
              :key="i.id"
              :label="i.name"
              :value="`${i.name},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="专业 :" prop="">
          <el-select
            @change="majorFormChange"
            v-model="ruleForm.major"
            clearable
            :disabled="
              !store.BtnRole('bedManagementSetting15') &&
              dialongTitle == '编辑床位信息'
            "
            placeholder="请选择专业"
          >
            <el-option
              v-for="i in majorFormData"
              :key="i.id"
              :label="i.name"
              :value="`${i.name},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="所属班级 :" prop="">
          <el-select
            clearable
            :disabled="
              !store.BtnRole('bedManagementSetting16') &&
              dialongTitle == '编辑床位信息'
            "
            v-model="ruleForm.classstr"
            placeholder="请选择所属班级"
          >
            <el-option
              v-for="i in classstrFormData"
              :key="i.id"
              :label="i.name"
              :value="`${i.name},${i.id}`"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="dialongTitle == '编辑床位信息' && ruleForm.isCheck == 1"
          label="是否入住 :"
        >
          <el-switch
            disabled
            :active-value="1"
            :inactive-value="0"
            v-model="ruleForm.isCheck"
          />
        </el-form-item>
        <el-form-item
          v-if="dialongTitle == '编辑床位信息' && ruleForm.cardNum"
          label="录取号 :"
        >
          <el-input
            v-model.trim="ruleForm.cardNum"
            placeholder="请输入录取号"
            clearable
            disabled
          />
        </el-form-item>
        <el-form-item
          v-if="dialongTitle == '编辑床位信息' && ruleForm.name"
          label="姓名 :"
        >
          <el-input
            v-model.trim="ruleForm.name"
            placeholder="请输入姓名"
            clearable
            disabled
          />
        </el-form-item>
        <el-form-item label="辅导员 :" prop="">
          <el-input
            v-model.trim="ruleForm.instructor"
            placeholder="请输入辅导员"
            clearable
            :disabled="
              !store.BtnRole('bedManagementSetting17') &&
              dialongTitle == '编辑床位信息'
            "
          />
        </el-form-item>
        <el-form-item label="备注 :">
          <el-input
            v-model.trim="ruleForm.remark"
            placeholder="请输入备注"
            clearable
          />
        </el-form-item>
        <el-form-item class="options">
          <el-button @click="cancelAdd">取消</el-button>
          <el-button
            color="rgba(0, 97, 255, 1)"
            class="queding"
            type="primary"
            @click="submitAdd(ruleFormRef)"
          >
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 入住 -->
    <el-dialog
      class="addStaff"
      v-model="checkDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="入住"
      align-center
      width="560"
      :before-close="cancelCheck"
      destroy-on-close
      draggable
    >
      <el-form
        ref="checkRef"
        :model="ruleFormCheck"
        :rules="rulesCheck"
        label-width="100px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="right"
        status-icon
      >
        <el-form-item label="录取号 :" prop="admissNum">
          <el-input
            clearable
            v-model.trim="ruleFormCheck.admissNum"
            class="w-50 m-2"
            placeholder="请输入录取号"
          />
        </el-form-item>
        <el-form-item label="姓名 :" prop="name">
          <el-input
            clearable
            v-model.number="ruleFormCheck.name"
            class="w-50 m-2"
            placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item class="options">
          <el-button @click="cancelCheck">取消</el-button>
          <el-button
            color="rgba(0, 97, 255, 1)"
            class="queding"
            type="primary"
            @click="submitCheck(checkRef)"
          >
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 换床 -->
    <el-dialog
      class="addStaff"
      v-model="changeBedVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="changeBedTitle"
      align-center
      width="560"
      :before-close="cancelChangeBed"
      destroy-on-close
      draggable
    >
      <el-form
        ref="changeBedRef"
        :model="ruleFormChangeBed"
        :rules="rulesChangeBed"
        label-width="100px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="right"
        status-icon
      >
        <!-- <el-form-item label="校区 " prop="school">
          <el-select
            clearable
            @change="schoolChange"
            v-model="ruleFormChangeBed.school"
            placeholder="请选择校区名称"
          >
            <el-option
              v-for="i in schoolData"
              :key="i.id"
              :label="i.school"
              :value="`${i.school},${i.id}`"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="楼栋 " prop="buildId">
          <el-select
            clearable
            v-model="ruleFormChangeBed.buildId"
            placeholder="请选择楼栋名称"
            @change="buildChangeBed"
          >
            <el-option
              v-for="i in changeBedBuildData"
              :key="i.buildId"
              :label="i.build"
              :value="i.buildId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="寝室号" prop="dormitoryId">
          <el-select
            v-model="ruleFormChangeBed.dormitoryId"
            placeholder="请选择寝室号"
            clearable
            @change="dormitoryChangeBed"
          >
            <el-option
              v-for="i in changeBedDormitoryData"
              :key="i.dormitoryId"
              :label="i.dormitory"
              :value="i.dormitoryId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="床位号" prop="changeBedId">
          <el-select
            v-model="ruleFormChangeBed.changeBedId"
            placeholder="请选择床位号"
            clearable
          >
            <el-option
              v-for="i in changeBedBedData"
              :key="i.bedId"
              :label="i.number"
              :value="i.bedId"
            />
          </el-select>
        </el-form-item>
        <el-form-item class="options">
          <el-button @click="cancelChangeBed">取消</el-button>
          <el-button
            color="rgba(0, 97, 255, 1)"
            class="queding"
            type="primary"
            @click="submitChangeBed(changeBedRef)"
          >
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 项目导入 -->
    <el-dialog
      class="projectImport"
      v-model="buildImportVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="床位信息导入"
      align-center
      width="600"
      :before-close="cancelProjectImport"
    >
      <!-- <p class="title">当前只支持项目类型为“非装配式建筑项目”的项目导入</p> -->
      <p class="down">
        <span>床位信息导入模板下载</span
        ><span @click="templateDown">模板下载</span>
      </p>
      <el-upload
        class="avatar-uploader"
        action="#"
        :auto-upload="false"
        :on-remove="projectImportRemove"
        :on-change="projectImportChange"
        :before-upload="beforeAvatarProImport"
        ref="buildRef"
        :limit="1"
        :on-exceed="projectImportExceed"
      >
        <template #trigger>
          <el-button class="queding" type="primary">
            &nbsp;&nbsp;导入文件&nbsp;&nbsp;
          </el-button>
        </template>
      </el-upload>
      <div class="options">
        <el-button
          color="rgba(9, 101, 98, 1)"
          class="queding"
          type="primary"
          @click="projectImportConfirm(buildRef)"
          :loading="buildImportLoading"
        >
          &nbsp;&nbsp;确认导入&nbsp;&nbsp;
        </el-button>
        <el-button @click="cancelProjectImport"
          >&nbsp;&nbsp;取消导入&nbsp;&nbsp;</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  ref,
  watch,
  reactive,
  nextTick,
  onBeforeMount,
  onUnmounted,
} from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
import { dayjs } from "element-plus";
import lodash from "lodash";
import { https } from "@/utils/request"; // 绝对路径

import { storeToRefs } from "pinia";
import { useCounterStore } from "@/stores/index";

const router = useRouter();
const store = useCounterStore();

// 为避免解构时失去响应性
const { name, age, isCollapse, realAge, collegeRole } = storeToRefs(store);

// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [],
});
const dialongTitle = ref("新增账号"); // 弹窗标题

const searchInput = reactive({
  schoolId: null,
  buildId: null,
  dormitoryId: null,
  sex: null,
  isCheck: null,
  majorId: null,
  collegeId: null,
  classstrId: null,
  retentionState: null, // 1:开放，2:保留
}); // 搜索按钮数据

const currentPage = ref(1); // 当前页
const pageSize = ref(10);
const total = ref(); // 当前总数
const selectIds = ref([]);

const addDialogVisible = ref(false); // 控制添加账号弹窗

// 表单数据
const formSize = ref("default");
const ruleFormRef = ref();
const ruleForm = reactive({
  school: "男", //校区名称
  build: "1", //楼栋名称
  dormitory: "", //宿舍名称
  sex: "", //床位性别
  college: "",
  major: "",
  classstr: "",
  number: "", //床位号
  isCheck: "",
  cardNum: "",
  name: "",
  instructor: "",
  remark: "",
  retentionState: "",
  id: "",
});
// 表单验证
const rules = reactive({
  school: [{ required: true, message: "校区名称不能为空", trigger: "blur" }],
  build: [{ required: true, message: "楼栋名称不能为空", trigger: "blur" }],
  dormitory: [{ required: true, message: "寝室号不能为空", trigger: "blur" }],
  sex: [{ required: true, message: "床位性别不能为空", trigger: "blur" }],
  college: [{ required: true, message: "所属学院不能为空", trigger: "blur" }],
  major: [{ required: true, message: "专业不能为空", trigger: "blur" }],
  classstr: [{ required: true, message: "所属班级不能为空", trigger: "blur" }],
  instructor: [{ required: true, message: "辅导员不能为空", trigger: "blur" }],
  number: [{ required: true, message: "床位号不能为空", trigger: "blur" }],
});

// 入住
const checkRef = ref();
const checkDialogVisible = ref();
const ruleFormCheck = reactive({
  admissNum: "",
  name: "",
  id: "",
});
// 表单验证
const rulesCheck = reactive({
  admissNum: [{ required: true, message: "录取号不能为空", trigger: "blur" }],
  name: [{ required: true, message: "姓名不能为空", trigger: "blur" }],
});
const checkClick = (row) => {
  checkDialogVisible.value = true;
  ruleFormCheck.id = row.id;
};
const submitCheck = lodash.debounce(async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let data = {
        admissNum: ruleFormCheck.admissNum,
        name: ruleFormCheck.name,
        bedId: ruleFormCheck.id,
      };
      console.log(data);
      data.id = ruleForm.id;
      let res = await https.post(
        "/welcome/api/welcomeBed/checkIn",
        "data",
        data
      );
      if (res.code == 200) {
        checkDialogVisible.value = false;
        getList();
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    } else {
      console.log("error submit!", fields);
      loading.value = false;
    }
  });
}, 1000);
const cancelCheck = () => {
  checkDialogVisible.value = false;
};

// 换床
const changeBedRef = ref();
const changeBedTitle = ref();
const changeBedVisible = ref();
const changeBedBuildData = ref();
const changeBedDormitoryData = ref();
const changeBedBedData = ref();
const ruleFormChangeBed = reactive({
  schoolId: "", //校区名称
  collegeId: "",
  sex: "",
  buildId: "", //楼栋名称
  dormitoryId: "",
  changeBedId: "",
  id: "",
});
// 表单验证
const rulesChangeBed = reactive({
  // school: [{ required: true, message: "校区名称不能为空", trigger: "blur" }],
  buildId: [{ required: true, message: "楼栋名称不能为空", trigger: "blur" }],
  dormitoryId: [{ required: true, message: "寝室号不能为空", trigger: "blur" }],
  changeBedId: [{ required: true, message: "床位号不能为空", trigger: "blur" }],
});
const changeBedClick = (row, title) => {
  console.log(row, "换床");
  ruleFormChangeBed.id = row.id;
  changeBedVisible.value = true;
  changeBedTitle.value = title;

  ruleFormChangeBed.buildId = null;
  changeBedBuildData.value = null;

  ruleFormChangeBed.dormitoryId = null;
  changeBedDormitoryData.value = null;

  ruleFormChangeBed.changeBedId = null;

  changeBedBedData.value = null;
  ruleFormChangeBed.schoolId = row.schoolId;
  ruleFormChangeBed.collegeId = row.collegeId;
  ruleFormChangeBed.sex = row.sex;
  changeBedBuildList();
};
// 获取楼栋数据
const changeBedBuildList = async () => {
  let params = {
    schoolId: ruleFormChangeBed.schoolId,
    collegeId: ruleFormChangeBed.collegeId,
    sex: ruleFormChangeBed.sex,
  };
  let res = null;
  if (changeBedTitle.value == "换床") {
    res = await https.get(
      "/welcome/api/welcomeBed/changeBuildGroup",
      "params",
      params
    );
  } else if (changeBedTitle.value == "床位对调") {
    res = await https.get(
      "/welcome/api/welcomeBed/replaceBuildGroup",
      "params",
      params
    );
  }
  console.log(res, "楼栋数据");
  if (res.code == 200) {
    changeBedBuildData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 获取寝室号数据
const changeBedDormitoryList = async () => {
  let params = {
    schoolId: ruleFormChangeBed.schoolId,
    collegeId: ruleFormChangeBed.collegeId,
    sex: ruleFormChangeBed.sex,
    buildId: ruleFormChangeBed.buildId,
  };
  let res = null;
  if (changeBedTitle.value == "换床") {
    res = await https.get(
      "/welcome/api/welcomeBed/changeDormitoryGroup",
      "params",
      params
    );
  } else if (changeBedTitle.value == "床位对调") {
    res = await https.get(
      "/welcome/api/welcomeBed/replaceDormitoryGroup",
      "params",
      params
    );
  }
  console.log(res, "寝室号数据");
  if (res.code == 200) {
    changeBedDormitoryData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 获取床位号数据
const changeBedBedList = async () => {
  let params = {
    schoolId: ruleFormChangeBed.schoolId,
    collegeId: ruleFormChangeBed.collegeId,
    sex: ruleFormChangeBed.sex,
    buildId: ruleFormChangeBed.buildId,
    dormitoryId: ruleFormChangeBed.dormitoryId,
  };
  let res = "";
  if (changeBedTitle.value == "换床") {
    res = await https.get(
      "/welcome/api/welcomeBed/changeBedGroup",
      "params",
      params
    );
  } else if (changeBedTitle.value == "床位对调") {
    res = await https.get(
      "/welcome/api/welcomeBed/replaceBedGroup",
      "params",
      params
    );
  }

  console.log(res, "床位号数据");
  if (res.code == 200) {
    changeBedBedData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};

// 切换楼栋
const buildChangeBed = () => {
  ruleFormChangeBed.dormitoryId = null;
  changeBedDormitoryData.value = null;
  ruleFormChangeBed.changeBedId = null;
  changeBedBedData.value = null;
  changeBedDormitoryList();
};

// 切换寝室号
const dormitoryChangeBed = () => {
  ruleFormChangeBed.changeBedId = null;
  changeBedBedData.value = null;
  changeBedBedList();
};
const submitChangeBed = lodash.debounce(async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let data = {
        sourceBedId: ruleFormChangeBed.id, //源床位id
        changeBedId: ruleFormChangeBed.changeBedId, //交换的床位id
      };
      let res = null;
      if (changeBedTitle.value == "换床") {
        res = await https.post(
          "/welcome/api/welcomeBed/changeBed",
          "data",
          data
        );
      } else if (changeBedTitle.value == "床位对调") {
        res = await https.post(
          "/welcome/api/welcomeBed/replaceBed",
          "data",
          data
        );
      }

      if (res.code == 200) {
        changeBedVisible.value = false;
        getList();
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    } else {
      console.log("error submit!", fields);
      loading.value = false;
    }
  });
}, 1000);

const cancelChangeBed = () => {
  changeBedVisible.value = false;
};

// 导入
const buildImportVisible = ref(false);
const buildRef = ref();
const buildFile = ref();
const buildImportLoading = ref(false);

// 校区数据
const schoolData = ref([]);
// 楼栋数据
const buildData = ref([]);
const buildFormData = ref([]);
// 寝室号数据
const dormitoryData = ref([]);
const dormitoryFormData = ref([]);
// 学院
const collegeData = ref([]);
const useCollegeData = ref([]); // 根据床位号获取学院
// 专业
const majorData = ref([]);
const majorFormData = ref([]);
// 班级
const classstrData = ref([]);
const classstrFormData = ref([]);

const schoolList = async () => {
  let res = await https.get("/welcome/api/welcome-build/schoolGroup", "params");
  console.log(res, "校区数据");
  if (res.code == 200) {
    schoolData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const buildList = async (flag) => {
  let params = {
    schoolId: flag ? flag : searchInput.schoolId,
    accountId: sessionStorage.getItem("accountId"),
  };
  let res = await https.get(
    // "/welcome/api/welcome-build/buildGroup",
    "/welcome/api/welcome-dormitory/saveBedBuildGroup",
    "params",
    params
  );
  console.log(res, "楼栋数据");
  if (res.code == 200) {
    if (flag) {
      buildFormData.value = res.data;
    } else {
      buildData.value = res.data;
    }
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const dormitoryList = async (flag) => {
  let params = null;
  let res = null;
  if (flag) {
    params = flag;
    res = await https.get(
      "/welcome/api/welcome-dormitory/saveBedDormitoryGroup",
      "params",
      params
    );
  } else {
    params = {
      schoolId: searchInput.schoolId,
      buildId: searchInput.buildId,
    };
    res = await https.get(
      "/welcome/api/welcome-dormitory/dormitoryTGroup",
      "params",
      params
    );
  }

  console.log(res, "寝室号数据");
  if (res.code == 200) {
    if (flag) {
      dormitoryFormData.value = res.data;
    } else {
      dormitoryData.value = res.data;
    }
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const collegeList = async () => {
  collegeData.value = collegeRole.value;
  // let res = await https.get("/welcome/api/welcomeOrg/getColleges", "params");
  // console.log(res, "学院数据");
  // if (res.code == 200) {
  //   collegeData.value = res.data;
  // } else {
  //   ElMessage({
  //     type: "error",
  //     showClose: true,
  //     message: res.message,
  //     center: true,
  //   });
  // }
};
const majorList = async (flag) => {
  let params = {
    collegeId: flag ? flag : searchInput.collegeId,
  };
  let res = await https.get(
    "/welcome/api/welcomeOrg/getMajors",
    "params",
    params
  );
  console.log(res, "专业数据");
  if (res.code == 200) {
    if (flag) {
      majorFormData.value = res.data;
    } else {
      majorData.value = res.data;
    }
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const classstrList = async (flag) => {
  let params = {
    majorId: flag ? flag : searchInput.majorId,
  };
  let res = await https.get(
    "/welcome/api/welcomeOrg/getClasss",
    "params",
    params
  );
  console.log(res, "班级数据");
  if (res.code == 200) {
    if (flag) {
      classstrFormData.value = res.data;
    } else {
      classstrData.value = res.data;
    }
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};

const schoolChange = async (val) => {
  console.log(val);
  searchInput.buildId = null;
  searchInput.dormitoryId = null;
  if (!val) {
    buildData.value = null;
    dormitoryData.value = null;
    return;
  } else {
    buildData.value = null;
    dormitoryData.value = null;
  }
  buildList();
};
const schoolFormChange = async (val) => {
  console.log(val);
  ruleForm.build = null;
  ruleForm.dormitory = null;
  ruleForm.college = null;

  ruleForm.sex = null;
  ruleForm.major = null;
  ruleForm.classstr = null;
  majorFormData.value = null;
  classstrFormData.value = null;

  if (!val) {
    buildFormData.value = null;
    dormitoryFormData.value = null;
    return;
  } else {
    buildFormData.value = null;
    dormitoryFormData.value = null;
  }
  buildList(val.split(",")[1]);
};
const buildChange = async (val) => {
  searchInput.dormitoryId = null;
  if (!val) {
    dormitoryData.value = null;
    return;
  } else {
    dormitoryData.value = null;
  }
  dormitoryList();
};
const buildFormChange = async (val) => {
  console.log(val);
  ruleForm.dormitory = null;
  ruleForm.college = null;

  ruleForm.college = null;
  ruleForm.major = null;
  ruleForm.classstr = null;
  ruleForm.sex = null;
  majorFormData.value = null;
  classstrFormData.value = null;

  if (!val) {
    dormitoryFormData.value = null;
    return;
  } else {
    dormitoryFormData.value = null;
  }
  dormitoryList({
    schoolId: ruleForm.school.split(",")[1],
    buildId: val.split(",")[1],
    accountId: sessionStorage.getItem("accountId"),
  });
};
const dormitoryFormChange = (val) => {
  // 选择寝室号 时判断是 所属学院和性别
  if (val) {
    useCollegeList(val.split(",")[1]).then(() => {
      dormitoryFormData.value.forEach((i) => {
        if (i.id == val.split(",")[1]) {
          ruleForm.college = `${i.college.split(',')[0]},${i.collegeId.split(',')[0]}`;
          collegeFormChange(ruleForm.college);
          ruleForm.sex = i.sex;
          ruleForm.retentionState = i.retentionState;
        }
      });
    });
    // dormitoryFormData.value.forEach((i) => {
    //   if (i.id == val.split(",")[1]) {
    //     ruleForm.college = `${i.college},${i.collegeId}`;
    //     collegeFormChange(ruleForm.college);
    //     ruleForm.sex = i.sex;
    //     ruleForm.retentionState = i.retentionState;
    //   }
    // });
  } else {
    ruleForm.college = null;
    ruleForm.sex = null;
    ruleForm.major = null;
    ruleForm.classstr = null;
    majorFormData.value = null;
    classstrFormData.value = null;
  }
};

const collegeChange = async (val) => {
  console.log(val);
  searchInput.majorId = null;
  searchInput.classstrId = null;
  if (!val) {
    majorData.value = null;
    classstrData.value = null;
    return;
  } else {
    majorData.value = null;
    classstrData.value = null;
  }
  majorList();
};
const collegeFormChange = async (val) => {
  console.log(val);
  ruleForm.major = null;
  ruleForm.classstr = null;
  if (!val) {
    majorFormData.value = null;
    classstrFormData.value = null;
    return;
  } else {
    majorFormData.value = null;
    classstrFormData.value = null;
  }
  majorList(val.split(",")[1]);
};
const majorChange = async (val) => {
  console.log(val);
  searchInput.classstrId = null;
  if (!val) {
    classstrData.value = null;
    return;
  } else {
    classstrData.value = null;
  }
  classstrList();
};
const majorFormChange = async (val) => {
  console.log(val);
  ruleForm.classstr = null;
  if (!val) {
    classstrFormData.value = null;
    return;
  } else {
    classstrFormData.value = null;
  }
  classstrList(val.split(",")[1]);
};

// 获取账户列表
const getList = async () => {
  loading.value = true;
  let params = {
    accountId: sessionStorage.getItem("accountId"),
    currentPage: currentPage.value, // 当前页
    pageCount: pageSize.value, // 一页数据条数
    schoolId: searchInput.schoolId,
    buildId: searchInput.buildId,
    dormitoryId: searchInput.dormitoryId,
    sex: searchInput.sex,
    isCheck: searchInput.isCheck,
    collegeId: searchInput.collegeId,
    majorId: searchInput.majorId,
    classstrId: searchInput.classstrId,
    retentionState: searchInput.retentionState,
  };

  let res = await https.get(
    "/welcome/api/welcomeBed/queryPageBeds",
    "params",
    params
  );
  console.log(res, "床位信息");
  if (res.code == 200) {
    tableData.list = res.data.list;
    total.value = res.data.totalCount;
    loading.value = false;
  } else {
    loading.value = false;
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};

// 搜索功能
const searchBtn = lodash.debounce(async () => {
  getList();
}, 300);

const resetBtn = lodash.debounce(async () => {
  searchInput.schoolId = null;
  searchInput.buildId = null;
  buildData.value = [];
  searchInput.dormitoryId = null;
  dormitoryData.value = [];
  searchInput.sex = null;
  searchInput.isCheck = null;
  searchInput.retentionState = null;

  searchInput.collegeId = null;
  searchInput.majorId = null;
  majorData.value = [];
  searchInput.classstrId = null;
  classstrData.value = [];
  getList();
}, 300);

// 添加账号
const addlist = () => {
  dialongTitle.value = "新增床位信息";
  addDialogVisible.value = true;
  ruleForm.number = null;
  ruleForm.school = null;
  ruleForm.build = null;
  buildFormData.value = null;
  ruleForm.dormitory = null;
  dormitoryFormData.value = null;
  ruleForm.sex = null;

  useCollegeData.value = [];
  ruleForm.college = null;
  ruleForm.major = null;
  majorFormData.value = null;
  ruleForm.classstr = null;
  classstrFormData.value = null;
  ruleForm.isCheck = null;
  ruleForm.cardNum = null;
  ruleForm.name = null;
  ruleForm.instructor = null;
  ruleForm.remark = null;
  ruleForm.retentionState = null;
  ruleForm.id = null;
};

const useCollegeList = async (dormitoryId) => {
  let params = {
    dormitoryId: dormitoryId,
  };

  let res = await https.get(
    "/welcome/api/welcome-dormitory/getColleges",
    "params",
    params
  );
  console.log(res, "根据寝室号获取学院");
  if (res.code == 200) {
    useCollegeData.value = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 添加账号
const updateS = (row) => {
  console.log(row);

  dialongTitle.value = "编辑床位信息";
  addDialogVisible.value = true;
  ruleForm.number = row.number;
  if (row.school && row.schoolId) {
    ruleForm.school = `${row.school},${row.schoolId}`;
  } else {
    ruleForm.school = null;
  }
  if (row.build && row.buildId) {
    buildList(row.schoolId).then(() => {
      ruleForm.build = `${row.build},${row.buildId}`;
    });
  } else {
    ruleForm.build = null;
  }
  if (row.dormitory && row.dormitoryId) {
    dormitoryList({
      schoolId: row.schoolId,
      buildId: row.buildId,
      accountId: sessionStorage.getItem("accountId"),
    }).then(() => {
      ruleForm.dormitory = `${row.dormitory},${row.dormitoryId}`;
    });
  } else {
    ruleForm.dormitory = null;
  }
  ruleForm.sex = row.sex;

  if (row.college && row.collegeId) {
    useCollegeList(row.dormitoryId).then(() => {
      ruleForm.college = `${row.college},${row.collegeId}`;
    });
  } else {
    ruleForm.college = null;
  }

  majorList(row.collegeId).then(() => {
    if (row.major && row.majorId) {
      ruleForm.major = `${row.major},${row.majorId}`;
    } else {
      ruleForm.major = null;
    }
  });
  if (row.majorId) {
    classstrList(row.majorId).then(() => {
      if (row.classstr && row.classstrId) {
        ruleForm.classstr = `${row.classstr},${row.classstrId}`;
      } else {
        ruleForm.classstr = null;
      }
    });
  }
  ruleForm.retentionState = row.retentionState;
  ruleForm.isCheck = row.isCheck;
  ruleForm.cardNum = row.cardNum;
  ruleForm.name = row.name;
  ruleForm.instructor = row.instructor;
  ruleForm.remark = row.remark;
  ruleForm.id = row.id;
};
// 退宿
const outDormitory = async (row) => {
  ElMessageBox.confirm("确认该床位退宿?", "提示!!!", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      let data = {
        bedId: row.id, // 当前页
      };
      let res = await https.get(
        "/welcome/api/welcomeBed/checkOutDormitory",
        "params",
        data
      );
      if (res.code == 200) {
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
        loading.value = false;
        getList();
      } else {
        loading.value = false;
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    })
    .catch(() => {});
};
const deleteS = async (row) => {
  ElMessageBox.confirm("是否删除此数据?", "提示！！！", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      loading.value = true;
      let data = {
        id: row.id, // 当前页
      };
      let res = await https.get(
        "/welcome/api/welcomeBed/deleteBedInfo",
        "params",
        data
      );
      if (res.code == 200) {
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
        loading.value = false;
        getList();
      } else {
        loading.value = false;
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    })
    .catch(() => {
      loading.value = false;
    });
};
// 保留
const retainS = async (row, flag) => {
  let data = {
    bedIds: [row.id], // 当前页
    retentionState: flag, //保留状态 1:开放，0保留
  };
  let res = await https.post(
    "/welcome/api/welcomeBed/batchOperationBed",
    "data",
    data
  );
  if (res.code == 200) {
    ElMessage({
      type: "success",
      showClose: true,
      message: res.message,
      center: true,
    });
    getList();
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 批量保留
const batchRetainS = async (title, flag) => {
  if (selectIds.value.length == 0) {
    ElMessage({
      type: "warning",
      showClose: true,
      message: "至少选择一条数据",
      center: true,
    });
    return;
  }
  ElMessageBox.confirm(`是否${title}数据?`, "提示!!!", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      let data = {
        bedIds: selectIds.value, // 当前页
        retentionState: flag, //保留状态 1:保留，0不保留
      };
      let res = await https.post(
        "/welcome/api/welcomeBed/batchOperationBed",
        "data",
        data
      );
      if (res.code == 200) {
        ElMessage({
          type: "success",
          showClose: true,
          message: res.message,
          center: true,
        });
        getList();
      } else {
        ElMessage({
          type: "error",
          showClose: true,
          message: res.message,
          center: true,
        });
      }
    })
    .catch(() => {
      loading.value = false;
    });
};

// 确认添加员工
const submitAdd = lodash.debounce(async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      let data = {
        school: ruleForm.school.split(",")[0],
        schoolId: ruleForm.school.split(",")[1],
        build: ruleForm.build.split(",")[0],
        buildId: ruleForm.build.split(",")[1],
        dormitory: ruleForm.dormitory.split(",")[0],
        dormitoryId: ruleForm.dormitory.split(",")[1],
        sex: ruleForm.sex,
        // isCheck: ruleForm.isCheck == true ? 1 : 0,
        cardNum: ruleForm.cardNum,
        name: ruleForm.name,
        instructor: ruleForm.instructor,
        remark: ruleForm.remark,
        number: ruleForm.number,
        retentionState: ruleForm.retentionState,
        grade: dayjs().year(),
      };
      if (ruleForm.college) {
        data.college = ruleForm.college.split(",")[0];
        data.collegeId = ruleForm.college.split(",")[1];
      }
      if (ruleForm.major) {
        data.major = ruleForm.major.split(",")[0];
        data.majorId = ruleForm.major.split(",")[1];
      }
      if (ruleForm.classstr) {
        data.classstr = ruleForm.classstr.split(",")[0];
        data.classstrId = ruleForm.classstr.split(",")[1];
      }
      if (ruleForm.id) {
        data.id = ruleForm.id;
        let res = await https.post(
          "/welcome/api/welcomeBed/updateBedInfo",
          "data",
          data
        );
        if (res.code == 200) {
          addDialogVisible.value = false;
          getList();
          ElMessage({
            type: "success",
            showClose: true,
            message: res.message,
            center: true,
          });
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.message,
            center: true,
          });
        }
      } else {
        let res = await https.post(
          "/welcome/api/welcomeBed/insertBedInfo",
          "data",
          data
        );
        if (res.code == 200) {
          addDialogVisible.value = false;
          getList();
          ElMessage({
            type: "success",
            showClose: true,
            message: res.message,
            center: true,
          });
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.message,
            center: true,
          });
        }
      }
    } else {
      console.log("error submit!", fields);
      loading.value = false;
    }
  });
}, 1000);
const cancelAdd = () => {
  addDialogVisible.value = false;
  ruleForm.number = null;
  ruleForm.school = null;
  ruleForm.build = null;
  buildFormData.value = null;
  ruleForm.dormitory = null;
  dormitoryFormData.value = null;
  ruleForm.sex = null;
  ruleForm.college = null;
  ruleForm.major = null;
  majorFormData.value = null;
  ruleForm.classstr = null;
  classstrFormData.value = null;
  ruleForm.isCheck = null;
  ruleForm.cardNum = null;
  ruleForm.name = null;
  ruleForm.instructor = null;
  ruleForm.remark = null;
  ruleForm.id = null;
  // ruleFormRef.value.resetFields();
};
// 多选框功能
const handleSelectionChange = (val) => {
  console.log(val);
  selectIds.value = val.map((i) => i.id);
};

// 表格斑马纹颜色修改
const tableRowClassName = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return "even";
  } else if (rowIndex % 2 !== 0) {
    return "odd";
  }
  return "";
};
// 每页显示条数
const handleSizeChange = (value) => {
  console.log(value, "每页显示条数");
  pageSize.value = value;
  getList();
};
// 分页
const handleCurrentChange = (value) => {
  // console.log(value);
  currentPage.value = value;
  getList();
};

// 楼栋导出
const buildExportbtn = async () => {
  let params = {
    accountId: sessionStorage.getItem("accountId"),
    schoolId: searchInput.schoolId,
    buildId: searchInput.buildId,
    dormitoryId: searchInput.dormitoryId,
    sex: searchInput.sex,
    isCheck: searchInput.isCheck,
    collegeId: searchInput.collegeId,
    majorId: searchInput.majorId,
    classstrId: searchInput.classstrId,
    retentionState: searchInput.retentionState,
  };
  let res = await https.getBlob(
    "/welcome/api/welcomeBed/welcomeBedExport",
    "params",
    params
  );
  console.log(res, "床位信息管理导出");
  let name = `床位信息管理`;
  var content = res;
  var datas = new Blob([content]);
  var downloadUrl = window.URL.createObjectURL(datas);
  var anchor = document.createElement("a");
  anchor.href = downloadUrl;
  anchor.download = name + ".xlsx";
  anchor.click();
  window.URL.revokeObjectURL(datas);
  ElMessage({
    type: "success",
    showClose: true,
    message: "导出成功",
    center: true,
  });
};
// 楼栋导入 (--------------------------------------------------)
const buildImportBtn = () => {
  buildImportVisible.value = true;
};
// 模板下载
const templateDown = async () => {
  let res = await https.get(
    "/welcome/api/welcomeBed/downloadBedExcel",
    "params"
  );
  console.log(res, "模板下载");
  if (res.code == 200) {
    window.location.href = res.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
// 移出照片
const projectImportRemove = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles);
  buildFile.value = "";
};
// 限制上传图片的大小
// const beforeAvatarProImport = (rawFile) => {
//   console.log(rawFile, 33333);
//   if (rawFile.type !== "image/jpeg" && rawFile.type !== "image/png") {
//     ElMessage.error("图片格式必须为JPG/PNG格式!");
//     return false;
//   } else if (rawFile.size / 1024 > 150) {
//     ElMessage.error("图片的大小不能超过150kb!");
//     return false;
//   }
//   return true;
// };
// 添加照片时往fileList列表中添加图片信息
const projectImportChange = async (file, fileLists) => {
  console.log(file, "1111");
  buildFile.value = file.raw;
};
const projectImportExceed = (files) => {
  buildRef.value.clearFiles();
  const file = files[0];
  file.uid = genFileId();
  buildRef.value.handleStart(file);
};
// 导入项目
const projectImportConfirm = async () => {
  buildImportLoading.value = true;
  let data = new FormData();
  data.set("file", buildFile.value);
  let res = await https.post(
    "/welcome/api/welcomeBed/importBedExcel",
    "data",
    data
  );
  console.log(res, "导入项目");
  if (res.code == 200) {
    buildImportVisible.value = false;

    buildImportLoading.value = false;
    getList();
    ElMessage({
      type: "success",
      showClose: true,
      message: res.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.message,
      center: true,
    });
  }
};
const cancelProjectImport = () => {
  buildImportVisible.value = false;
  if (buildRef.value) {
    buildRef.value.clearFiles();
    buildFile.value = null;
  }
};

onBeforeMount(() => {
  getList();
  schoolList();
  collegeList();
});
onUnmounted(() => {
  // document.removeEventListener("keyup", Enters);
});
</script>

<style scoped lang="scss">
.content-box {
  width: calc(100% - 40px);
  height: calc(100% - 105px);
  margin: 20px auto;
  background-color: #fff;
  color: #000;
  display: flex;
  flex-direction: column;

  .svg {
    width: 22px;
    height: 22px;
  }

  .left {
    width: calc(100% - 60px);
    height: 60px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    color: #000;
    font-size: 18px;
    font-weight: 600;
    .camera {
      margin-right: 15px;
      color: #4392f7;
    }
  }
  .scroll {
    width: calc(100% - 60px);
    height: calc(100% - 61px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;

    .middle {
      width: calc(100%);
      color: #000;
      .filter {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        .search {
          margin-left: 0 !important;
          color: #fff;
        }
        .condition {
          display: flex;
          align-items: center;
          margin: 10px 30px 10px 0;
          :deep(.el-input .el-input__inner) {
            font-size: 14px;
          }
          .el-select {
            width: 220px;
          }
          span {
            margin: 0 10px 0 0;
          }
        }
      }
      .gongneng {
        margin: 10px 0;
        .el-button {
          color: #fff;
          margin-right: 15px;
        }
      }
    }
    .footer {
      width: calc(100%);
      flex: 1;
      margin: 0 auto;
      overflow: auto;

      .el-table--fit {
        height: calc(100% - 60px);
        :deep(.el-table__header-wrapper) {
          background-color: #000;
          font-size: 15px;
          color: #000;
          .cell {
            color: #000;
          }
        }
        :deep(.el-table__row) {
          height: 50px;
          font-size: 15px;
          color: #000;
        }
        :deep(.el-table__row td) {
          padding: 0;
          border: 0;
        }

        .el-button--primary {
          margin-left: 5px;
        }
        :deep(.el-table__body .even) {
          background-color: #fff;
        }
        :deep(.el-table__body .odd) {
          background-color: rgba(240, 243, 247, 1);
        }
        :deep(.options) {
          display: flex;
          justify-content: center;
          align-items: center;
          .open {
            color: #2697ff;
            cursor: pointer;
            margin: 0 15px 0 0;
          }
          .edit {
            margin: 0 15px 0 0;
            color: rgba(0, 186, 173, 1);
            cursor: pointer;
          }
          .delete {
            color: rgba(212, 48, 48, 1);
            cursor: pointer;
          }
        }
      }

      .pageSize {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 30px;
        height: 60px;

        span {
          color: #000;
        }

        .el-pagination {
          // width: 1600px;
          :deep(.el-pagination__total) {
            color: #000;
          }

          :deep(.el-pagination__goto) {
            color: #000;
          }

          :deep(.el-pagination__classifier) {
            color: #000;
          }

          :deep(.el-input__wrapper) {
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            box-shadow: none;
          }

          :deep(.el-pager li) {
            margin: 0 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }

          :deep(.el-pager li.is-active) {
            // background-color: rgba(0, 97, 255, 0.8);
            border: 1px solid rgba(0, 97, 255, 1);
            color: rgba(0, 97, 255, 1);
          }

          :deep(.btn-prev) {
            margin-right: 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }

          :deep(.btn-next) {
            margin-left: 5px;
            border: 1px solid rgba(0, 0, 0, 1);
            border-radius: 5px;
            background-color: transparent;
          }
        }
      }
    }
  }

  // 添加员工弹窗样式
  :deep(.addStaff) {
    .el-dialog__body {
      padding: 20px 20px 10px 20px;
      .el-input {
        width: 400px;
        .el-input__suffix-inner {
          color: rgba(61, 81, 232, 1);
        }
      }
      .el-select {
        width: 400px;
      }
      .el-tree {
        width: 400px;
      }
    }
  }
  // 导入
  :deep(.projectImport) {
    .el-dialog__body {
      padding: 20px 30px 0 30px;
      .title {
        color: red;
      }
      .down {
        span:nth-child(1) {
          color: rgba(127, 127, 127, 1);
        }
        span:nth-child(2) {
          margin-left: 25px;
          color: rgba(2, 167, 240, 1);
          cursor: pointer;
        }
      }
      .options {
        margin: 50px 0 30px 0;
        display: flex;
        flex-direction: row-reverse;
        .queding {
          margin-left: 20px;
          background: linear-gradient(
            90deg,
            rgba(38, 151, 255, 1) 0%,
            rgba(102, 181, 255, 1) 100%
          );
          border: none;
        }
        .quxiao {
          border: 1px solid rgba(43, 151, 252, 1);
          color: rgba(43, 151, 252, 1);
        }
      }
    }
  }
}
</style>
