2021-09-17 00:18:50 +08:00
|
|
|
<template>
|
|
|
|
<el-form
|
2021-12-15 16:36:49 +08:00
|
|
|
ref="ruleFormRef"
|
2021-09-17 00:18:50 +08:00
|
|
|
:model="ruleForm"
|
|
|
|
:rules="rules"
|
|
|
|
label-width="120px"
|
|
|
|
class="demo-ruleForm"
|
2021-12-15 16:36:49 +08:00
|
|
|
:size="formSize"
|
2022-05-25 23:02:57 +08:00
|
|
|
status-icon
|
2021-09-17 00:18:50 +08:00
|
|
|
>
|
|
|
|
<el-form-item label="Activity name" prop="name">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-input v-model="ruleForm.name" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="Activity zone" prop="region">
|
|
|
|
<el-select v-model="ruleForm.region" placeholder="Activity zone">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-option label="Zone one" value="shanghai" />
|
|
|
|
<el-option label="Zone two" value="beijing" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2022-05-25 23:02:57 +08:00
|
|
|
<el-form-item label="Activity count" prop="count">
|
|
|
|
<el-select-v2
|
|
|
|
v-model="ruleForm.count"
|
|
|
|
placeholder="Activity count"
|
|
|
|
:options="options"
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
2021-09-17 00:18:50 +08:00
|
|
|
<el-form-item label="Activity time" required>
|
|
|
|
<el-col :span="11">
|
|
|
|
<el-form-item prop="date1">
|
|
|
|
<el-date-picker
|
|
|
|
v-model="ruleForm.date1"
|
|
|
|
type="date"
|
2022-05-05 22:04:32 +08:00
|
|
|
label="Pick a date"
|
2021-09-17 00:18:50 +08:00
|
|
|
placeholder="Pick a date"
|
|
|
|
style="width: 100%"
|
2022-03-14 04:16:11 +08:00
|
|
|
/>
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-col>
|
2021-12-15 17:32:09 +08:00
|
|
|
<el-col class="text-center" :span="2">
|
|
|
|
<span class="text-gray-500">-</span>
|
2021-12-15 16:36:49 +08:00
|
|
|
</el-col>
|
2021-09-17 00:18:50 +08:00
|
|
|
<el-col :span="11">
|
|
|
|
<el-form-item prop="date2">
|
|
|
|
<el-time-picker
|
|
|
|
v-model="ruleForm.date2"
|
2022-05-05 22:04:32 +08:00
|
|
|
label="Pick a time"
|
2021-09-17 00:18:50 +08:00
|
|
|
placeholder="Pick a time"
|
|
|
|
style="width: 100%"
|
2022-03-14 04:16:11 +08:00
|
|
|
/>
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-col>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="Instant delivery" prop="delivery">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-switch v-model="ruleForm.delivery" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="Activity type" prop="type">
|
|
|
|
<el-checkbox-group v-model="ruleForm.type">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-checkbox label="Online activities" name="type" />
|
|
|
|
<el-checkbox label="Promotion activities" name="type" />
|
|
|
|
<el-checkbox label="Offline activities" name="type" />
|
|
|
|
<el-checkbox label="Simple brand exposure" name="type" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-checkbox-group>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="Resources" prop="resource">
|
|
|
|
<el-radio-group v-model="ruleForm.resource">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-radio label="Sponsorship" />
|
|
|
|
<el-radio label="Venue" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-radio-group>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="Activity form" prop="desc">
|
2022-03-14 04:16:11 +08:00
|
|
|
<el-input v-model="ruleForm.desc" type="textarea" />
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
2022-12-06 16:36:21 +08:00
|
|
|
<el-button type="primary" @click="submitForm(ruleFormRef)">
|
|
|
|
Create
|
|
|
|
</el-button>
|
2021-12-15 16:36:49 +08:00
|
|
|
<el-button @click="resetForm(ruleFormRef)">Reset</el-button>
|
2021-09-17 00:18:50 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</template>
|
|
|
|
|
2021-12-15 16:36:49 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { reactive, ref } from 'vue'
|
2022-04-17 17:43:23 +08:00
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2021-12-15 16:36:49 +08:00
|
|
|
|
2023-06-11 20:36:27 +08:00
|
|
|
interface RuleForm {
|
|
|
|
name: string
|
|
|
|
region: string
|
|
|
|
count: string
|
|
|
|
date1: string
|
|
|
|
date2: string
|
|
|
|
delivery: boolean
|
|
|
|
type: string[]
|
|
|
|
resource: string
|
|
|
|
desc: string
|
|
|
|
}
|
|
|
|
|
2022-03-06 22:20:56 +08:00
|
|
|
const formSize = ref('default')
|
2022-01-31 23:43:56 +08:00
|
|
|
const ruleFormRef = ref<FormInstance>()
|
2023-06-11 20:36:27 +08:00
|
|
|
const ruleForm = reactive<RuleForm>({
|
2022-03-06 22:20:56 +08:00
|
|
|
name: 'Hello',
|
2021-12-15 16:36:49 +08:00
|
|
|
region: '',
|
2022-05-25 23:02:57 +08:00
|
|
|
count: '',
|
2021-12-15 16:36:49 +08:00
|
|
|
date1: '',
|
|
|
|
date2: '',
|
|
|
|
delivery: false,
|
|
|
|
type: [],
|
|
|
|
resource: '',
|
|
|
|
desc: '',
|
|
|
|
})
|
|
|
|
|
2023-06-11 20:36:27 +08:00
|
|
|
const rules = reactive<FormRules<RuleForm>>({
|
2021-12-15 16:36:49 +08:00
|
|
|
name: [
|
2022-03-06 22:20:56 +08:00
|
|
|
{ required: true, message: 'Please input Activity name', trigger: 'blur' },
|
|
|
|
{ min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
|
2021-12-15 16:36:49 +08:00
|
|
|
],
|
|
|
|
region: [
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: 'Please select Activity zone',
|
|
|
|
trigger: 'change',
|
|
|
|
},
|
|
|
|
],
|
2022-05-25 23:02:57 +08:00
|
|
|
count: [
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: 'Please select Activity count',
|
|
|
|
trigger: 'change',
|
|
|
|
},
|
|
|
|
],
|
2021-12-15 16:36:49 +08:00
|
|
|
date1: [
|
|
|
|
{
|
|
|
|
type: 'date',
|
|
|
|
required: true,
|
|
|
|
message: 'Please pick a date',
|
|
|
|
trigger: 'change',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
date2: [
|
|
|
|
{
|
|
|
|
type: 'date',
|
|
|
|
required: true,
|
|
|
|
message: 'Please pick a time',
|
|
|
|
trigger: 'change',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
type: [
|
|
|
|
{
|
|
|
|
type: 'array',
|
|
|
|
required: true,
|
|
|
|
message: 'Please select at least one activity type',
|
|
|
|
trigger: 'change',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
{
|
|
|
|
required: true,
|
|
|
|
message: 'Please select activity resource',
|
|
|
|
trigger: 'change',
|
2021-09-17 00:18:50 +08:00
|
|
|
},
|
2021-12-15 16:36:49 +08:00
|
|
|
],
|
|
|
|
desc: [
|
2022-03-06 22:20:56 +08:00
|
|
|
{ required: true, message: 'Please input activity form', trigger: 'blur' },
|
2021-12-15 16:36:49 +08:00
|
|
|
],
|
|
|
|
})
|
2022-01-31 23:43:56 +08:00
|
|
|
|
2022-03-06 22:20:56 +08:00
|
|
|
const submitForm = async (formEl: FormInstance | undefined) => {
|
2022-01-31 23:43:56 +08:00
|
|
|
if (!formEl) return
|
2022-03-06 22:20:56 +08:00
|
|
|
await formEl.validate((valid, fields) => {
|
2022-01-31 23:43:56 +08:00
|
|
|
if (valid) {
|
|
|
|
console.log('submit!')
|
|
|
|
} else {
|
2022-03-06 22:20:56 +08:00
|
|
|
console.log('error submit!', fields)
|
2022-01-31 23:43:56 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return
|
|
|
|
formEl.resetFields()
|
|
|
|
}
|
2022-05-25 23:02:57 +08:00
|
|
|
|
|
|
|
const options = Array.from({ length: 10000 }).map((_, idx) => ({
|
|
|
|
value: `${idx + 1}`,
|
|
|
|
label: `${idx + 1}`,
|
|
|
|
}))
|
2021-09-17 00:18:50 +08:00
|
|
|
</script>
|