<script setup lang="ts">
import type { BasicForm, ICRUD } from '@/types/form'
import { getQuestionList, saveQuestion, deleteQuestion } from '@/api/miniprogram'

const CRUD: ICRUD = {
  create(data) {
    return saveQuestion(data)
  },
  update(data) {
    return saveQuestion(data)
  },
  getList(data) {
    return getQuestionList(data)
  },
  delete(data) {
    return deleteQuestion({ ids: data.id })
  },
  deleteBatch(data) {
    return deleteQuestion({ ids: data.ids })
  }
}

const formConfig = reactive<BasicForm>({
  span: 24,
  formItems: [
    {
      label: '标题',
      value: '',
      name: 'title',
      type: 'input',
      rules: [{ required: true, message: '请输入标题', trigger: 'blur' }]
    },
    {
      label: '内容',
      value: '',
      name: 'content',
      type: 'editor',
      rules: [{ required: true, message: '请输入内容', trigger: 'blur' }]
    },
    {
      label: '是否使用',
      value: true,
      name: 'isEnable',
      type: 'switch'
    },
    {
      label: '排序',
      value: '',
      name: 'sort',
      type: 'input-number'
    }
  ]
})
</script>

<template>
  <pro-table :crud="CRUD" :formConfig="formConfig">
    <vxe-column field="title" title="标题"></vxe-column>
  </pro-table>
</template>

<style lang="scss" scoped></style>
