<template>
  <div>
    <search-module :search="search" :table="table">
      <template #btn>
        <el-button @click="onAddOrEdit('add', null)" type="success">新增</el-button>
      </template>
    </search-module>
    <div id="table-drag-wrap">
      <table-module :table="table"> </table-module>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useDraggable } from 'vue-draggable-plus'
import { initConfig } from './config'

/** 新增&编辑 */
const onAddOrEdit = (type: string, row: any) => {}

/** 复制 */
const onCopy = (row: any) => {}

// 加入首页
const onAddHome = (row: any) => {}

// 删除
const onDelete = (row: any) => {
  handleMessageBox({
    msg: `是否确认删除吗?`,
    success: api.commodity.delCommodity.post!,
    data: { id: row.id }
  }).then(() => {
    table.value.$onGetData(table.value)
  })
}

/** 初始化页面 */
const ConfigData = initConfig()
const { search, table } = handleInit(ConfigData, api.commodity.getHomeCommodityList.post, [
  onAddOrEdit.bind(null, 'edit'),
  onCopy,
  onAddHome,
  onDelete
])
table.value.$onGetData(table.value, 1, search)
setTimeout(() => {
  useDraggable('#table-drag-wrap .el-table__body tbody', table.value.$data)
}, 2000)

/** 页面缓存 */
defineOptions({ name: 'HomeGoods' })
</script>
