|
|
@@ -3,18 +3,24 @@ |
|
|
|
<view class="tki-tree-mask" :class="{'show':showTree}" @tap="_cancel"></view> |
|
|
|
<view class="tki-tree-cnt" :class="{'show':showTree}"> |
|
|
|
<view class="tki-tree-bar"> |
|
|
|
<view class="tki-tree-bar-cancel" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_cancel">取消</view> |
|
|
|
<view class="tki-tree-bar-cancel" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_cancel">取消 |
|
|
|
</view> |
|
|
|
<view class="tki-tree-bar-title" :style="{'color':titleColor}">{{title}}</view> |
|
|
|
<view class="tki-tree-bar-confirm" :style="{'color':confirmColor}" hover-class="hover-c" @tap="_confirm">确定</view> |
|
|
|
<view class="tki-tree-bar-confirm" :style="{'color':confirmColor}" hover-class="hover-c" |
|
|
|
@tap="_confirm">确定</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<view class="tki-tree-view"> |
|
|
|
<!-- <view style=""> |
|
|
|
<u-search height="90rpx" @change="searChange(searchText,treeList)" :inputStyle="{fontSize:'30rpx'}" |
|
|
|
v-model="searchText" placeholder="请输入" shape="square" :showAction="false"></u-search> |
|
|
|
</view> --> |
|
|
|
<scroll-view class="tki-tree-view-sc" :scroll-y="true"> |
|
|
|
<block v-for="(item, index) in treeList" :key="index"> |
|
|
|
<view class="tki-tree-item" :style="[{ |
|
|
|
paddingLeft: item.rank*15 + 'px', |
|
|
|
zIndex: item.rank*-1 +50 |
|
|
|
}]" |
|
|
|
:class="{ |
|
|
|
}]" :class="{ |
|
|
|
border: border === true, |
|
|
|
show: item.show, |
|
|
|
last: item.lastRank, |
|
|
@@ -22,14 +28,21 @@ |
|
|
|
open: item.open, |
|
|
|
}"> |
|
|
|
<view class="tki-tree-label" @tap.stop="_treeItemTap(item, index)"> |
|
|
|
<image class="tki-tree-icon" :src="item.lastRank ? lastIcon : item.showChild ? currentIcon : defaultIcon"></image> |
|
|
|
<image class="tki-tree-icon" |
|
|
|
:src="item.lastRank ? lastIcon : item.showChild ? currentIcon : defaultIcon"> |
|
|
|
</image> |
|
|
|
{{item.name}} |
|
|
|
</view> |
|
|
|
<view class="tki-tree-check" @tap.stop="_treeItemSelect(item, index)" v-if="selectParent?true:item.lastRank"> |
|
|
|
<view class="tki-tree-check-yes" v-if="item.checked" :class="{'radio':!multiple}" :style="{'border-color':confirmColor}"> |
|
|
|
<view class="tki-tree-check-yes-b" :style="{'background-color':confirmColor}"><u-icon name="checkbox-mark" color="#ffffff" size="16"></u-icon></view> |
|
|
|
<view class="tki-tree-check" @tap.stop="_treeItemSelect(item, index)" |
|
|
|
v-if="selectParent?true:item.lastRank"> |
|
|
|
<view class="tki-tree-check-yes" v-if="item.checked" :class="{'radio':!multiple}" |
|
|
|
:style="{'border-color':confirmColor}"> |
|
|
|
<view class="tki-tree-check-yes-b" :style="{'background-color':confirmColor}"> |
|
|
|
<u-icon name="checkbox-mark" color="#ffffff" size="16"></u-icon> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="tki-tree-check-no" v-else :class="{'radio':!multiple}" :style="{'border-color':confirmColor}"></view> |
|
|
|
<view class="tki-tree-check-no" v-else :class="{'radio':!multiple}" |
|
|
|
:style="{'border-color':confirmColor}"></view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</block> |
|
|
@@ -108,10 +121,12 @@ |
|
|
|
showTree: false, |
|
|
|
treeList: [], |
|
|
|
selectIndex: -1, |
|
|
|
searchText: '' |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: {}, |
|
|
|
methods: { |
|
|
|
|
|
|
|
_show() { |
|
|
|
this.showTree = true |
|
|
|
}, |
|
|
@@ -268,13 +283,39 @@ |
|
|
|
this.treeList[i].checked = v.orChecked |
|
|
|
}) |
|
|
|
}, |
|
|
|
_initTree(range = this.range){ |
|
|
|
_initTree(range = this.range) { |
|
|
|
this.treeList = []; |
|
|
|
this._renderTreeList(range); |
|
|
|
this.$nextTick(() => { |
|
|
|
this._defaultSelect(range) |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
// searChange(value, data) { |
|
|
|
// // this.treeList = this.filterTree(value, data) |
|
|
|
// }, |
|
|
|
filterTree(val, tree, newArr = []) { |
|
|
|
if (!(tree.length && val)) { // 如果搜索关键字为空直接返回源数据 |
|
|
|
return tree |
|
|
|
} |
|
|
|
for (let item of tree) { |
|
|
|
if (item.name.indexOf(val) > -1) { // 匹配到关键字的逻辑 |
|
|
|
newArr.push(item) // 如果匹配到就在数值中添加记录 |
|
|
|
continue // 匹配到了就退出循环了此时如果有子集也会一并带着 |
|
|
|
} |
|
|
|
|
|
|
|
if (item.children && item.children.length) { // 如果父级节点没有匹配到就看看是否有子集,然后做递归 |
|
|
|
let subArr = this.filterTree(val, item.children) // 缓存递归后的子集数组 |
|
|
|
if (subArr && subArr.length) { // 如果子集数据有匹配到的节点 |
|
|
|
let node = { |
|
|
|
...item, |
|
|
|
children: subArr |
|
|
|
} // 关键逻辑,缓存父节点同时将递归后的子节点作为新值 |
|
|
|
newArr.push(node) // 添加进数组 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return newArr |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
range(list) { |
|
|
@@ -290,6 +331,19 @@ |
|
|
|
this._reTreeList(); |
|
|
|
} |
|
|
|
}, |
|
|
|
// searchText: { |
|
|
|
// handler(newValue, oldValue) { |
|
|
|
// console.log(111) |
|
|
|
// console.log(this.treeList,11) |
|
|
|
// console.log(this.range,11) |
|
|
|
// // let arr = JSON.parse(JSON.stringify(this.treeList)) |
|
|
|
// this.filterTrees = this.filterTree(newValue, this.range) |
|
|
|
// console.log(this.range,22) |
|
|
|
// console.log(this.treeList,22) |
|
|
|
// }, |
|
|
|
// deep: true |
|
|
|
|
|
|
|
// } |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this._initTree(); |
|
|
@@ -299,4 +353,4 @@ |
|
|
|
|
|
|
|
<style scoped> |
|
|
|
@import "./style.css"; |
|
|
|
</style> |
|
|
|
</style> |