
<template>
  <PageWrapLayout>
    <div style="max-width: 800px">
      <el-form
          ref="ruleFormRef"
          :model="ruleForm"
          :rules="rules"
          label-width="120px"
          class="demo-ruleForm"
          :size="formSize"
      >
        <el-form-item label="礼包码" prop="code">
          <el-input v-model="ruleForm.code" placeholder="3 到 8 个字符"/>
        </el-form-item>
        <el-form-item label="礼包类型" prop="codeType">
          <el-select v-model="ruleForm.codeType" placeholder="礼包类型">
            <el-option label="一次性" value="0" />
            <el-option label="通用" value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="礼包道具ID" prop="itemIds">
          <el-input v-model="ruleForm.itemIds" placeholder="道具ID列表，逗号间隔" />
        </el-form-item>
        <el-form-item label="礼包道具数量" prop="itemCounts">
          <el-input v-model="ruleForm.itemCounts" placeholder="道具数量列表，逗号间隔" />
        </el-form-item>
        <el-form-item label="礼包生效时间" required>
          <el-col :span="11">
            <el-form-item prop="validTime">
              <el-date-picker
                  v-model="ruleForm.validTime"
                  type="datetime"
                  placeholder="选择开始时间"
                  style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col class="text-center" :span="2" style="text-align: center">
            <span class="text-gray-500">-</span>
          </el-col>
          <el-col :span="11">
            <el-form-item prop="invalidTime">
              <el-date-picker v-model="ruleForm.invalidTime"  type="datetime" placeholder="选择结束时间" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm(ruleFormRef)">立即生成</el-button>
          <el-button @click="resetForm(ruleFormRef)">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </PageWrapLayout>
</template>

<script lang="ts" setup >
import { reactive, ref } from 'vue'
import type { FormInstance } from 'element-plus'
// import Upload from './components/Upload.vue'

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive({
  code: '',
  codeType: '',
  validTime: '',
  invalidTime: '',
  giftItems: '',
  itemIds:[],
  itemCounts:[],
})

const rules = reactive({
  code: [
    {
      required: true,
      message: '请输入礼包码',
      trigger: 'change',
    },
    { min: 3, max: 8, message: '长度在 3 到 8 个字符', trigger: 'blur' },
  ],
  codeType: [
    {
      required: true,
      message: '请选择礼包类型',
      trigger: 'change',
    },
  ],
  validTime: [
    {
      type: 'date',
      required: true,
      message: '请选择时间',
      trigger: 'change',
    },
  ],
  invalidTime: [
    {
      type: 'date',
      required: true,
      message: '请选择时间',
      trigger: 'change',
    },
  ],
  itemIds: [
    {
      type: 'array',
      required: true,
      message: '请输入礼包道具ID',
      trigger: 'change',
    },
  ],
  itemCounts: [
    {
      type: 'array',
      required: true,
      message: '请输入礼包道具数量',
      trigger: 'change',
    },
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  console.log('--FORM---', ruleForm)
  if (!formEl) return

}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>
