diff --git a/src/pages/data/list/index.vue b/src/pages/data/list/index.vue index 098782b..9e3a123 100644 --- a/src/pages/data/list/index.vue +++ b/src/pages/data/list/index.vue @@ -194,11 +194,10 @@ export default { } }, methods: { - getType(id = 0) { + getType() { // 获取分类 - this.$post(`${this.api.getLevel}?parentId=${id}`).then(res => { - const list = res.list - let typeId = this.typeId // 取得首页传过来的id + this.$post(this.api.getTableByClassification).then(res => { + let typeId = this.typeId // 取得传值的id let introduce = ''// 对应股票的介绍,规则为无children则取上级 let dataSource = '' // 数据来源,同上 let action @@ -217,25 +216,20 @@ export default { if (i) isFirst = false if (typeId && e.id == typeId) {// 若id匹配 action = String(e.id) - if (e.children && e.children.length) {// 若有下级 + if (e.children.length) {// 若有下级 if (!e.children[0].children.length) {// 找到下级的下级若无子级,则赋值勾选 action = String(e.children[0].id) } else {// 直接赋值 action = String(e.children[0].children[0].id) } } - } else if (e.children && e.children.length) { // id不匹配,递归找 + } else if (e.children.length) { // id不匹配,递归找 actionId(e.children) } }) } - if (id) { - this.typeList[0].children = list - } else { - this.typeList = list - } - console.log(11, this.typeList) - actionId(list) + this.typeList = res + actionId(res) this.defaultType = action this.introduce = introduce this.dataSource = dataSource @@ -281,45 +275,44 @@ export default { let introduce = '' let dataSource = '' this.keyword = '' - this.getType(index) - // let list = this.typeList - // let select = '' - // // 获取最里层的第一个子级id - // function getDeepest(data) { - // if (data[0].children && data[0].children.length) { - // getDeepest(data[0].children) - // } else { - // select = data[0].id - // if (data[0].introduce) introduce = data[0].introduce - // if (data[0].dataSource) dataSource = data[0].dataSource - // } - // } - // function handleData(data) { - // data.map((n, i) => { - // // 匹配到点击的分类,默认展开子级第一个分类 - // if (n.id == index) { - // // 如果有子级,则递归取到最下面的第一级子级id,如果没有子级,则取当前id - // if (n.children.length) { - // getDeepest(n.children) - // } else { - // select = index - // if (n.introduce) introduce = n.introduce - // if (n.dataSource) dataSource = n.dataSource - // } - // } else { - // handleData(n.children) - // } - // }) - // } - // handleData(list) - // if (!introduce) introduce = list.find(n => n.id == indexPath[0]).introduce - // if (!dataSource) dataSource = list.find(n => n.id == indexPath[0]).dataSource - // this.defaultType = select - // this.introduce = introduce - // this.dataSource = dataSource - // this.previewHead = [] - // this.previewData = [] - // this.initData() + let list = this.typeList + let select = '' + // 获取最里层的第一个子级id + function getDeepest(data) { + if (data[0].children && data[0].children.length) { + getDeepest(data[0].children) + } else { + select = data[0].id + if (data[0].introduce) introduce = data[0].introduce + if (data[0].dataSource) dataSource = data[0].dataSource + } + } + function handleData(data) { + data.map((n, i) => { + // 匹配到点击的分类,默认展开子级第一个分类 + if (n.id == index) { + // 如果有子级,则递归取到最下面的第一级子级id,如果没有子级,则取当前id + if (n.children.length) { + getDeepest(n.children) + } else { + select = index + if (n.introduce) introduce = n.introduce + if (n.dataSource) dataSource = n.dataSource + } + } else { + handleData(n.children) + } + }) + } + handleData(list) + if (!introduce) introduce = list.find(n => n.id == indexPath[0]).introduce + if (!dataSource) dataSource = list.find(n => n.id == indexPath[0]).dataSource + this.defaultType = select + this.introduce = introduce + this.dataSource = dataSource + this.previewHead = [] + this.previewData = [] + this.initData() }, previewCurrentChange(val) { this.currentRow = val