<template>
<div>
  <el-button size="small" @click="onShow(drawer = true)" type="text">编 辑</el-button>
  <el-drawer
    title="编辑"
    :visible.sync="drawer"
    direction="rtl"
    append-to-body>
    <div class="drawer__panel">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" size="small">
        <el-form-item label="仓库名称" prop="stockname">
          <el-input v-model="form.stockname" placeholder="输入仓库名称"></el-input>
        </el-form-item>
        <el-form-item label="是否启用">
          <el-radio-group v-model="form.isused">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">停用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否销售仓">
          <el-radio-group v-model="form.issalestock">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item>
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item> -->
      </el-form>
    </div>
    <div class="fixed__btn__panel">
      <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
      <el-button size="small" type="primary" @click="submitForm" class="normal-btn-width">确 定</el-button>
    </div>
  </el-drawer>
</div>
</template>

<script>
export default {
  props:['data'],
  data() {
    return {
      form: {
        stockid: 0,
        stockname: '',
        isused: '1',
        issalestock:'1'
      },
      rules: {
        stockname: [
          { required: true, message: '请输入仓库名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
      },
      drawer:false
    }
  },
  methods: {
    onShow () {
      this.form = Object.assign({},this.form,this.data)
    },
    submitForm() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          // 提交表单
          const res = await this.$api.requested({
            "id": 20230104094704,
            "content": this.form
          })
          console.log(res);
          
          this.tool.showMessage(res,()=>{
            this.drawer = false
            console.log('触发');
            
            this.$emit('onSuccess')
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>