<script lang="ts" setup name="benchCol">
import type { TableColumn } from '@/components/NormalTable/table_interface'

// 逻辑代码
const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  icon: {
    type: String,
    default: '',
  },
  pathUrl: {
    type: String,
    default: '',
  },
  width: {
    type: String,
    default: '100%',
  },
  height: {
    type: [String, Number],
    default: '',
  },
  // 是否需要分页控件
  pagination: {
    type: Boolean,
    default: false,
  },
  // 可选单页显示条数
  pageSizes: {
    type: Array,
    default() {
      return [10, 20, 30]
    },
  },
  // 查询条件，此处主要需要分页的条件
  query: {
    type: Object,
    default() {
      return {
        offset: 1,
        limit: 20,
      }
    },
  },
  // 数据总数
  total: {
    type: Number,
    default: 0,
  },
  // 可编辑
  isEdit: {
    type: Boolean,
    default: false,
  },
  // 是否显示删除
  isShowDelete: {
    type: Boolean,
    default: false,
  },
})
const emit = defineEmits(['change', 'editData', 'deleteData'])

// 改变页容量
function handleSizeChange(val: number) {
  emit('change', { size: val })
}
// 改变当前页
function handleCurrentChange(val: number) {
  emit('change', { page: val })
}

// 点击编辑icon
function clickEdit() {
  emit('editData')
}
// 点击删除icon
function clickDelete() {
  emit('deleteData')
}
</script>

<template>
  <div class="bench-left-top" :style="{ height: typeof height == 'string' ? height : `${height}px` }">
    <div v-if="title" class="bench-title">
      <el-icon v-if="icon" :name="icon" class="title-icon">
        <svg-icon :name="icon" />
      </el-icon>
      <div class="title">
        {{ title }}
      </div>
      <span v-if="pathUrl !== ''" class="more" @click="$router.push(pathUrl)">更多 ></span>
      <!-- <el-icon v-if="isEdit" :name="icon" class="title-icon edit-icon" @click="clickEdit">
        <svg-icon name="icon-edit" />
      </el-icon> -->
      <el-icon v-if="isEdit" :size="18" color="#3d7eff" style="cursor: pointer;" @click="clickEdit">
        <edit />
      </el-icon>
      <el-icon v-if="isShowDelete" :size="18" color="#f56c6c" style="margin-left: 4px;cursor: pointer;" @click="clickDelete">
        <delete />
      </el-icon>
    </div>
    <div class="content" :style="{ height: typeof height == 'string' ? height : `${height - 50}px` }">
      <slot />
    </div>
    <div v-if="props.pagination" style="width: 100%;margin-top: 10px;">
      <!-- <el-pagination
        :current-page="props.query.offset"
        :page-sizes="props.pageSizes as number[]"
        :page-size="props.query.limit"
        :total="props.total"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      /> -->
      <el-pagination
        v-model:current-page="props.query.offset"
        small
        :page-size="props.query.limit"
        layout="total, prev, pager, next"
        :total="props.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
// 样式
.bench-left-top {
  border-radius: 10px;
  background-color: #fff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;

  .bench-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    height: 30px;
    overflow: hidden;

    .title-icon {
      width: 14px;
      height: 14px;
      font-size: 14px;
      line-height: 16px;
      color: #3d7eff;
      margin-right: 5px;
    }

    .edit-icon {
      cursor: pointer;
    }

    .delete-icon {
      color: red;
      cursor: pointer;
    }

    .title {
      color: #000;
      font-size: 16px;
      flex: 1;
    }

    .more {
      cursor: pointer;
      font-size: 14px;
      color: #ccc;
    }
  }

  .content {
    flex: 1;
    width: 100%;
    box-sizing: border-box;
  }

  .bench-title + .content {
    padding-top: 10px;
  }
}
</style>

