123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <template>
- <div class="treeBox">
- <treeComp :treeData="options" @handleClick="handleClick"></treeComp>
- </div>
- </template>
- <script>
- export default {
- props: {
- options: {
- default: {}
- },
- categoryValue: {
- type: Array,
- default: []
- },
- },
- name: 'classMenu',
- data () {
- return {
- checkArr:[],
- checkId:null
- }
- },
- created(){
- this.init()
- },
- mounted(){
- this.checkArr=this.categoryValue
- if(this.categoryValue.length!=0){
- this.checkId=this.categoryValue[(this.categoryValue.length-1)]
- }
- this.checkArr.push('000')
- //this.init()
- },
- methods:{
- init(){
- let that=this
- Vue.component('treeComp', {
- functional: true,
- props: {treeData: Object},
- render(h, {props: {treeData = {}}}) {
- const creatNode = (node,num,pId)=>{
- node.pId=pId
- if(num==1){
- node.parent='000'
- }
- if(node.children && node.children.length > 0){
- let hArr = node.children.map(item=>{
- let nowPid = pId+','+item.pkId
- return creatNode(item,num+1,nowPid)
- })
- if(num==0){
- return h('div', {class:{'demoShow':true}},
- [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(2+num*0.5)+'vw',
- on:{click:function (event){
- event.stopPropagation();
- event.preventDefault();
- that.handleClick(node,this);
- } }},[
- h('div',{class:{'classifyRightAction':that.checkArr.indexOf(node.pkId)>-1,'classifyRight':true},
- on:{click:function (event){
- event.stopPropagation();
- event.preventDefault();
- that.handleOpenClick(node);
- } }},['']),
- node.name]), hArr])
- }else{
- return h('div', {class:{'demo':!(that.checkArr.indexOf(node.parent)>-1),'demoShow':(that.checkArr.indexOf(node.parent)>-1)}}, [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(2+num*0.5)+'vw',
- on:{click:function (event){
- event.stopPropagation();
- event.preventDefault();
- that.handleClick(node,this);
- } }},[
- h('div',{class:{'classifyRightAction':that.checkArr.indexOf(node.pkId)>-1,'classifyRight':true},
- on:{click:function (event){
- event.stopPropagation();
- event.preventDefault();
- that.handleOpenClick(node);
- } }},['']),
- node.name]), hArr])
- }
- }else{
- return h('div', {class:{'demo':!(that.checkArr.indexOf(node.parent)>-1),'demoShow':(that.checkArr.indexOf(node.parent)>-1)}}, [h('div',{class:{'demoText':true,'demoTextSelect':that.checkId==node.pkId},style:'padding-Left:'+(3.2+num*0.5)+'vw',
- on:{click: function(event){
- event.stopPropagation();
- event.preventDefault();
- that.handleClick(node,this);
- }}},[
- node.name])])
- }
- }
- return creatNode(treeData,0,'')
- }
- })
- },
- handleOpenClick(node){
- //console.log(node)
- //node.openData=!node.openData
- let indexNum=this.checkArr.indexOf(node.pkId)
- if(indexNum>-1){
- this.checkArr.splice(indexNum, 1)
- }else{
- this.checkArr.push(node.pkId)
- }
- console.log(this.checkArr)
- },
- handleClick(node,ele){
- console.log(node)
- this.checkId = node.pkId;
- let dataArr=node.pId.split(",")
- dataArr.shift()
-
- let data={
- categoryId:node.pkId,
- categoryName:node.name,
- categoryValue:dataArr
- }
- this.$emit('changeClass',data);
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .demoShow{
- min-width: 11.71875vw;
- width: max-content;
- text-align: left;
- font-size:0.9375vw;
- display: flex;
- flex-direction: column;
- color: #202124;
- &:before{
- content:' ';
- display: inline-block;
- }
- }
- .demo{
- min-width: 11.71875vw;
- width: max-content;
- display: none;
- text-align: left;
- font-size:0.9375vw;
- flex-direction: column;
- color: #202124;
- &:before{
- content:' ';
- display: inline-block;
- }
- }
- .demoText{
- padding-right:2vw;
- font-weight: 500;
- min-width: 11.71875vw;
- height: 2.91vw;
- display: inline-block;
- line-height: 2.91vw;
- cursor: pointer;
- color: #202124;
- }
- .demoTextSelect{
- background: #ECF3FF;
- }
- .classifyRight{
- background: url('../../../../image/rightIcon.png');
- background-size: 100% 100%;
- width:0.6vw;
- height: 0.6vw;
- color: #CBCCCC;
- display: inline-block;
- margin-left: auto;
- transform-origin: 150% 60%;
- margin-right: 0.6vw;
- -moz-user-select:none;/*火狐*/
- -webkit-user-select:none;/*webkit浏览器*/
- -ms-user-select:none;/*IE10*/
- -khtml-user-select:none;/*早期浏览器*/
- user-select:none;
- }
- .classifyRightAction{
- transform: rotate(90deg);
- transform-origin: 75% 50%;
- }
- .treeBox{
- overflow-x: scroll;
- height: calc(100% - 3.5vw);
- }
- .treeBox::-webkit-scrollbar{
- width:16px;
- height:16px;
- background-color:#fff;
- display:block;
- }
- </style>
|