export default {

  methods: {
    addDir() {
      console.log("addDir 同级目录");
      this.initForm();
      // this.append(this.thisformdata);
      this.isShowDrop = false;
      console.log(this.thisformdata);
      this.materiaDirDialog.visible = true;
      this.dirform.parentId = this.thisformdata.parentId;
      this.isChildDir = false;
    },

    addDirChild() {
      console.log("addDirChild", this.thisformdata);
      //新增物料类目子树时，子树级别校验
      let parentId = this.thisformdata.id ? this.thisformdata.id : -1;
      this.$post("/materia/category/getLevel", {
        parentId: parentId,
      }).then((res) => {
        if(res.isNotEndLevel){
          this.initForm();
          this.dirform.parentId = this.thisformdata.id;
          this.isShowDrop = false;
          this.materiaDirDialog.visible = true;
          this.isChildDir = true;
        }else{
          this.$message.error("添加的子目录超过最大目录数！");
        }
      })
      .catch((error) => {
          this.$message.error(error.message);
      });
    },

    addMateria() {
      console.log("addMateria");
      this.isShowDrop = false;
      this.initForm();

      if (this.thisformdata.type === 0) {
        //从目录添加
        this.form.categoryId = this.thisformdata.id;
        this.materiaDialog.visible = true;
      } else if (this.thisformdata.type === 2) {
        //从物料添加 需查询物料类目
        this.$post("/materia/view", {
          id: this.thisformdata.id,
        }).then(({ data }) => {
          data.entity = this.util_toString(data.entity, this.toString);
          //this.dirform = Object.assign({}, this.dirform, data.entity);

          this.form.categoryId = data.entity.categoryId;
          this.materiaDialog.visible = true;
        });
      } else {
        console.log("未选择目录");
        this.$message.warning("未选择目录");
        this.materiaDialog.visible = false;
      }
    },

    addMateriaAtts() {
      console.log("addAtts");
      if (JSON.stringify(this.tableRowData) == "{}") {
        this.$message.info("请选择物料！");
        return;
      }

      this.fileList=[];
      this.initForm();
      this.attform.tableDataId = this.tableRowData.id;
      this.materiaAttsDialog.visible = true;
      this.isShowDrop = false;
    },

    addMateriaSupply() {
      if (JSON.stringify(this.tableRowData) == "{}") {
        this.$message.info("请选择物料！");
        return;
      }
       this.initForm();
         this.materiaSupplyDialog.visible = true;
         this.supplyform.materiaId = this.tableRowData.id;

    },

    editDir() {
      console.log("editDir");
      //初始化获取根节点
      this.$post("/materia/category/view", {
        id: this.thisformdata.id,
      }).then(({ data }) => {
        data.entity = this.util_toString(data.entity, this.toString);
        this.dirform = Object.assign({}, this.dirform, data.entity);
      });

      this.materiaDirDialog.visible = true;
      this.isChildDir = false;
    },

    editMateria() {
      if (JSON.stringify(this.tableRowData) == "{}") {
        this.$message.info("请选择物料！");
        return;

      }
      console.log("editMateria " + this.tableRowData.id);
      this.$post("/materia/view", {
        id: this.tableRowData.id,
      }).then(({ data }) => {
        data.entity = this.util_toString(data.entity, this.toString);
        this.form = Object.assign({}, this.form, data.entity);
        this.form.costPlan = ((this.form.costPlan) / 1000).toFixed(2);
        this.materiaDialog.visible = true;
      });

      this.isShowDrop = false;
    },


  },

  data() {
    return {
      isShowAddDir: true,
      isShowAddDirChild: true,
      isShowEdit: true,
      isShowDelete: true,
      isShowEditMateria: true,
      isShowDeleteMateria: true,
      isShowAddMateria: true,
      isShowAddMateriaAtts: true,
      isShowAddMateriaSupply: true,
    }
  }
}



