<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      top="8vh"
      width="40%"
      :visible.sync="dialogVisible"
      center
      @close="handleCancel"
    >
      <div class="el-dialog-div">
      <el-form
        :rules="rules"
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="120px"
        style="height: 90%;"
      >
        <el-form-item label="会员卡名" prop="cardName" class="is-required">
          <el-input v-model="temp.cardName" placeholder="会员卡名" />
        </el-form-item>

        <el-form-item label="卡编号" prop="cardNo" class="is-required">
          <el-input v-model="temp.cardNo" placeholder="卡编号" />
        </el-form-item>

        <el-form-item label="预设开卡金" prop="cardAmount" class="is-required">
          <el-input v-model="temp.cardAmount" placeholder="预设开卡金" />
        </el-form-item>

        <el-form-item label="预设赠送金" prop="giveAmount" class="is-required">
          <el-input v-model="temp.giveAmount" placeholder="预设赠送金" />
        </el-form-item>

        <el-form-item label="最低开卡金额" prop="buildCardAmount" class="is-required">
          <el-input v-model="temp.buildCardAmount" placeholder="最低开卡金额" />
        </el-form-item>

        <el-form-item label="卡折扣" prop="cardDiscount" class="is-required">
          <el-input v-model="temp.cardDiscount" placeholder="卡折扣" />
        </el-form-item>

        <el-form-item label="卡提成" prop="cardPushPercent" class="is-required">
          <el-input v-model="temp.cardPushPercent" placeholder="卡提成" />
        </el-form-item>

        <el-form-item label="工本费用" prop="todos" class="is-required">
          <el-input v-model="temp.todos" placeholder="工本费用" />
        </el-form-item>

        <el-form-item label="状态" prop="cardStatus"  class="is-required">
          <el-radio-group v-model="temp.cardStatus" size="small">
            <el-radio-button label="0">正常</el-radio-button>
            <el-radio-button label="1">禁用</el-radio-button>
          </el-radio-group>
        </el-form-item>

<!--        <el-form-item label="所属门店" prop="shopId"  class="is-required">-->
<!--          <dept-select v-model="temp.shopId" @changeSelect="getDept"  style="width: 100%;"/>-->
<!--        </el-form-item>-->
      </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { editCard } from "@/api/business/card/card";
import {setRequiredFields} from "@/utils";
const requiredFields = []

export default {
  name: "editForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        cardId:'',
        cardName:'',
        cardNo:'',
        cardAmount:'',
        giveAmount:'',
        buildCardAmount:'',
        cardDiscount:'',
        cardPushPercent:'',
        todos:'',
        cardStatus:0,
      },
    }
  },
  methods: {
    open(row) {
      this.temp = this.$options.data().temp
      this.temp = row
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          editCard(this.temp).then(response => {
            this.handleCancel()
            this.$emit('ok', response.data)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    handleCancel() {
      //初始化
      this.temp = this.$options.data().temp
      this.dialogVisible = false
      this.$refs['dataForm'].resetFields()
    }
  },
}
</script>

<style scoped>

</style>
