| | |
| | | <template> |
| | | <div class="product-tree-container " :style="'height:' + tree_Hei +'px'"> |
| | | <div class="product-tree-container"> |
| | | <el-input |
| | | placeholder="输入名称进行过滤" |
| | | style="width: 60%" |
| | |
| | | size="small" |
| | | clearable |
| | | ></el-input> |
| | | <el-button type="primary" @click="add()" style="margin: 10px 0 0 10px;padding: 9px 18px !important;">新增</el-button> |
| | | <el-button v-if="isShow" type="primary" @click="add()" style="margin: 10px 0 0 10px;padding: 9px 18px !important;">新增型号</el-button> |
| | | <el-divider></el-divider> |
| | | <el-tree |
| | | style="height: 90%;overflow: auto" |
| | |
| | | :data="productList" |
| | | :props="defaultProps" |
| | | default-expand-all |
| | | node-key="id" |
| | | :current-node-key="defaultId" |
| | | :expand-on-click-node="false" |
| | | :highlight-current="true" |
| | | @node-click="handleNodeClick" |
| | |
| | | |
| | | export default { |
| | | name: 'ProductModelTree', |
| | | props: {}, |
| | | props: { |
| | | showXdy: { |
| | | type: Boolean, |
| | | default: true |
| | | }, |
| | | isShow: { |
| | | type: Boolean, |
| | | default: true |
| | | }, |
| | | basic: { |
| | | type: Number, |
| | | default: 1 |
| | | }, |
| | | }, |
| | | |
| | | data() { |
| | | return { |
| | | filterText: '', |
| | | productList: [], |
| | | tree_Hei: document.documentElement.clientHeight - 200, |
| | | defaultId: '', |
| | | defaultProps: { |
| | | children: 'children', |
| | | label: 'name' |
| | | } |
| | | } |
| | | }, |
| | | } |
| | | , |
| | | watch: { |
| | | filterText(val) { |
| | | this.$refs.tree.filter(val) |
| | | } |
| | | }, |
| | | } |
| | | , |
| | | components: { |
| | | AddOrUpdate |
| | | }, |
| | | } |
| | | , |
| | | mounted() { |
| | | this.getProductList() |
| | | }, |
| | | methods: { |
| | | // 获取系统列表 |
| | | async getProductList() { |
| | | let res = await this.$http.get('/basicInfo/XhProductModel/tree') |
| | | let params = { |
| | | showXdy: this.showXdy, |
| | | ztShow: this.basic |
| | | } |
| | | let res = await this.$http.get('/basicInfo/XhProductModel/tree', {params: params}) |
| | | this.productList = res.data |
| | | console.log(res.data,'async getProductList()') |
| | | if (this.basic) { |
| | | if (this.productList && this.productList[0].children) { |
| | | this.defaultId = this.productList[0].children[0].id |
| | | this.$nextTick(() => { |
| | | this.$refs.tree.setCurrentKey(this.defaultId); //一定要加这个选中了否则样式没有出来 |
| | | }); |
| | | this.$emit('on-default', this.defaultId) |
| | | } |
| | | } |
| | | console.log(res.data, 'async getProductList()') |
| | | }, |
| | | add() { |
| | | this.$refs.AddOrUpdate.$refs.dialog.init(null,{id: null, type: 'tree'}) |
| | | this.$refs.AddOrUpdate.$refs.dialog.init(null, {id: null, type: 'xh'}) |
| | | }, |
| | | filterNode(value, data) { |
| | | if (!value) return true |
| | |
| | | }, |
| | | handleNodeClick(data) { |
| | | this.$emit('on-selected', data) |
| | | } |
| | | }, |
| | | } |
| | | } |
| | | </script> |
| | | <style> |
| | | .product-tree-container { |
| | | height: 100%; |
| | | } |
| | | </style> |