<template>
  <div>
    <div class="titleBox">
      <PageTitle title="标签组合管理">
        <el-button type="primary">
          <span style="vertical-align: middle">调级</span>
        </el-button>
        <el-button type="primary">
          <span style="vertical-align: middle">导出</span>
        </el-button>
        <el-button type="primary">
          <span style="vertical-align: middle">批量导入</span>
        </el-button>
        <el-button type="primary" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
        <el-button type="danger" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><Dete /></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">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
        @chooseData="chooseData"
      >
        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary"  @click="addEdit('edit', row)">编辑</el-link>
          <el-link type="primary"  @click="addEdit('edit', row)">编辑</el-link>
          <el-link type="danger"  @click="delDictItem([row.id])">删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 编辑详情 -->
    <EditAddForm ref="detailDiloag" @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 detailDiloag = ref();
const searchBox = ref(); //搜索框
const searchConfiger = ref(
  [
  { label: "组合标签名称", prop: 'bqmc', placeholder: "请输入组合标签名称", showType: "input" },
  { label: "身份标签大类", prop: 'bqdl', placeholder: "请选择身份标签大类", showType: "select" },
  { label: "身份标签细类", prop: 'bqxl', placeholder: "请选择身份标签细类", showType: "select" },
  { label: "身份标签颜色", prop: 'bqys', placeholder: "请输入组合标签名称", showType: "input" },
  { label: "行为标签大类", prop: 'xwbqdl', placeholder: "请选择行为标签大类", showType: "select" },
  { label: "行为标签细类", prop: 'xwbqxl', placeholder: "请选择行为标签细类", showType: "select" },
  { label: "行为标签等级", prop: 'xwbqdj', placeholder: "请选择行为标签等级", showType: "select" },
  { label: "行为标签颜色", prop: 'xwbqys', placeholder: "请选择行为标签颜色", showType: "select" },
  { label: "身份标签积分", prop: 'sfbajf', placeholder: "请选择身份标签积分", showType: "select" },
  { label: "行为标签积分", prop: 'xwbqjf', placeholder: "请选择行为标签积分", showType: "select" },
  { label: "组组合标签积分", prop: 'zzhbqjf', placeholder: "请选择组组合标签积分", showType: "select" },
]);
const queryFrom = ref({});
const pageData = reactive({
  tableData: [
    {
      id: 1,
      zhpqmc: "高风险重点人群A",
      zhbqdj: "一级",
      sfdqdl: "涉毒人员",
      sfbaxl: "吸毒人员",
      sfbqdj: "一级",
      sfbqys: "红色",
      xwbqdl: "涉毒行为",
      xwbqxl: "复吸行为",
      xwbqdj: "一级",
      xwbqys: "红色",
      sfbajf: 100,
      xwbqjf: 100,
      zzhbqjf: 200
    },
    {
      id: 2,
      zhpqmc: "中风险关注人群B",
      zhbqdj: "二级",
      sfdqdl: "涉毒人员",
      sfbaxl: "社区康复人员",
      sfbqdj: "二级",
      sfbqys: "橙色",
      xwbqdl: "涉毒行为",
      xwbqxl: "戒毒行为",
      xwbqdj: "二级",
      xwbqys: "橙色",
      sfbajf: 80,
      xwbqjf: 80,
      zzhbqjf: 160
    },
    {
      id: 3,
      zhpqmc: "低风险观察人群C",
      zhbqdj: "三级",
      sfdqdl: "涉毒人员",
      sfbaxl: "戒毒人员",
      sfbqdj: "三级",
      sfbqys: "黄色",
      xwbqdl: "涉毒行为",
      xwbqxl: "社区康复",
      xwbqdj: "三级",
      xwbqys: "黄色",
      sfbajf: 60,
      xwbqjf: 60,
      zzhbqjf: 120
    }
  ], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 160, //操作栏宽度
  tableColumn: [
    { label: "组合标签名称", prop: "zhpqmc" },
    { label: "组合标签等级", prop: "zhbqdj" },
    { label: "身份标签大类", prop: "sfdqdl"},
    { label: "身份标签细类", prop: "sfbaxl"},
    { label: "身份标签等级", prop: "sfbqdj"},
    { label: "身份标签颜色",  prop: "sfbqys" },
    { label: "行为标签大类",  prop: "xwbqdl" },
    { label: "行为标签细类",  prop: "xwbqxl" },
    { label: "行为标签等级",  prop: "xwbqdj" },
    { label: "行为标签颜色",  prop: "xwbqys" },
    { label: "身份标签积分",  prop: "sfbajf" },
    { label: "行为标签积分",  prop: "xwbqjf" },
    { label: "组组合标签积分",  prop: "zzhbqjf" },
  ]
});
onMounted(() => {
  tabHeightFn();
});


// 搜索
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 = () =>{
  // pageData.tableConfiger.loading = true;
  // qcckGet(queryFrom.value).then((res)=>{
  //   pageData.tableData = res.data.list;
  //   pageData.total = res.data.total;
  //   pageData.keyCount++;
  //   pageData.tableConfiger.loading = false;
  // })
}

// 删除
const delDictItem = (ids) =>{
  // proxy.$confirm("确定要删除", "警告", {type: "warning"}).then(() => {
  //   qcckPost(ids,url).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>
