<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 - 170px)' }"
    />
    <!-- 自定义弹窗 -->
    <Dialog ref="dialog">
      <template slot="content" />
    </Dialog>
  </div>
</template>
<script>
import Dialog from '@/components/Dialog/index.vue'
import { validateURL } from '@/utils/rules'

export default {
  components: {
    Dialog
  },
  data() {
    return {
      loading: false,
      visibleBasicDrawer: false,
      renderContent: '',
      searchForm: [
        {
          label: '游戏名称',
          type: 'input',
          prop: 'game_name',
          clearable: false
        }
      ],
      columns: [
        {
          label: 'ID',
          prop: 'id'
        },
        {
          label: '游戏名称',
          prop: 'game_name'
        }
      ],
      rowsActions: [
        // {
        //   key: 'edit',
        //   label: '编辑'
        // },
        {
          key: 'delete',
          label: '删除'
        }
      ],
      apis: {
        list: {
          url: 'game',
          dataParam: 'data.data',
          resultParam: 'data',
          init: false
        },
        add: {
          url: 'game/update'
        },
        edit: {
          url: 'game/update'
        },
        delete: {
          url: 'game/delete',
          params: 'id',
          method: 'post'
        }
      },
      tableOptions: {
        add: {
          show: true,
          initData: () => {
            return {id:0 }
          }
        }
      },
      editForm: [
        {
          body: [
            {
              label: '游戏名称',
              type: 'input',
              prop: 'game_name',
              required: true
            },
            {
              label: '跳转地址',
              type: 'input',
              prop: 'game_url',
              required: [
                {
                  validator: validateURL,
                  trigger: ['blur', 'change']
                }

              ]
            }
          ]
        }
      ],
      editConfig: {
        size: 'small'
        // addTip: '注：备注',
        // editTip: '注：备注'
      }
    }
  },
  created() {
  },
  mounted() {
    this.onSubmit()
  },
  methods: {
    handleSubmit(formData) {
      console.log('提交数据:', formData)
      // 调用API提交数据
    },
    handleClickDrawer(row) {

    },
    onValueChange(val) {

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