<template>
  <div class="table">
    <!-- 高级搜索 -->
    <TableSearch @searchTable="searchTable" @heightContent="heightContent" />
    <div class="columns-action">
      <!-- 表格大小设置 -->
      <TableSize class="action-size" @changeTableSize="changeTableSize" :that="this" />

      <!-- 表格列设置 -->
      <ActionColumns
        class="action-column"
        @columns="getcolumns"
        :columns-keys="columnsKeys"
        @getTableFixed="getTableFixed"
        @resetTableFixed="resetTableFixed"
        :columns-fixed="columnsFixed"
        :that="this"
      />
    </div>
    <a-spin :spinning="loading">
      <a-table
        :columns="columns"
        :data-source="data"
        :pagination="{
          total: total,
          current: searchParams.Page,
          pageSize: pageCount,
          showTotal: (total) => {
            return `共 ${total} 条`;
          },
        }"
        row-key="id"
        :size="tableSize"
        :loading="loading"
        @change="changepage"
        :scroll="{
          x: 1820,
          y: fullHeight - (heightSearch == true ? '440' : '370'),
        }"
        class="tac-box"
      >
        <p
          class="log-area"
          style="text-align: left"
          slot="expandedRowRender"
          slot-scope="record"
        >
          {{ record.content ? record.content : "No Content" }}
        </p>
        <span slot="deviceType" slot-scope="deviceType">
          {{ deviceType == 1 ? "PC" : "MOBILE" }}
        </span>
        <span slot="isSuccess" slot-scope="isSuccess">
          {{ isSuccess == 1 ? "成功" : "失败" }}
        </span>
      </a-table>
    </a-spin>
    <p class="pageCount">
      <span>数据条数：</span>
      <a-select v-model="pageCount" @change="changePageCount">
        <a-select-option :value="10">10条</a-select-option>
        <a-select-option :value="20">20条</a-select-option>
        <a-select-option :value="30">30条 </a-select-option>
        <a-select-option :value="50">50条</a-select-option>
      </a-select>
    </p>
  </div>
</template>
<script>
import "@/common/components/Commonality/Table/less/table.less";
// import "@/homeComponents/components/MyTable/table/table.less";

import { getOperatingList } from "@/baseConfigComponents/api/operating.js";
import { getSiteOfRouter } from "@/baseConfigComponents/components/Menu/List/js/utils.js";
import ActionColumns from "@/common/components/Commonality/Table/components/TableSet.vue";
import PopForm from "@/baseConfigComponents/components/Role/Modify/RoleForm.vue";
import TableSearch from "@/baseConfigComponents/components/operating/List/Search.vue";
import TableSize from "@/common/components/Commonality/Table/components/TableSize.vue";
import {
  resetFullHeight,
  changeTableSize,
  getcolumns,
  getTableFixed,
  resetTableFixed,
  closePopForm,
  columnsFixed,
  columnsKeys,
} from "@/common/components/Commonality/Table/js/table.js";
import { columns } from "@/baseConfigComponents/components/operating/List/column.js";

export default {
  data() {
    return {
      columns,
      columns2: [],
      data: [], // 数据
      loading: false,
      tableSize: "default", // 表格默认大小
      total: 0, // 总条数
      searchParams: {
        order: 2, // 排序
        Page: 1, // 页码
      }, // 高级搜索参数
      fullHeight: "", // 页面高度
      site: {},
      heightSearch: false,
      pageCount: 10,
    };
  },

  created() {
    this.site = getSiteOfRouter(window.location.hash);
    // 初始化表格窗口高度
    resetFullHeight(this);
    this.columns2 = JSON.parse(JSON.stringify(this.columns));
    // //获取广告列表
    this.getList(this.searchParams);
  },
  methods: {
    // 改变表格size  子传父
    changeTableSize,
    // 列设置 展示指定 的参数
    getcolumns,
    // 改变列固定方向
    getTableFixed,
    // 重置 列 固定方向
    resetTableFixed,
    refresh() {
      this.getList(this.searchParams);
    },
    // 获取 广告列表
    getList(searchParams) {
      this.loading = true;
      getOperatingList(
        this.site.siteCode,
        this.site.siteId,
        searchParams,
        this.pageCount
      ).then((res) => {
        this.loading = false;
        this.total = res.data.totalCount;
        this.data = res.data.data;
      });
    },
    // 翻页
    changepage(index, filters, sorter) {
      switch (sorter.order) {
        case "ascend":
          this.searchParams.order = 1;
          break;
        default:
          this.searchParams.order = 2;
          break;
      }
      this.searchParams.Page = index.current;
      this.getList(this.searchParams);
    },
    // 查询
    searchTable(searchParams) {
      this.searchParams = { order: 2, Page: 1, ...searchParams };
      this.getList(this.searchParams);
    },
    heightContent() {
      this.heightSearch = !this.heightSearch;
      console.log(this.heightSearch);
    },
    changePageCount(val) {
      // console.log(val);
      this.getList(this.searchParams, this);
    },
  },

  computed: {
    // 提取 标题 传递给子组件
    columnsKeys,
    // 提取 fixed 传递给子组件
    columnsFixed,

    that() {
      return this;
    },
  },
  components: {
    ActionColumns,
    TableSearch,
    TableSize,
  },
  watch: {
    fullHeight(val) {
      // ///console.log(val);
      this.fullHeight = val;
    },
  },
};
</script>
<style lang="less">
.tac-box {
  th,
  td {
    text-align: center !important;
  }
}
</style>
