Ben Lin
2025-03-11 8e977a7ec92bc1845079eda2473e9c3fc4691c8d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<template>
  <div class="m-4 mr-0 overflow-hidden bg-white" style="height: 800px;">
    <TigerTree title="仓库" toolbar search checkable :clickRowToExpand="false" :treeData="treeData" :disabled="disabledTree"
      :renderIcon="createIcon" :fieldNames="{ key: 'id', title: 'houseName' }" @select="handleSelect"
      ref="treeRef" />
    <!-- <button :onClick="aa" style="
    position: absolute;
    left: 11px;
    top: 15px;
    font-size: 22px;
    
    background-color: transparent;">+</button> -->
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref, unref } from 'vue';
import { TigerTree, TreeItem, TreeActionType } from '/@/components/TigerTree';
import { getTreeList } from '/@/api/tigerapi/wms/inventory';
import { watch } from 'vue';
export default defineComponent({
  name: 'HouseTree',
  components: { TigerTree },
  emits: ['select', 'success', 'gettree'],
  props: {
    disabledTree: {
      type: Number,
      default: 0,
    }
  },
  setup(props, { emit }) {
    const treeData = ref<TreeItem[]>();
    const treeRef = ref<Nullable<TreeActionType>>(null);
    var disabledTree = ref(false);
 
    function getTree() {
      const tree = unref(treeRef);
      if (!tree) {
        throw new Error('tree is null!');
      }
      return tree;
    }
    async function GetTree() {
      const keys = getTree().getCheckedKeys();
 
      const node = getTree().getSelectedNode(keys[0]);
 
      //createMessage.success(node !== null ? JSON.stringify(node) : null);
    }
    async function fetch() {
      const param={
        ID:'',
        AUTH_ORG:'',
        HOUSE_NAME:'',
        HOUSE_CODE:'',
        PARENT_HOUSE:'',
        CREATE_TIME:'',
        TYPE:''
      }
      treeData.value = (await getTreeList(param)) as unknown as TreeItem[];
      console.log(treeData.value);
    }
 
    function handleSelect(keys: any[]) {
      console.log(treeData.value)
      // const keyss = getTree().getSelectedKeys();
      // const node = getTree().getSelectedNode(keyss[0]);
      // emit('checkedKeys',node)
      //alert(keys[0])
      emit('select', keys[0]);
    }
    onMounted(() => {
      emit('gettree', getTree());
      fetch();
    });
    watch(
      () => props.disabledTree,
      (v) => {
        if(v!=0){
          disabledTree.value=true
        }
      },
    );
    function handleSuccess({ isUpdate, values }) {
      fetch();
    };
 
    // async function GetORG_CODE(params:string) {
    //   var org = await getWHList(params)
    //   return org[0].ORG_CODE
    // }
    function createIcon({ houseType }) {
      if (houseType === 'Warehouse') {
        return 'warehouse|svg';
      }
      if (houseType === 'Region') {
        return 'Region|svg';
      }
      if (houseType === 'Shelf') {
        return 'Shelf|svg';
      }
      return '';
    }
    return {
      treeData,
      treeRef,
      handleSelect,
      handleSuccess,
      //GetORG_CODE,
      createIcon,
      getTree,
      GetTree,
      disabledTree,
      props
    };
  },
});
</script>