<template>
  <div>
    <i style="font-weight:bold" class="el-icon-plus" @click="() => append()"></i>
    <el-dialog title="新建部门" append-to-body width="864px" :visible.sync="dialogDepVisible" @close="onClose">
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" size="small" label-width="100px" label-position="left">
          <el-col  :span="12">
            <el-form-item class="item_width-full" label="部门名称" prop="depname">
              <el-input class="item_width-full" v-model="form.depname" placeholder="请输入部门名称" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col  :span="12">
            <el-form-item class="item_width-full" label="部门编号" prop="depno">
              <el-input class="item_width-full" v-model="form.depno" placeholder="请输入部门编号" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">  
            <el-form-item class="item_width-full" label="部门描述" prop="remarks">
              <el-input class="item_width-full" v-model="form.remarks" placeholder="请输入部门描述" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">  
            <el-form-item class="item_width-full" label="排序">
              <el-input class="item_width-full" v-model="form.sequence" placeholder="请输入部门排序号" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否启用">
              <el-checkbox v-model="form.isused" :false-label="0" :true-label="1">是否启用</el-checkbox>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogDepVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {
      dialogDepVisible:false,
      rules:{
        depname: [
          { required: true, message: '请输入部门名称', trigger: 'blur' },
        ],
        remarks: [
          { required: true, message: '请输入部门描述', trigger: 'blur' },
        ],
        depno: [
          { required: true, message: '请输入部门编号', trigger: 'blur' },
        ],
      },
      form:{
        "departmentid":0,
        "depname":"",
        "isused":1,
        "depno":'',
        "parentid":this.data.departmentid,
        "remarks":"",
        "sequence":""
      }
    }
  },
  methods:{
    append () {
      this.dialogDepVisible = true
    },
    onSubmit () {
      this.$refs['form'].validate(async (valid) => {
        if (!valid)  return false;
        const res = await this.$api.requested({
          "classname": "webmanage.department.department",
          "method": "insertormodify_department",
          "content": this.form
        })
        if (res.code === 1)
          this.dialogDepVisible = false
          this.$emit('onSuccess')
      });
    },
    onClose () {
      this.$refs['form'].resetFields();
    }
  }
}

</script>
<style>
</style>
<style scoped>
.item_width-full{
  width:100%
}

</style>