<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-row>
  <el-col :span="12">
   <el-form-item label="券包名称" prop="券包名称">
        <el-input :disabled="ids" v-model.trim="form.券包名称" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>
   <el-row>
   <el-col :span="12">
   <el-form-item label="券包价格" prop="券包价格">
        <el-input :disabled="ids" v-model.trim="form.券包价格" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>
  <el-row>
  <el-col :span="2">
   <el-form-item label="券1" prop="券1">
        <!-- <el-input v-model.trim="form.券包名称" autocomplete="off" /> -->
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券ID" prop="券ID">
        <el-input :disabled="ids" v-model="form.package1.券ID" autocomplete="off" />
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券有效期" prop="券的有效期限">
        <el-input :disabled="ids" v-model="form.package1.券的有效期限" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>
   <el-row>
     <el-col :span="2">
   <el-form-item label="券2" prop="券2">
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券ID" prop="券ID">
        <el-input :disabled="ids" v-model="form.package2.券ID" autocomplete="off" />
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券有效期" prop="券的有效期限">
        <el-input :disabled="ids" v-model="form.package2.券的有效期限" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>

   <el-row>
     <el-col :span="2">
   <el-form-item label="券3" prop="券3">
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券ID" prop="券ID">
        <el-input :disabled="ids" v-model="form.package3.券ID" autocomplete="off" />
      </el-form-item>
  </el-col>
   <el-col :span="10">
   <el-form-item label="券有效期" prop="券的有效期限">
        <el-input :disabled="ids" v-model="form.package3.券的有效期限" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>

   <!-- <el-row>
 
  </el-row> -->
       </template>
         <!-- <el-form-item v-else label="订单状态" prop="订单状态">
             <el-select v-model="form.订单状态" placeholder="请选择">
             <el-option
               v-for="item in options"
               :key="item.value"
               :label="item.label"
               :value="item.value">
             </el-option>
           </el-select>
      </el-form-item> -->
    </el-form>
     
    <div slot="footer" class="dialog-footer" v-if="!ids">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { doEdit,addPackage,editPackage } from '@/api/table'

  export default {
    name: 'TableEdit',
    data() {
      return {
        ids:true,
        status:'',
          options: [{
          value: '已支付',
          label: '已支付'
        },
        ],
        form: {
          券包名称:'',
          券包价格:'',
          package1:{
             券ID:'',
          券的有效期限:'',
          },
           package2:{
             券ID:'',
          券的有效期限:'',
          },
           package3:{
             券ID:'',
          券的有效期限:'',
          },
         
        
        },
        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,ids) {
        console.log(row,ids,'???')
        this.status = row
        if (!row) {
        this.title = '添加2'
        this.ids = false
        this.form.券包名称='',
        this.form. 券包价格='',
        this.form.package1 = {}
        this.form.package2 = {}
        this.form.package3 = {}
           
        } else if (ids) {
          this.ids = ids
           this.title = '查看'
             this.form = Object.assign({}, row)
        }else{
           this.title = '编辑'
            this.ids = false
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close(){
        // this.$refs['form'].resetFields()
        // this.form = this.$options.data().form
      this.dialogFormVisible = false
      this.form.券包名称='',
      this.form. 券包价格='',
      this.form.package1 = {}
      this.form.package2 = {}
      this.form.package3 = {}
        // this.$emit('fetch-data')
      },
      save() {
        if(this.status){
           this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await editPackage(this.form)
            this.$message({
              message:msg,
              duration:2000,
              type:'success'
            })
            // this.$baseMessage(msg, 'success')
            this.$refs['form'].resetFields()
            this.$parent.fetchData();
            this.dialogFormVisible = false
            this.form = this.$options.data().form
          } else {
            return false
          }
        })
        }else{
            this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await addPackage(this.form)
            this.$message({
              message:msg,
              duration:2000,
              type:'success'
            })
            // this.$baseMessage(msg, 'success')
            this.$refs['form'].resetFields()
            this.$parent.fetchData();
            this.dialogFormVisible = false
            this.form = this.$options.data().form
          } else {
            return false
          }
        })

        }
        // console.log(this.status,'--=')
      },
    },
  }
</script>

