<template>
  <OrgEditor
    ref="functree"
    :initData="initData()"
    :metainfo="metainfo"
    @controlctl="controlctl"
    @drawaction="drawaction"
    @modisave="orgsave"
    @deletenode="orgsave"
    @onselnode="onselnode"
  ></OrgEditor>
</template>
  <script>
import { getApp, saveAuths, findAuthsByRoles } from "@/api/meta";
import { saveFormData, getFuncs } from "@/api/data";
import OrgEditor from "@/view/components/tables/forms/jsoneditor.vue";
import config from "@/config";
export default {
  name: "treeinfo_page",
  props: {},
  components: {
    OrgEditor
  },
  data() {
    return {
      appkey: "",
      metainfo: {
        name: "节点编辑",
        main: [
          {
            title: "可授权范围",
            key: "baseinfo",
            cols: 2,
            ctls: [
              {
                type: "checkgroup",
                dicName: "authType",
                label: "权限",
                prop: "auths",
                labelField: "name",
                valueField: "id",
                style: {},
                isHide: false
              }
            ]
          }
        ],
        lists: null
      }
    };
  },
  mounted() {
    this.appkey = this.$route.query.appkey;
  },
  methods: {
    onselnode(root, node, data) {},
    orgsave(treedata, modidata) {
      // if(modidata.auths && modidata.auths.length>0){
      //   modidata.sels=[]
      // }
      saveFormData("/web/common/appCtl/saveFuncTree", {
        funcJson: treedata,
        curdata: modidata,
        appkey: this.appkey
      }).then(res => {
        let rtn = res.data;
        console.log("ddddddddddddddddd", rtn);
        if (rtn.status == 0) {
          let treedata2 = rtn.data.funcJson;
          console.log("save org...............................", treedata2);
          this.$refs.functree.treedata = treedata2;
          this.$refs.functree.refreshTree();
          this.$Message.success("当前操作成功完成");
        } else {
        }
      });
    },
    drawaction(v, fm) {},
    controlctl(v, prop, fm) {},
    initData() {
      let self=this
      let pappkey= self.appkey
      return cbk => {
        getFuncs({ appkey: pappkey }).then(res => {
          let rtn = res.data;
          if (rtn.status == 0) {
            let treedata2 = rtn.data.funcJson;
            cbk(treedata2);
          } else {
            throw new Error("获取功能清单数据出错");
          }
        });
      };
    }
  }
};
</script>
  <style>
</style>
