<template>
  <div class="app-container app-edit">
    <el-form class="small-space" :model="form" :rules="rules" ref="form" label-position="right" label-width="120px" style="width: 700px;">

      <!-- 状态 -->
      <el-form-item label="状态">
        <el-radio class="radio" v-model="form.status" :label="1">可用</el-radio>
        <el-radio class="radio" v-model="form.status" :label="0">禁用</el-radio>
      </el-form-item>

      <!-- 用户ID -->
      <el-form-item label="用户ID" prop="memberId">
        <el-input v-model="form.memberId" placeholder="请输入用户ID"></el-input>
      </el-form-item>

      <!-- 会员卡类型 -->
      <el-form-item label="会员卡类型" prop="cardType">
        <el-input v-model="form.cardType" placeholder="请输入会员卡类型"></el-input>
      </el-form-item>

      <!-- 场馆类型 -->
      <el-form-item label="场馆类型" prop="venueType">
        <el-input v-model="form.venueType" placeholder="请输入场馆类型"></el-input>
      </el-form-item>

      <!-- 场馆ID -->
      <el-form-item label="场馆ID" prop="venueId">
        <el-input v-model="form.venueId" placeholder="请输入场馆ID"></el-input>
      </el-form-item>

      <!-- 平台来源ID -->
      <el-form-item label="平台来源ID" prop="platformId">
        <el-input v-model="form.platformId" placeholder="请输入平台来源ID"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" :loading="onSubmit" @click="handleSave">保存</el-button>
        <el-button @click="handleCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { find, save } from '@/api//gift/member/card'

export default {
  data() {
    return {
      form: {
        id: undefined,
        status: 1,
        memberId: '',
        cardType: '',
        venueType: '',
        venueId: '',
        platformId: ''
      },

      onSubmit: false,

      // 表单验证规则
      rules: {
//        mobile: [
//          { required: true, message: '请输入手机号码', trigger: 'blur' }
//        ],
//        username: [
//          { required: true, message: '请输入姓名', trigger: 'blur' },
//          { max: 15, message: '姓名长度不能超过15个字符', trigger: 'blur' }
//        ],
//        email: [
//          { required: true, message: '请输入邮箱', trigger: 'blur' },
//          { type: 'email', message: '您输入的邮箱格式不正确', trigger: 'blur' }
//        ],
//        password: [
//          { required: true, message: '请输入密码', trigger: 'blur' },
//          { min: 6, message: '密码长度不能少于6个字符', trigger: 'blur' }
//        ]
      }
    }
  },
  created() {
    if (this.$route.query.id) {
      this.form.id = this.$route.query.id
      this.findById(this.form.id)
    }
  },
  methods: {
    /**
     * 查询送会员卡记录
     */
    findById(id) {
      find(id).then(response => {
        this.form.status = response.giftMemberCard.status
        this.form.memberId = response.giftMemberCard.memberId
        this.form.cardType = response.giftMemberCard.cardType
        this.form.venueType = response.giftMemberCard.venueType
        this.form.venueId = response.giftMemberCard.venueId
        this.form.platformId = response.giftMemberCard.platformId
      })
    },

    /**
     * 保存送会员卡记录
     */
    handleSave() {
      this.$refs.form.validate(valid => {
        if (!valid) {
          return false
        }

        this.onSubmit = true
        save(this.form).then(response => {
          this.$router.go(-1)
        }).finally(() => {
          this.onSubmit = false
        })
      })
    },

    /**
     * 取消
     */
    handleCancel() {
      this.$router.go(-1)
    }
  }
}
</script>
