<!-- 应急值守 -->
<template>
  <div class="percentage-content">
    <div class="content">
      <div style="margin-bottom: 16px" class="h-layout space-between h-center">
        <div>
          <div class="h-layout">
            <div
              class="tool-item"
              @click="(dialogVisible = true), (form = {}), (readonly = false)"
            >
              <svg-icon name="add" class="icon" />
              <span>新增</span>
            </div>
            <div class="tool-item" @click="getCompanyList">
              <svg-icon name="refurbish" class="icon" />
              <span>刷新</span>
            </div>
            <!-- <div class="tool-item" @click="exportCompanys">
              <svg-icon name="delete" class="icon" />
              <span>删除</span>
            </div> -->
          </div>
        </div>
        <div style="width: 30%">
          <div>
            <el-input
              v-model="search"
              @keydown.enter.native="getCompanyList"
              placeholder="请输入关键字"
              class="search-input"
            >
              <template #append>
                <span @click="getCompanyList" class="search-bottom">
                  <svg-icon name="search" class="icon_class" />
                  <span>搜索</span>
                </span>
              </template>
            </el-input>
          </div>
        </div>
      </div>
      <el-table
        ref="loading"
        v-loading="tableDataloading"
        :data="tableData"
        header-row-class-name="el-one-header"
        @selection-change="handleSelectionChange"
        border
      >
        <el-table-column
          type="index"
          align="center"
          label="序列"
          width="60"
        ></el-table-column>
        <el-table-column
          prop="name"
          :resizable="true"
          align="center"
          label="场所名称"
        ></el-table-column>
        <el-table-column
          prop="area"
          :resizable="true"
          align="center"
          label="占地面积"
        ></el-table-column>
        <el-table-column
          prop="number"
          :resizable="true"
          align="center"
          label="容纳人数"
        ></el-table-column>
        <el-table-column
          prop="address"
          :resizable="true"
          align="center"
          label="详细地址"
        ></el-table-column>

        <el-table-column
          :resizable="true"
          align="center"
          width="260"
          label="操作"
        >
          <template #default="scope">
            <span
              class="operate"
              @click="
                (dialogVisible = true), (form = scope.row), (readonly = false)
              "
            >
              <svg-icon name="edit" class="icon"></svg-icon>
              <span class="edit">编辑</span>
            </span>
            <span
              class="operate"
              @click="
                (dialogVisible = true), (form = scope.row), (readonly = true)
              "
            >
              <svg-icon name="detail" class="icon"></svg-icon>
              <span class="detail">详情</span>
            </span>
            <span class="operate" @click="deletelist(scope.row.othequipmentid)">
              <svg-icon name="delete" class="icon"></svg-icon>
              <span class="func">删除</span>
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        class="pagination"
        @size-change="getCompanyList"
        @current-change="getCompanyList"
        v-model:current-page.sync="currentPage"
        :page-sizes="[10, 15, 20, 30]"
        v-model:page-size.sync="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
      <!-- 新增 -->
      <AddEdit :visible="dialogVisible" :form="form" @close="onclone" />
    </div>
  </div>
</template>
<script lang='ts' setup>
import { onMounted, reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { getOthequipmentPage, delOthequipment } from "@/api/Othteam";
import AddEdit from "./dialog/add-edit.vue";

import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const user = ref(JSON.parse(userStore.userInfo));
const userId = ref(user.value.userId);

const search = ref([]);
const tableData = ref([
  {
    name: "鲜水镇",
    area: "3000㎡",
    number: "20000",
    address: "xxxxxx地址",
  },
]);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);

const dialogVisible = ref(false);
const form = ref({});
const readonly = ref(false);

const handleSelectionChange = () => {};
//获取列表
const tableDataloading = ref(false);
const getCompanyList = () => {
  tableDataloading.value = true;
  let params = {
    equname: search.value,
    equtype: null,
    houseId: null,
    limit: pageSize.value,
    page: currentPage.value,
  };
  getOthequipmentPage(params).then((res: any) => {
    tableData.value = res.data.list;
    total.value = res.data.total;
    tableDataloading.value = false;
  });
};
//删除列表
const deletelist = (id) => {
  ElMessageBox.confirm("是否确认删除?", "提示", {
    confirmButtonText: "是",
    cancelButtonText: "否",
    type: "warning",
  }).then(() => {
    delOthequipment(id, userId.value).then((res: any) => {
      if (res.code == 1) {
        ElMessage.success({
          message: "删除成功",
          type: "success",
        });
      } else {
        ElMessage.error({
          message: res.message,
          type: "error",
        });
      }
      getCompanyList();
    });
  });
};
//关闭新增弹窗
const onclone = () => {
  dialogVisible.value = false;
  form.value = {};
};
onMounted(() => {});
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  background: #fff;
  border-radius: 0.26042vw;
  box-shadow: 0 0 0.41667vw 0 rgba(8, 33, 85, 0.1);
  height: 100%;
  padding: 0.83333vw;
  overflow-y: auto;
  overflow-x: hidden !important;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -o-box-sizing: border-box;
  -ms-box-sizing: border-box;
  box-sizing: border-box;
}
</style>