<template>
  <div class="addCombo app-container" v-loading="loading1">
    <el-form
      :model="setQuery"
      ref="setQuery"
      :rules="rules"
      label-width="130px"
    >
      <el-form-item label="套餐名称：" prop="setMealName">
        <el-input
          v-model="setQuery.setMealName"
          :maxlength="11"
          class="item-width-300"
        ></el-input>
      </el-form-item>
      <el-form-item label="套餐code：" prop="setMealCode">
        <el-input
          v-model="setQuery.setMealCode"
          :maxlength="11"
          class="item-width-300"
        ></el-input>
      </el-form-item>
      <el-form-item label="套餐说明：">
        <el-input
          type="textarea"
          placeholder="请输入套餐说明"
          v-model="setQuery.setMealDetail"
          maxlength="400"
          :rows="6"
          class="item-width-500"
          show-word-limit
        >
        </el-input>
      </el-form-item>
    </el-form>

    <div class="btn-group">
      <el-button>取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >确 定</el-button
      >
    </div>
  </div>
</template>

<script>
import { addOrUpdate } from "@/api/common";
export default {
  data() {
    return {
      loading: false,
      loading1: false,
      setQuery: {
        setMealCode: 0,
        setMealDetail: "",
        setMealId: 0,
        setMealName: "",
      },
      rules: {
        setMealCode: [
          { required: true, message: "请输入套餐code", trigger: "blur" },
        ],
        setMealName: [
          { required: true, message: "请输入套餐名称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    save() {
      this.loading = true;
      this.$refs.setQuery.validate((v) => {
        if (v) {
          addOrUpdate(this.setQuery).then((res) => {
            this.loading = false;
            if (res.state == "Success") {
              this.$notify({
                title: "成功",
                message: "操作成功",
                type: "success",
              });
              this.setQuery = {
                setMealCode: 0,
                setMealDetail: "",
                setMealId: 0,
                setMealName: "",
              };
              this.$router.push("/operationManage/comboManage/index");
            }
          });
        }
      });
    },
  },
  created () {
  },
};
</script>

<style lang="scss" scoped>
.addCombo {
  padding-bottom: 40px;
  .btn-group {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>