<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
       <template >
      <el-form-item label="券ID" prop="券ID">
        <el-input v-model.trim="form.券ID" autocomplete="off" />
      </el-form-item>
      <el-form-item label="手机号" prop="手机号">
        <el-input v-model.trim="form.手机号" autocomplete="off" />
      </el-form-item>
       <el-form-item label="有效期" prop="有效期">
             <el-date-picker
      v-model="form.有效期"
      style="width:350px;"
      type="date"
      value-format="yyyy-MM-dd"
      placeholder="选择日期">
    </el-date-picker>
      </el-form-item>
       </template>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { distributeEdit } from '@/api/table'

  export default {
    name: 'TableEdit',
    data() {
      return {
          options: [{
          value: '已支付',
          label: '已支付'
        },
        ],
        form: {
          title: '',
          author: '',
          smallWow:'',
          time:'',
          author:''
        },
        rules: {
            券ID: [{ required: true, trigger: 'blur', message: '请输入券ID' }],
             手机号: [{ required: true, trigger: 'blur', message: '请输入手机号' }],
          有效期: [{ required: true, trigger: 'blur', message: '请选择时间' }],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '派发'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        // this.$refs['form'].resetFields()
        // this.form = this.$options.data().form
        this.dialogFormVisible = false
        // this.$emit('fetch-data')
      },
      save() {
        // console.log(this.form,'--=')
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await distributeEdit(this.form)
            this.$baseMessage(msg, 'success')
            this.$refs['form'].resetFields()
            this.$parent.fetchData();
            this.dialogFormVisible = false
            this.form = this.$options.data().form
          } else {
            return false
          }
        })
      },
    },
  }
</script>
