<script setup lang="ts">
import type { BasicForm, ICRUD } from '@/types/form'
import { getAdviceList, saveAdvice, deleteAdvice } from '@/api/miniprogram'

const CRUD: ICRUD = {
  create(data: any) {
    return saveAdvice(data)
  },
  update(data: any) {
    return Promise.resolve(data)
  },
  getList(data: any) {
    return getAdviceList(data)
  },
  delete(data: any) {
    return deleteAdvice(data)
  }
}

const formConfig = reactive<BasicForm>({
  span: 24,
  formItems: []
})

const dialogVisible = ref(false)
const replyConfig = reactive<BasicForm>({
  span: 24,
  formItems: [
    {
      label: '回复内容',
      value: '',
      name: 'reply',
      type: 'input',
      rules: [{ required: true, message: '请输入回复内容', trigger: 'blur' }],
      props: {
        type: 'textarea'
      }
    }
  ]
})
const curQuestion = ref<any>(null)
const formData = ref<any>({})

const openDiolog = (row: any) => {
  dialogVisible.value = true
  curQuestion.value = row
}
const handleReply = () => {
  // 回复接口
}
</script>

<template>
  <pro-table
    :formConfig="formConfig"
    :crud="CRUD"
    :selection="false"
    :showToolbar="false"
    :tableConfig="{ showEdit: false }"
  >
    <el-table-column prop="content" label="反馈内容"></el-table-column>
    <el-table-column prop="createDate" label="反馈时间"></el-table-column>
    <template #operateBefore="{ row }">
      <el-button type="primary" size="small" @click="openDiolog(row)">回复</el-button>
    </template>
  </pro-table>

  <dialog-form
    v-model="dialogVisible"
    :formConfig="replyConfig"
    :create="handleReply"
    :update="handleReply"
    :formData="formData"
    v-if="dialogVisible"
  />
</template>

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