import type { TableData } from 'lib/type/TableData'

const data: TableData = {
  async fetchFun(self, data) {
    const res = await self.api?.getDataList(data)
    return res
  },
  addNods: [

  ],
  launchTask: [
  ],
  fliter: [
    {
      key: 'id',
      name: 'ID',
      type: 'input'
    },
    {
      key: 'name',
      name: '名称',
      type: 'input'
    },
    {
      key: 'type',
      name: '类型',
      type: 'select',
      items: [
        { key: 'page',name: '页面' },
        { key: 'api',name: 'API' },
      ],
      value: 'page'
    },
    {
      key: 'path',
      name: '路径',
      type: 'input',
    },
    {
      type: 'dialogForm',
      key: 'create',
      form: {
        title: '新建',
        data: [
          {
            key: 'name',
            name: '名称',
            type: 'input',
            must: true
          },
          {
            key: 'type',
            name: '类型',
            type: 'select',
            items: [
              { key: 'page',name: '页面' },
              { key: 'api',name: 'API' },
            ],
            must: true,
            value: 'page'
          },
          {
            key: 'path',
            name: '路径',
            type: 'input',
            must: true
          },
          {
            key: 'method',
            name: '方法',
            type: 'input',
          },
        ],
        subFun(self, data) {
          return self.api?.addData(data)
        }
      }
    }
  ],
  tableColumns: [
    {
      key: 'id',
      name: 'ID',
      width: '80px',
      showJson: '*'
    },
    {
      key: 'name',
      name: '名称',
      width: '200px'
    },
    {
      key: 'type',
      name: '类型',
    },
    {
      key: 'path',
      name: '路径',
    },
    {
      key: 'method',
      name: '方法',
    },
    {
      key: 'create_time',
      name: '创建时间',
    },
    {
      key: 'table_tools',
      name: '操作',
      buttons: [
        {
          type: 'dialogForm',
          key: 'update',
          form: {
            title: '编辑',
            type: 'warning',
            primary: 'id',
            data: [
              {
                key: 'name',
                name: '名称',
                type: 'input',
                must: true
              },
              {
                key: 'type',
                name: '类型',
                type: 'select',
                must: true,
                items: [
                  { key: 'page',name: '页面' },
                  { key: 'api',name: 'API' },
                ],
                value: 'page'
              },
              {
                key: 'path',
                name: '路径',
                type: 'input',
                must: true
              },
              {
                key: 'method',
                name: '方法',
                type: 'input',
              },
            ],
            subFun(self, data) {
              return self.api?.updateData({...data, id: String(data.id)})
            }
          }
        },
        {
          type: 'popoverConfirm',
          key: 'delete',
          confirm: {
            title: '删除',
            primary: 'id',
            subFun(self, data) {
              return self.api?.deleteData(data)
            }
          }
        }
      ]
    }
  ]
}

export default data
