<template>
  <div class="inline-16">
    <el-button type="text" icon="el-icon-edit" size="small" class="inline-16" style="color:#333" @click="onShow()">编 辑</el-button>
    <el-dialog title="编辑群组" append-to-body :visible.sync="dialogFormVisible" width="600px">
      <el-form :model="form" ref="form" label-position="right" label-width="80px" size="small">
        <el-form-item label="群组名称" prop="groupname" :rules="[
          { required: true, message: '群组名称不能为空'},
        ]">
          <el-input v-model="form.groupname" autocomplete="on" placeholder="输入群组名称"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" style="width:120px" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="small" style="width:120px" type="primary" @click="addGroup()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {
      dialogFormVisible:false,
      form:{}
    }
  },
  methods:{
    onShow () {
      this.dialogFormVisible = true
      this.form = Object.assign({},this.form,this.data.data)
    },
    addGroup () {
      this.$refs['form'].validate(async (valid) => {
        if (!valid)  return false;
        const res = this.$api.requested({
          "id": "20220831164203",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          setTimeout(() => {
            this.$emit('onSuccess')
          }, 500);
          this.dialogFormVisible = false
        })
      });
    }
  }
}

</script>
<style>
</style>