|
@@ -26,13 +26,13 @@ class GoodsTagsService extends CrudService {
|
|
async tree({ pid }) {
|
|
async tree({ pid }) {
|
|
let list = await this.model.find({ status: '0' });
|
|
let list = await this.model.find({ status: '0' });
|
|
list = JSON.parse(JSON.stringify(list));
|
|
list = JSON.parse(JSON.stringify(list));
|
|
- list = list.map(i => _.omit(i, [ 'meta', '__v' ]));
|
|
|
|
- const level1 = list.filter(f => (pid ? f.id === pid : !f.pid));
|
|
|
|
|
|
+ list = list.map((i) => _.omit(i, ['meta', '__v']));
|
|
|
|
+ const level1 = list.filter((f) => (pid ? f.id === pid : !f.pid));
|
|
const loop = (list, parents) => {
|
|
const loop = (list, parents) => {
|
|
for (const p of parents) {
|
|
for (const p of parents) {
|
|
const pid = _.get(p, '_id');
|
|
const pid = _.get(p, '_id');
|
|
if (!pid) continue;
|
|
if (!pid) continue;
|
|
- const children = list.filter(f => ObjectId(pid).equals(f.pid));
|
|
|
|
|
|
+ const children = list.filter((f) => ObjectId(pid).equals(f.pid));
|
|
if (children.length <= 0) continue;
|
|
if (children.length <= 0) continue;
|
|
const newChildren = loop(list, children);
|
|
const newChildren = loop(list, children);
|
|
p.children = newChildren;
|
|
p.children = newChildren;
|
|
@@ -42,6 +42,11 @@ class GoodsTagsService extends CrudService {
|
|
const tree = loop(list, level1);
|
|
const tree = loop(list, level1);
|
|
return tree;
|
|
return tree;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async getData({ code }) {
|
|
|
|
+ const data = await this.model.findOne({ code });
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = GoodsTagsService;
|
|
module.exports = GoodsTagsService;
|