<template>
  <LjVxeTable
    ref="vxeTableRef"
    row-key="key"
    :columns="admsg_columns"
    :request-api="getData"
    :data-callback="dataCallback"
    :dwname="DwnameEnum.adMsgHome"
    pagination
    table-cls=""
    :table-events="tableEvents"
    :table-props="tableProps"
    :header-cell-class-name="headerCellClassName"
    :tool-button="['refresh', 'setting', 'search']"
    :auto-load-layout="false"
    :layout-attr-define="{ ...TABLE_LAYOUT_ATTR_DEFINE, width: '' }"
  >
    <template #tableHeader>
      <div class="flx-start">
        <el-button :icon="Plus" plain type="success" @click="AddAdviceMsg">撰写</el-button>
        <el-button plain @click="AddAdviceMsg">消息管理</el-button>
      </div>
    </template>
  </LjVxeTable>
</template>

<script setup lang="tsx" name="sys_admsg_crm">
import { ref, computed, inject, nextTick, onMounted, watch } from "vue";
import { useRouter } from "vue-router";
import LjVxeTable from "@/components/LjVxeTable/index.vue";
import { CommonDynamicSelect } from "@/api/modules/common";
import { useI18n } from "vue-i18n";
import { formatToDateTime, formatToDate } from "@/utils/dateUtil";
import { useGlobalStore } from "@/stores/modules/global";
import { DwnameEnum } from "@/enums/dwnameEnum";
import { useLayoutStore } from "@/stores/modules/layout";
import { useHomeData } from "@/hooks/useHomeData";
import { useUserStore } from "@/stores/modules/user";
import { Plus } from "@element-plus/icons-vue";
import { TABLE_LAYOUT_ATTR_DEFINE } from "@/config/index";

const { t } = useI18n();
const router = useRouter();
const globalStore = useGlobalStore();
// 布局暂存数据
const emit = defineEmits(["cellClickSaleTask", "toPinDetail"]);
const { userInfo } = useUserStore();

const { vxeTableRef, admsg_columns } = useHomeData(t);

const rowClsNameFunc = (data: any) => {
  const { row, rowIndex, $rowIndex } = data;
  if (row.ifover == 1) {
    return "vxecol-bg-danger";
  }
  return "";
};
const tableProps = {
  height: "auto",
  minHeight: "300px",
  columnConfig: { isHover: true, resizable: true, minWidth: 200 },
  editConfig: { trigger: "click", mode: "cell" },
  rowClassName: rowClsNameFunc,
  exportConfig: {
    // filename: t("menu.saletask") + formatToDate(new Date(), "YYYY-MM-DD HH:mm:ss")
  }
};

// 修改表头样式
const headerCellClassName = ({ column }: any) => {
  if (column?.editRender) {
    return "vxecol-edit";
  }
  return null;
};

const dataCallback = (data: any) => {
  console.log("data :>> ", data);
  return {
    list: data.datatable,
    tableinfo: data.tableinfo,
    total: data.totalcnt,
    pageNum: data.pageindex,
    pageSize: data.pagesize
  };
};

// 如果你想在请求之前对当前请求参数做一些操作，可以自定义如下函数：params 为当前所有的请求参数（包括分页），最后返回请求列表接口
// 默认不做操作就直接在 ProTable 组件上绑定	:requestApi="getUserList"
const getData = (params: any) => {
  console.log("params :>> ", params);
  let newParams = JSON.parse(JSON.stringify(params));
  newParams.dsname = "L1WEB_GetAdviceMessageMxList";
  newParams.queryParams = { scid: userInfo.scid, deptid: userInfo.deptid };
  newParams.pageNum && (newParams.pageindex = newParams.pageNum);
  newParams.pageSize && (newParams.pagesize = newParams.pageSize);
  return CommonDynamicSelect(newParams, DwnameEnum.adMsgHome);
};

const AddAdviceMsg = () => {
  alert("功能维护中!");
};

// 返回绑定的事件
const tableEvents = {
  // "checkbox-change": handleCheckboxChange,
  // "checkbox-all": handleCheckboxChange,
  // "checkbox-range-change": handleCheckboxChange,
  // "current-change": handleCurrentChanged
  // "cell-dblclick": handleDBlClickTable
  //   "cell-click": handleClickTable
};

// 布局暂存数据
// const layoutStore = useLayoutStore();
// onMounted(async () => {
//   let layout = await layoutStore.getDwLayout(DwnameEnum.saletask + "__layout-detail");
//   console.log("SaleTaskDetailRef layout :>> ", layout);
// });
</script>
