|
@@ -30,4 +30,35 @@ export class RegionService extends BaseServiceV2 {
|
|
|
}
|
|
|
return { data, total };
|
|
|
}
|
|
|
+
|
|
|
+ // 地区列表
|
|
|
+ async area(query) {
|
|
|
+ const { skip = 0, limit = 0, level, code } = pick(query, ['skip', 'limit', 'level', 'code']);
|
|
|
+ const whereObject: any = { level, code };
|
|
|
+ const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
|
|
|
+ const data = await builder.getMany();
|
|
|
+ const total = await builder.getCount();
|
|
|
+ for (const val of data) {
|
|
|
+ if (get(val, 'code')) {
|
|
|
+ let level = get(val, 'level');
|
|
|
+ if (get(val, 'level') === 'province') level = 'city';
|
|
|
+ else if (get(val, 'level') === 'city') level = 'area';
|
|
|
+ else if (get(val, 'level') === 'area') level = 'street';
|
|
|
+ // 查询下一级
|
|
|
+ if (level === 'city') {
|
|
|
+ const cityList = await this.model.find({ where: { parent_code: Equal(val.code), level: Equal(level) } });
|
|
|
+ if (cityList && cityList.length > 0) {
|
|
|
+ for (const item of cityList) {
|
|
|
+ const areaList = await this.model.find({ where: { parent_code: Equal(item.code), level: Equal('area') } });
|
|
|
+ if (areaList && areaList.length > 0) {
|
|
|
+ Object.assign(item, { children: areaList });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Object.assign(val, { children: cityList });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
}
|