import { h, ref, reactive } from 'vue'
import TableImage from '@/components/DataTable/tools/Image.vue'
import TableTags from '@/components/DataTable/tools/Tags.vue'
import TableAction from '@/components/DataTable/tools/Action.vue'
import TableSwitch from '@/components/DataTable/tools/Switch.vue'
/* 注册table */
const tableRef = ref()
const searchParams = ref()

function handleSearch(params) {
  searchParams.value = { ...params }
  tableRef.value.reFetch({ searchParams })
}
/**
 * @description: 获取数据及操作
 * @param {*} row 单行数据
 * @param {*} type 操作类型 create:创建，preview:预览，edit:编辑
 * @return {*}
 */
function getRowData(row, type) {
  data.rowData = type === 'create' ? { pid: row.id } : row
  data.modalType = type
  data.modalShow = true
}

// 删除方法
function deleteData(id) {
  advertisingDelete(id)
    .then((res) => {
      if (res.code === 0) {
        handleSearch()
      }
    })
    .catch((e) => {
      console.log(e)
    })
}

const data = reactive({
  tableRef,
  searchParams,
  rowData: {},
  modalType: 'create',
  modalShow: false,
  columns: [
    {
      title: '序号',
      key: 'key',
      render: (_, index) => {
        return `${index + 1}`
      },
      align: 'center',
      width: 50
    },
    {
      title: '广告名称',
      key: 'title',
      align: 'center',
      width: 200
    },
    {
      title: '广告名称',
      key: 'title',
      align: 'center',
      width: 200
    },
    {
      title: '广告名称',
      key: 'title',
      align: 'center',
      width: 200
    }
  ]
})

export default data
