<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :model="form" label-width="200px">
        <div class="filter-control">
          <div>
            <label class="label_width">套餐1:</label>
            <span>12个月超级会员，售价: </span>
            <el-input v-model="form.price1" type="text" size="mini" style="width:150px">
              <template slot="append">元</template>
            </el-input>
          </div>
        </div><br>
        <div class="filter-control">
          <div>
            <label class="label_width">套餐2:</label>
            <span>3个月超级会员，售价</span>
            <el-input v-model="form.price2" type="text" size="mini" style="width:150px">
              <template slot="append">元</template>
            </el-input>
          </div>
        </div><br>
        <div class="filter-control">
          <div>
            <label class="label_width">采美豆兑换套餐:</label>
            <span>采美豆兑换超会员套餐比例为</span>
            <el-input v-model="form.proportion" size="mini" style="width:150px">
              <template slot="append">:1</template>
            </el-input>
          </div>
        </div>
      </el-form>
      <div>
        <el-button type="primary" size="mini" @click="updateMeal()">保存</el-button>
      </div>
    </div>
    <el-dialog title="提示" :visible.sync="dialogTableVisible" width="50%">
      <span>超级会员套餐以修改完成</span>
      <div slot="footer">
        <el-button type="primary" @click="renovate()">确定</el-button>
        <el-button type="primary" @click="dialogTableVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { fetchFindPackage, updatePrice } from '@/api/member/meal/meal'

export default {
  name: 'MemberMeal',
  data() {
    return {
      form: {
        price1: '',
        price2: '',
        proportion: ''
      },
      dialogTableVisible: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取超级会员套餐配置
    async getList() {
      const res = await fetchFindPackage()
      this.form.price1 = res.data.price1
      this.form.price2 = res.data.price2
      this.form.proportion = res.data.proportion
    },
    // 修改超级会员套餐配置
    async updateMeal() {
      const res = await updatePrice(this.form)
      if (res.code === 1) {
        this.dialogTableVisible = true
      }
    },
    // 提示信息确认刷新数据
    renovate() {
      this.dialogTableVisible = false
      this.getList()
    }
  }
}
</script>

<style>
.label_width{
  width: 150px;
  text-align: right;
}
</style>
