<template>
  <div class="app-container">
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleCancle"
    >
      <el-form
        :model="form"
        :rules="rules"
        ref="form"
        label-width="100px"
        class="demo-form"
      >
        <el-form-item label="券类型" prop="region">
          <el-select v-model="form.region" placeholder="请选择">
            <el-option
              v-for="item in activeAreaList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="优惠内容" prop="content">
          <div class="d-flex a-center custom-input">
            <div class="margin-right">减免</div>
            <el-input
              class="flex-1"
              type="number"
              min="1"
              placeholder="减免金额>0且<99999"
              v-model="form.content"
            >
            </el-input>
            <div class="margin-left">元</div>
          </div>
        </el-form-item>
        <el-form-item label="优惠门槛" prop="content">
          <div class="d-flex a-center custom-input">
            <div class="margin-right">最低消费，满</div>
            <el-input
              class="flex-1"
              type="number"
              min="0"
              v-model="form.content"
            />
            <div class="margin-left">元，可用</div>
          </div>
        </el-form-item>
        <el-form-item label="生效时间" prop="startTime">
          <el-date-picker
            v-model="form.startTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="失效时间" prop="endTime">
          <el-date-picker
            v-model="form.endTime"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button @click="handleCancle">取消</el-button>
      <el-button v-if="isEdit" type="primary" @click="onSubmit">{{
        form.id ? "保存修改" : "保存添加"
      }}</el-button>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    dialogVisible: {
      type: Boolean,
    },
    title: {
      type: String,
    },
    isEdit:Boolean
  },
  data() {
    return {
      width: "30%",
      value1: "",
      form: {
        region: "",
        content: "",
        startTime: "",
        endTime: "",
      },
      rules: {
        content: [
          { required: true, message: "请输入优惠内容", trigger: "blur" },
        ],
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
        startTime: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
        endTime: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
      },
      activeAreaList: [
        {
          value: "新用户券",
          label: "新用户券",
        },
        {
          value: "满减券",
          label: "满减券",
        },
      ],
    };
  },
  created() {},
  methods: {
    handleCancle() {
      this.$emit("cancle");
    },
    onSubmit() {
      let that = this;
      that.$refs.form.validate((valid) => {
        console.log(valid);
        if (valid) {
          that.$emit("onSubmit", that.form);
        } else {
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.description {
  font-size: 25px;
  margin-top: 10px;
}
.d-flex {
  display: flex;
}
.a-center {
  align-items: center;
}
.flex-1 {
  flex: 1;
}
.margin-left {
  margin-left: 10px;
}
.margin-right {
  margin-right: 10px;
}
.custom-input {
  width: 250px !important;
}
.customer {
  display: flex;
  flex-wrap: wrap;
  margin-top: 20px;

  &-lab {
    width: 33%;

    &-icke {
      width: 100%;
    }
  }
}
</style>
