<template>
  <div class="app-container">
    <div class="club-container" style="width: 100%;height: 600px;padding-top: 40px;">
      <div class="filter-container">
        <div class="filter-control">
          <el-form :model="form" label-width="140px">
            <el-form-item label="套餐1:" prop="price1" :rules="rules.price1">
              <span>12个月超级会员，售价：</span>
              <el-input v-model="form.price1" style="width: 150px">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="套餐2:" prop="price2" :rules="rules.price2">
              <span>3个月超级会员，售价：</span>
              <el-input v-model="form.price2" style="width: 150px">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
            <el-form-item label="采美豆兑换套餐:" prop="proportion" :rules="rules.proportion">
              <span>采美豆兑换超会员套餐比例为：</span>
              <el-input v-model="form.proportion" style="width: 150px">
                <template slot="append">:1</template>
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="updateMeal">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'MemberMeal',
  data() {
    return {
      form: {
        price1: '',
        price2: '',
        proportion: ''
      },
      rules: {
        price1: [{ required: true, message: '请输入套餐1价格', trigger: 'blur' }],
        price2: [{ required: true, message: '请输入套餐2价格', trigger: 'blur' }],
        proportion: [{ required: true, message: '请输入采美豆', trigger: 'blur' }]
      },
      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() {
      try {
        await updatePrice(this.form)
        this.$message.success('保存超级会员套餐成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

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