Commit f32ece3b by 蒋勇

d

parent aee8f573
......@@ -4,6 +4,12 @@ class TreearchCtl extends CtlBase {
constructor() {
super("common", CtlBase.getServiceName(TreearchCtl));
}
async getTreeArchByCode(p,q,req){
let code=p.code;
let archName=p.archName;
let rtn=await this.service.getTreeArchByCode(archName,code)
return system.getResult(rtn)
}
async getRegions(p,q,req){
let regionjson=await this.service.getRegions();
return system.getResult({regionJson:regionjson})
......
......@@ -4,29 +4,88 @@ class TreeArchService extends ServiceBase {
constructor() {
super("common", ServiceBase.getDaoName(TreeArchService));
}
async getRegions(){
let rs=await this.dao.model.findAll({attributes:['regionJSON']})
async getRegions() {
let rs = await this.dao.model.findAll({ attributes: ['regionJSON'] })
return JSON.parse(rs[0].regionJSON)
}
async saveRegions(regionJson){
let rs=await this.dao.model.findAll()
let upobj=rs[0]
upobj.regionJSON=JSON.stringify(regionJson)
async saveRegions(regionJson) {
let rs = await this.dao.model.findAll()
let upobj = rs[0]
upobj.regionJSON = JSON.stringify(regionJson)
upobj.save()
return regionJson
}
async getProductcats(){
let rs=await this.dao.model.findAll({attributes:['productcatJSON']})
async getProductcats() {
let rs = await this.dao.model.findAll({ attributes: ['productcatJSON'] })
return JSON.parse(rs[0].productcatJSON)
}
async saveProductcats(productcatJson){
let rs=await this.dao.model.findAll()
let upobj=rs[0]
upobj.productcatJSON=JSON.stringify(productcatJson)
upobj.save()
return productcatJson
}
}
async saveProductcats(productcatJson) {
let rs = await this.dao.model.findAll()
let upobj = rs[0]
upobj.productcatJSON = JSON.stringify(productcatJson)
upobj.save()
return productcatJson
}
// async itetree(jsontree, level, results) {
// jsontree.forEach(item => {
// if (item.level < level) {
// let cloneobj = { ...item }
// if (results) {
// results.push(cloneobj)
// }
// if (item.children) {
// cloneobj.children = []
// itetree(item.children, level, cloneobj.children)
// }
// } else {
// if (results) {
// results.push(cloneobj)
// }
// }
// })
// }
findNodeByCode(jsontree, code, results) {
jsontree.forEach(item => {
if (item.code == code) {
if (item.children) {
item.children.forEach(c => {
let tmp = { ...c }
tmp.loading = false
if (tmp.children) {
tmp.children = []
}
results.push(tmp)
})
//this.findNodeByCode(item.children, code, results)
}
}else{
if(item.children){
this.findNodeByCode(item.children, code, results)
}
}
})
}
async getTreeArchByCode(archName,code) {
let results = []
let rs = await this.dao.model.findAll({ attributes: [archName] })
let jsontree = JSON.parse(rs[0][archName])
this.findNodeByCode(jsontree,code,results)
console.log(results)
return results;
}
/**
* 按照字段和及级别读取树部分节点
* @param {*} archName
* @param {*} level
*/
// async getTreeArchs(archName, level) {
// let results = []
// let rs = await this.dao.model.findAll({ attributes: [archName] })
// let jsontree = JSON.parse(rs[0].[archName])
// await this.itetree(jsontree, level, results)
// console.log(results)
// return results;
// }
}
module.exports = TreeArchService;
// (async ()=>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment