<template>
  <el-dialog title="修改会员价格" :close-on-click-modal="false" :visible.sync="open" width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="价格" prop="vipPrice">
        <el-input v-model="form.vipPrice" placeholder="请输入会员价格"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getVipPrice, updateVipPrice } from '@/api/xq/vipPrice'

export default {
  components: {
  },
  data () {
    return {
      open: false,
      form:{
        id: undefined,
        vipPrice: undefined,
      },
      // 表单校验
      rules: {
        vipPrice: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ],
      },
      buttonLoading: false,
    }
  },
  created() {
  },
  methods: {
    init (id) {
      this.form.id = id || undefined;
      this.open = true;
      this.$nextTick(() => {
        this.$refs['form'].resetFields();
        if(this.form.id){
          getVipPrice(id).then(response => {
            this.form = response.data;
          });
        }
      })
    },
    // 表单提交
    submitForm () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          updateVipPrice({
            id: this.form.id,
            vipPrice: this.form.vipPrice
          }).then(data => {
            this.$modal.msgSuccess("修改成功");
            this.$modal.buttonLoading = false;
            this.open = false
            this.$emit('refreshDataList')
          }).finally(() => {
            this.buttonLoading = false;
          });
        }
      })
    },
  }
}
</script>
