<template>
  <div class="new-app-container layout-vertical">
    <!--    <YMTableSearch :loading="loading" :search-form="searchForm" @onValueChange="onValueChange" @submit="onSubmit" />-->
    <YMTable
      ref="table"
      :table-key="1"
      :index="true"
      :selection="false"
      :table-options="tableOptions"
      :edit-form="editForm"
      :edit-config="editConfig"
      :columns="columns"
      :rows-actions="rowsActions"
      :show-summary="false"
      :apis="apis"
      :custom-style="{ height: 'calc(100vh - 80px)' }"
    />
    <!-- 自定义弹窗 -->
    <Dialog ref="dialog">
      <template slot="content"/>
    </Dialog>
  </div>
</template>
<script>
import Dialog from '@/components/Dialog/index.vue'

export default {
  components: {
    Dialog
  },
  data() {
    return {
      loading: false,
      visibleBasicDrawer: false,
      renderContent: '',
      columns: [
        {
          label: '字段',
          prop: 'field'
        },
        {
          label: '名称',
          prop: 'remark'
        },
        {
          label: '内容',
          prop: 'val'
        }
      ],
      rowsActions: [
        {
          key: 'edit',
          label: '编辑'
        },
        {
          key: 'delete',
          label: '删除',
          vIF: (row) => row.group_id !== 1
        }
      ],
      apis: {
        list: {
          url: 'config',
          dataParam: 'data.data',
          resultParam: 'data',
          init: false
        },
        add: {
          url: 'config/submit'
        },
        edit: {
          url: 'config/submit'
        },
        delete: {
          url: 'config/delete',
          method: 'post'
        }
      },
      tableOptions: {
        add: {
          show: true
        }
      },
      editForm: [{
        body: [
          {
            label: '字段',
            type: 'input',
            prop: 'field',
            rules: [
              {
                required: true,
                message: '请输入字段',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '名称',
            type: 'input',
            prop: 'remark',
            rules: [
              {
                required: true,
                message: '请输入字段',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '内容',
            type: 'textarea',
            prop: 'val',
            rules: [
              {
                required: true,
                message: '请输入内容',
                trigger: 'blur'
              }
            ]
          }
        ]
      }],
      editConfig: {}
    }
  },
  created() {
  },
  mounted() {
    this.onSubmit()
  },
  methods: {
    handleSubmit(formData) {
      console.log('提交数据:', formData)
      // 调用API提交数据
    },
    handleClickDrawer(row) {

    },
    onValueChange(val) {

    },
    onSubmit(params) {
      this.$refs.table.getList(params)
    }
  }
}
</script>
