<template>
  <div>
    <search-module :search="search" :table="table">
      <template #btn>
        <el-button @click="onAddOrEdit('add', null)" type="success">新增</el-button>
      </template>
    </search-module>
    <table-module :table="table">
      <template #headerBtn>
        <el-radio-group v-model="commodityType" @change="onChangeCommodityType">
          <el-radio-button
            v-for="item in commodityTypeOptions"
            :key="item.value"
            :value="item.value"
            >{{ item.label }}</el-radio-button
          >
        </el-radio-group>
      </template>
    </table-module>
  </div>
</template>

<script lang="ts" setup>
import { initConfig } from './config'
import { useCommodityType } from './use-method'

/** 新增&编辑 */
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.getCommodityList.post, [
  onAddOrEdit.bind(null, 'edit'),
  onCopy,
  onAddHome,
  onDelete
])
const { commodityType, onChangeCommodityType, commodityTypeOptions } = useCommodityType(
  search,
  table
)
onChangeCommodityType(commodityType.value)

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