<template>
  <div>
    <div class="titleBox">
      <PageTitle title="身份标签管理">
        <template #left>
          <el-button :type="type == '标签大类'? 'success':''" @click="chooseListType('标签大类')">
            <span style="vertical-align: middle">标签大类</span>
          </el-button>
          <el-button :type="type == '标签细类'? 'success':''" @click="chooseListType('标签细类')">
            <span style="vertical-align: middle">标签细类</span>
          </el-button>
        </template>
        <el-button type="primary" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
      </PageTitle>
    </div>
    <!-- 搜索 -->
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount"></Search>
    </div>
    <!-- 表格 -->
    <div class="tabBox" :style="{height:pageData.tableHeight+20+'px'}">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
        @chooseData="chooseData"
      >
        <template #bqLx="{ row }">
          <DictTag :value="row.bqLx" :options="D_GS_BQ_LX" />
        </template>
        <template #bqLb="{ row }">
          <DictTag :value="row.bqLb" :options=" D_GS_BQ_LB" />
        </template>
        <template #bqYs="{ row }">
          <DictTag :value="row.bqYs" :options=" D_GS_SSYJ" />
        </template>
        <template #bqDj="{ row }">
          <DictTag :value="row.bqDj" :options=" D_GS_BQ_DJ" />
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-button size="small" @click="addEdit('edit', row)">编辑</el-button>
          <el-button size="small" @click="delDictItem(row.id)" type="danger">删除</el-button>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 编辑详情 -->
    <EditAddForm ref="detailDiloag" :dic="{D_GS_BQ_DJ,D_GS_SSYJ,D_GS_BQ_LB,D_GS_BQ_LX}" @updateDate="getList" />
  </div>
</template>

<script setup>
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import Search from "@/components/aboutTable/Search.vue";
import EditAddForm from "./components/editAddForm.vue";
import { qcckGet, qcckPost, qcckDelete } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const { D_GS_BQ_DJ,D_GS_SSYJ,D_GS_BQ_LB,D_GS_BQ_LX } = proxy.$dict("D_GS_BQ_DJ","D_GS_SSYJ","D_GS_BQ_LB","D_GS_BQ_LX"); //获取字典数据
const detailDiloag = ref();
const searchBox = ref(); //搜索框
const type = ref('标签大类')

const searchConfiger = ref([
  { label: "标签大类",prop:'sfbqdl' ,placeholder: "请输入标签大类", showType: "input"},
  { label: "标签名称",prop:'bqmc',placeholder: "请输入学校名称", showType: "input"},
  { label: "标签等级",prop:'sfbqdl' ,placeholder: "请选择标签等级", showType: "select",options:D_GS_BQ_DJ },
  { label: "标签颜色",prop:'sfbqdl' ,placeholder: "请选择标签颜色", showType: "select",options:D_GS_SSYJ },
  { label: "积分分值",prop:'bqmc',placeholder: "请输入积分分值", showType: "input",},
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 160, //操作栏宽度
  tableColumn: [
    { label: "标签名称", prop: "bqMc" },
    { label: "标签代码", prop: "bqDm" },
    { label: "标签类型", prop: "bqLx",howSolt:true },
    { label: "标签类别", prop: "bqLb",howSolt:true },
    { label: "标签等级", prop: "bqDj",showSolt:true},
    { label: "标签颜色", prop: "bqYs",showSolt:true},
  ]
});
onMounted(() => {
  getList()
  tabHeightFn();
});

// 选择列表的大类和细类
const chooseListType = (val) => {
  type.value = val;
  pageData.keyCount++;
  switch(val){
    case '标签大类':
      let obj1 =  { label: "标签大类",prop:'sfbqdl' ,placeholder: "请输入标签大类", showType: "input"}
      searchConfiger.value.splice(0, 1, obj1); 
      break; 
    case '标签细类':
    let obj2 =   { label: "标签细类",prop:'sfbqdl' ,placeholder: "请输入标签细类", showType: "input"}
    searchConfiger.value.splice(0, 1, obj2);
    break; 
  }
  pageData.pageConfiger.pageCurrent = 1;
  getList()
};

// 搜索
const onSearch = (val) =>{
  queryFrom.value = {...val}
  pageData.pageConfiger.pageCurrent = 1;
  getList()
}

// 分页
const changeNo = (val) =>{
  pageData.pageConfiger.pageNum = val;
  getList()
}
// 页数
const changeSize = (val) =>{
  pageData.pageConfiger.pageSize = val;
  getList()
}

// 获取列表
const getList = (val) =>{
  // pageData.tableConfiger.loading = true;
  // let data = { ...pageData.pageConfiger,...queryFrom.value };
  // qcckPost(data,'/mosty-gsxt/tbGsxtBqgl/selectPage').then(res=>{
  //   pageData.tableData = res.records || [];
  //   pageData.total = res.total;
  //   pageData.tableConfiger.loading = false;
  // }).catch(()=>{ pageData.tableConfiger.loading = false; })
}
// 删除
const delDictItem = (id) =>{
  proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
    qcckPost({},'/mosty-gsxt/tbGsxtBqgl/'+id).then(()=>{
      proxy.$message({ type: "success",  message: "删除成功" });
      getList();
    })
  }).catch(() => {});
}

// 新增
const addEdit = (type, row) => {
  detailDiloag.value.init(type, row);
};

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 250;
  window.onresize = function () { tabHeightFn(); };
};
</script>

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
</style>
