<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 style="width:300px;" :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 style="width:300px;" :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 style="width:300px;" :disabled="ids" v-model.trim="form.销量" autocomplete="off" />
      </el-form-item>
  </el-col>
  </el-row>
    <el-form-item label="状态">
    <el-select v-model="form.状态" :disabled="ids" style="width: 300px;" 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-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,addproduct,editPackage } from '@/api/table'

  export default {
    name: 'TableEdit',
    data() {
      return {
        ids:true,
        status:'',
          options: [{
          value: '1',
          label: '上架'
        }, {
          value: '2',
          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 = '添加'
          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 = row
        }else{
           this.title = '编辑'
            this.ids = false
          this.form = 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) {
            if(this.form.状态 == '上架' ) this.form.状态 = '1'
             if(this.form.状态 == '下架' ) this.form.状态 = '2'
            const { msg } = await addproduct(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>

