<template>
  <div class="wrapper editwrap">
    <el-dialog
      :visible.sync="dialogVisible"
      :title="dialoTitle"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <el-form ref="editForm" :model="editForm" :rules="rules" label-width="100px">
        <el-form-item label="上级部门">
          <el-input disabled  v-model="checkedObj.fullName"></el-input>
        </el-form-item>
        <el-form-item label="部门全称" prop="fullName">
          <el-input v-model="editForm.fullName"></el-input>
        </el-form-item>
        <el-form-item label="部门简称" prop="shortName">
          <el-input v-model="editForm.shortName"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="editForm.description" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="editForm.sort" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="confirmFun('editForm')">确定</el-button>
        <el-button @click="$emit('dialogFun')" size="small">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="scss">
</style>
<script lang="ts">
import { Component, Vue, Provide, Prop, Watch } from "vue-property-decorator";
import { State, Getter, Mutation, Action } from "vuex-class";

@Component({
  components: { }
})
export default class BranchMgEdit extends Vue {
  //属性或参数中使用!:表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
  @Prop(Boolean) dialogVisible !: Boolean;
  @Prop(Object) editForm !:  {
    parentIds:number;
  };
  @Prop(String) dialoTitle !: String;
  @Prop(Object) checkedObj !:  {
    id: string;
    level: string;
    parentIds:string;
  };//选中节点

  @Provide() dialogTableVisible: Boolean = false;
  @Provide() rules: any = {
    fullName: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
  };

  @Provide() loadmap:Boolean = false;

  dialogcancelFun(){
    this.dialogTableVisible = false;
  }
  /**
   * parentIds格式'[0],[1],[2]'
   */
  confirmFun(formName: string) {
    let that = this,params:any = Object.assign({},that.editForm);
    let ids = that.checkedObj.parentIds;
    if(that.dialoTitle == '新增'){
        if(ids == ''){
        params.parentIds = '[0]';
      }else{
        params.parentIds = ids + ',' + '['+ Number(that.checkedObj.id) + ']'
      }
      console.log(params.parentIds)
      params.parentId = Number(that.checkedObj.id);
      params.level = String( Number(that.checkedObj.level) + 1);
    }
    // console.log(params)
    // return
    (that as any).$refs[formName].validate((valid: boolean) => {
      if (valid) {
        (that as any).$axios
          .post(`/dept/addOrEditDeptInfo`,params )
          .then((res: any) => {
            if( res ){
            (that as any).$emit("dialogFun");
            (that as any).$message({
              message: "操作成功！",
              type: "success"
            });
            that.$emit("refreshTableData"); //刷新表格
            }
          });
      } else {
        return false;
      }
    });
  }
  created() {
    let that = this;
    console.log(that.editForm)
  }
}
</script>
