Commit 7733d9bb authored by renjintao's avatar renjintao

shopTreeLeft

parent 9ab9fcb7
...@@ -16,21 +16,22 @@ ...@@ -16,21 +16,22 @@
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</h3> </h3>
<div class="tree"> <div class="tree" :style="{height:divHeight}">
<Tree ref="tree" :data="tree" @on-select-change="change" :render="renderContent" /> <Tree ref="tree" :data="tree" @on-select-change="change" :render="renderContent" />
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Api from './api' import Api from "./api";
export default { export default {
name: 'shopTreeLeft', name: "shopTreeLeft",
data() { data() {
return { return {
expand: true, expand: true,
ids: [], ids: [],
tree: [] tree: [],
} divHeight: ""
};
}, },
props: { props: {
CId: { CId: {
...@@ -38,57 +39,67 @@ export default { ...@@ -38,57 +39,67 @@ export default {
default: 0 default: 0
} }
}, },
mounted() {}, mounted() {
window.onresize = () => {
///浏览器窗口大小变化
return (() => {
window.screenHeight = window.innerHeight;
this.divHeight = window.innerHeight - 240 + "px";
})();
};
},
created() { created() {
this.loadTree() this.loadTree();
var theight = window.innerHeight - 240 + "px";
this.divHeight = theight;
}, },
methods: { methods: {
toggle() { toggle() {
this.expand = !this.expand this.expand = !this.expand;
this.getTrees(this.tree) this.getTrees(this.tree);
//this.loadTree() //this.loadTree()
}, },
async loadTree() { async loadTree() {
//alert(this.CId) //alert(this.CId)
Api.getshoptree({ Id: this.CId }).then((r) => { Api.getshoptree({ Id: this.CId }).then(r => {
if (r.success) { if (r.success) {
if (r.result.length > 0) { if (r.result.length > 0) {
this.tree = r.result this.tree = r.result;
this.change1(this.tree) this.change1(this.tree);
} else { } else {
this.tree = [ (this.tree = [
{ title: '暂无组织信息', value: -100, expand: true, children: [] } { title: "暂无组织信息", value: -100, expand: true, children: [] }
], ]),
this.$emit('storeIds', [-100]) this.$emit("storeIds", [-100]);
this.$emit('treeData', r.result) this.$emit("treeData", r.result);
} }
} }
}) });
}, },
//重构左侧树 //重构左侧树
getTrees(trees) { getTrees(trees) {
var expand = this.expand var expand = this.expand;
trees.forEach((data, index) => { trees.forEach((data, index) => {
var that = this var that = this;
data.expand = expand data.expand = expand;
if (data.children.length > 0) { if (data.children.length > 0) {
this.getTrees(data.children) this.getTrees(data.children);
} }
}) });
return trees return trees;
}, },
renderContent(h, { root, node, data }) { renderContent(h, { root, node, data }) {
return h( return h(
'span', "span",
{ {
style: { style: {
color: '#000', //根据选中状态设置样式 color: "#000", //根据选中状态设置样式
cursor: 'pointer', cursor: "pointer",
background: node.node.selected ? '#AAD8D4' : '#ffffff', background: node.node.selected ? "#AAD8D4" : "#ffffff",
paddingLeft: '10px', paddingLeft: "10px",
paddingRight: '10px', paddingRight: "10px",
paddingTop: '3px', paddingTop: "3px",
paddingBottom: '3px' paddingBottom: "3px"
}, },
on: { on: {
// click: () => { // click: () => {
...@@ -99,47 +110,47 @@ export default { ...@@ -99,47 +110,47 @@ export default {
} }
}, },
data.title data.title
) );
}, },
//得到此树节点下所有是产品的Id //得到此树节点下所有是产品的Id
getAllIds(trees) { getAllIds(trees) {
trees.forEach((data, index) => { trees.forEach((data, index) => {
var that = this var that = this;
this.ids.push(data.value) this.ids.push(data.value);
if (data.children.length > 0) { if (data.children.length > 0) {
this.getAllIds(data.children) this.getAllIds(data.children);
} }
}) });
}, },
change(value) { change(value) {
if (value.length > 0) { if (value.length > 0) {
this.ids = [] this.ids = [];
this.getAllIds(value) this.getAllIds(value);
if (this.ids.length > 0) { if (this.ids.length > 0) {
this.$emit('storeIds', this.ids) this.$emit("storeIds", this.ids);
//this.easySearch.storeId.value = this.ids //this.easySearch.storeId.value = this.ids
} else { } else {
this.$emit('storeIds', [-1]) this.$emit("storeIds", [-1]);
} }
} else { } else {
this.$emit('storeIds', [-1]) this.$emit("storeIds", [-1]);
} }
this.$emit('treeData', value) this.$emit("treeData", value);
}, },
change1(value) { change1(value) {
if (value.length > 0) { if (value.length > 0) {
this.ids = [] this.ids = [];
this.getAllIds(value) this.getAllIds(value);
if (this.ids.length > 0) { if (this.ids.length > 0) {
this.$emit('storeIds', this.ids) this.$emit("storeIds", this.ids);
} else { } else {
this.$emit('storeIds', [-1]) this.$emit("storeIds", [-1]);
} }
} else { } else {
this.$emit('storeIds', [-1]) this.$emit("storeIds", [-1]);
} }
} }
} }
} };
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment