const queryFormBtnList = [
  {
    name: 'search',
    label: '搜索',
    type: 'primary',
    click: `() => {
      queryApi()
    }`,
  },
  {
    name: 'clear',
    label: '清空',
    type: 'warning',
    click: `() => {
      queryForm_Data.value = {}
    }`,
  },
]

const tableRowBtnList = [
  {
    name: 'import',
    $import: true,
    label: '导入',
    type: 'primary',
    click: `async ({ file }: { file: File }) => {
      const res = await API_MAP['import']({ file })
      if(res.code === '1'){
        queryApi()
        ElMessage.success(res.msg)
      }
    }`,
  },
  {
    name: 'export',
    label: '导出',
    type: 'success',
    click: `() => {
      exportApi()
    }`,
  },
  {
    name: 'add',
    label: '新增',
    type: 'primary',
    click: `() => {
      whichDialogSubmit = 'add'
      dialogForm_Data.value = {}
      dialogVisible_addOrEdit.value = true
    }`,
  },
  {
    name: 'delete',
    label: '删除',
    type: 'danger',
    click: `async () => {
      await deleteApi(multipleSelection.value.map((item: TYPE_TABLE_FIELD)=>item[TABLE_KEY]))
      queryApi()
    }`,
  },
]

const tableColBtnList = [
  {
    name: 'edit',
    label: '编辑',
    type: 'primary',
    click: `async (scope:{row:TYPE_TABLE_FIELD}) => {
      whichDialogSubmit = 'edit'
      const res = await detailApi(scope.row[TABLE_KEY])
      dialogForm_Data.value = (res.data.one_info)
      dialogVisible_addOrEdit.value = true
    }`,
  },
  {
    name: 'audit',
    label: '审核',
    type: 'primary',
    click: `(scope:{row:TYPE_TABLE_FIELD}) => {
      whichDialogSubmit = 'edit'
      dialogForm_Data.value = pick(scope.row, [\`\${TABLE_KEY}\`, ...Object.keys(dialogForm_Rules_audit)])
      dialogVisible_audit.value = true
    }`,
  },
  {
    name: 'detail',
    label: '详情',
    type: 'primary',
    click: `(scope:{row:TYPE_TABLE_FIELD}) => {
      router.push({ name:DetailName, params:{ [DetailParam]:scope.row[TABLE_KEY]} })
    }`,
  },
  {
    name: 'delete',
    label: '删除',
    type: 'primary',
    click: `async (scope:{row:TYPE_TABLE_FIELD}) => {
      await deleteApi(scope.row[TABLE_KEY])
      queryApi()
    }`,
  },
]

const dialogFormBtnList = [
  {
    name: 'submit',
    label: '提交',
    type: 'primary',
    click: `async (formRefKey:string,extendData?:Partial<TYPE_TABLE_FIELD>) => {
      const isValid = await (instance?.refs[formRefKey] as FormInstance).validate((valid:boolean) => valid)
      if (isValid) {
        await API_MAP[whichDialogSubmit](<TYPE_TABLE_FIELD>({...dialogForm_Data.value,...extendData}))
        handleDialogFormBtn_cancel()
        queryApi()
      }
    }`,
  },
  {
    name: 'cancel',
    label: '取消',
    type: 'default',
    click: `(formRefKey?:string) => {
      dialogVisible_addOrEdit.value = false
      dialogVisible_audit.value = false
    }`,
  },
]

export default {
  queryFormBtnList,
  tableColBtnList,
  tableRowBtnList,
  dialogFormBtnList,
}
