<template>
  <el-form ref="resetFormData" :model="form" label-width="auto" style="width: 750px" size="large">
  </el-form>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="优惠券名称">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="兑换积分">
      <el-input v-model="form.requirePoints" />
    </el-form-item>
    <el-form-item label="满（元）">
      <el-input v-model="form.standardAmount" />
    </el-form-item>
    <el-form-item label="减（元）">
      <el-input v-model="form.conditionAmount" />
    </el-form-item>
    <el-form-item label="截至日期">
      <el-date-picker
          v-model="form.endTime"
          type="datetime"
          placeholder="Pick a Date"
          format="YYYY-MM-DD hh:mm:ss"
          value-format="YYYY-MM-DD hh:mm:ss"
      />
    </el-form-item>
    <el-form-item label="简介">
      <el-input v-model="form.content" type="textarea" />
    </el-form-item>
    <el-form-item label="使用说明">
      <el-input v-model="form.description" type="textarea" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="AddCoupon">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { ref,onMounted} from 'vue'
import {Plus} from "@element-plus/icons-vue";
import {ElMessage, type UploadProps} from "element-plus";
import myAxios from "@/api/myAxios";


const fileSimple = ref()
const form = ref({
  name: '',
  standardAmount:0,//满
  conditionAmount:0,//减
  requirePoints:0,
  endTime: '',
  content:'',
  description:'',
})
onMounted(() => {

})
const AddCoupon = async () => {
  const values = Object.values(form.value);
  if (values.some(value => value === null || value === undefined || value === '')) {
    ElMessage({
      type: 'warning',
      message: '请检查表单数据是否完整填写'
    });
    return;
  }
  const res = await myAxios.post('/coupon/add  ', {...form.value });
  if (res.data.code === 1) {
    ElMessage({
      type: 'success',
      message: "提交成功"
    });
  } else {
    ElMessage.error("服务错误");
  }
}

const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles)
}

</script>
