address-client
Version:
地址管理前台组件
251 lines (218 loc) • 7.6 kB
JavaScript
import {SearchList, date} from 'vue-client'
import {HttpResetClass,trans} from 'vue-client'
export default class Comp {
//http请求类
http = new HttpResetClass()
// 小区信息
community = new SearchList()
// 小区内的所有楼栋
tower = new SearchList()
towerInfo = {}
//判断在哪个显示层级
isShowCom = true
//列表提示信息
selectCommunityInfo = '请选择小区'
//用来存放list的存放
listInfo = []
//省
province
//区
district
//街道
street
//选中的小区
selectCom = {}
selectShow=''
loginInfo = {}
async ready() {
// this.loginInfo = await this.http.load('POST', `/rs/user/userLogin/客服系统`,
// "Xm3zKZYIkKr+AuudraJjmUVWlyuwnUI1mWUS4JFPvjmyZ9MMUI5qXxEik5EBmUPTcwtCiNDWkR7DKFOvpyIcbbGdywtsb/AG/LbCvgwldGmOtmLVracaRQiWScYM79BfvjlGNYkd1VOBBiRF4LNiK6X/u0SBQaLYwU3kUbQUN3I=",
// {resolveMsg: null, rejectMsg: null})
this.loginInfo ={'orgid':453}
this.setProperty('community','id',this.loginInfo.orgid)
this.setProperty('community','tower',this.loginInfo.orgid)
await this.searchCommunity(()=>{})
this.comInsertToListInfo()
}
async searchCommunity(f){
this.selectCommunityInfo = '请选择小区'
this.isShowCom =true
await this.community.searchList('/rs/sql/address_getarealist',{
'id':" 1=1 and s.f_filialeid = '{}'",
'name':" s.f_residential_area like '%{}%' ",
'street' :" s.f_street like '%{}%'"
},{})
this.comInsertToListInfo()
this.selectShow =''
f()
}
async searchTower(f){
await this.tower.searchList('/rs/sql/address_getAddress',{
'id':" 1=1 and a.f_filialeid = '{}'",
'com':" a.f_residential_area_id = {} "
},{})
while(this.tower.list.loadMoreState){
await this.tower.list.loadMore()
}
f()
}
//返回小区列表
listBack(f){
if(this.isShowCom){
console.log('小区列表无法返回')
return
}else {
this.comInsertToListInfo()
this.isShowCom =true
this.selectCommunityInfo = '请选择小区'
this.selectCom = {}
this.selectShow = ''
}
f()
}
async checkCom(Com, f) {
//加载小区内的楼栋情况
if(this.isShowCom){
console.log('in 小区')
this.selectCom = Com
this.isShowCom =false
this.province = Com.province
this.district = Com.district
this.street = Com.street
this.selectCommunityInfo = Com.name
this.setProperty('tower','com',Com.id)
this.listInfo=[]
f()
//调用查询
await this.searchTower(()=>{})
//调用数组的格式转化
this.towerInsertToListInfo()
}
//加载楼栋信息
else {
console.log('in 楼栋')
let s = await this.http.load('POST','/rs/sql/address_getAddress',{'data':{"condition": ` 1=1 and a.f_filialeid = '${this.loginInfo.orgid}' and a.f_residential_area_id = '${this.selectCom.id}' and a.f_building = '${Com.id}'`}}, {resolveMsg: null, rejectMsg: null})
// this.towerInfo.data.sort(function(a,b){
// if(a.f_unit === b.f_unit){
// return a.f_floor - b.f_floor;
// }
// return a.f_unit - b.f_unit;
// });
console.log('====>',s)
s.data.sort(function(a,b){
if(a.f_unit === b.f_unit){
if(a.f_floor === b.f_floor){
return a.f_room - b.f_room;
}
return a.f_floor - b.f_floor;
}
return a.f_unit - b.f_unit;
});
// console.log('in -->',this.towerInfo)
this.selectShow = Com.street+this.selectCommunityInfo+Com.name
// this.translate(this.towerInfo)
this.translate(s)
}
f()
}
//格式化小区数据
comInsertToListInfo(){
this.listInfo = []
this.community.list.data.forEach((row)=>{
this.listInfo.push({'id':row.id,"name":row.f_residential_area ,'province':row.f_province,'district':row.f_district,'street':row.f_street})
})
}
//格式化楼栋数据
towerInsertToListInfo(){
this.listInfo = []
let build =[]
this.tower.list.data.forEach((row)=>{
if(build.indexOf(row.f_building) === -1){
build.push(row.f_building)
}
})
build.forEach((row)=>{
this.listInfo.push({'id':row,"name":row+'栋' ,'province':this.province,'district':this.district,'street':this.street})
})
}
//设置搜索属性
setProperty(modulename, property, value) {
console.log(modulename+"新添--"+property+"--"+value)
this[modulename].search.setField(property, value)
}
//加载更多数据
async loadMore(modelname,f) {
if(this.isShowCom){
console.log('in community')
await this.community.list.loadMore()
this.comInsertToListInfo()
}
else{
console.log('in tower')
await this.tower.list.loadMore()
this.towerInsertToListInfo()
}
f()
}
translate(json) {
console.log('in tran')
let result = {};
//存储辅助变量
let auxiliary = {};
//遍历得到的数据
json.data.forEach(function (element) {
//拼接楼层
let unit = element.f_unit + element.f_unit_suffix;
//楼层数
let floor = element.f_floor;
//楼层名
let floorname = element.f_floor + element.f_floor_suffix;
//立管
let pipe = element.f_vertical_pipe ===null? ' ':element.f_vertical_pipe;
//单户房间
let room = {
id: element.f_room + element.f_room_suffix,
pipe: pipe,
username : element.f_user_name === null ? ' ' : element.f_user_name,
userinfo : element.f_user_name === null ? '无用户' : element.f_user_phone,
state: element.f_user_name === null ? ' ' : element.f_address_state+''
};
let info = '测试展示信息'
//若没有该户对应的单元,创建一个单元
if (!result[unit]) {
result[unit] = {upGround: [], underGround: [], pipes: {}};
auxiliary[unit] = {tiers: {},pipes:{}}
};
//若单元内没有该户对应的楼层,创建楼层,并将该户添加到楼层中
// if (!auxiliary[unit].tiers[floorname] && auxiliary[unit].tiers[floorname] !== 0) {
if (typeof (auxiliary[unit].tiers[floorname]) === 'undefined') {
if (floor > 0) {
auxiliary[unit].tiers[floorname] = result[unit].upGround.length;
result[unit].upGround.push([room]);
} else {
auxiliary[unit].tiers[floorname] = result[unit].underGround.length;
result[unit].underGround.push([room]);
}
} else {
if (floor > 0) {
result[unit].upGround[auxiliary[unit].tiers[floorname]].push(room)
} else {
result[unit].underGround[auxiliary[unit].tiers[floorname]].push(room)
}
};
if (!result[unit].pipes[pipe]) {
auxiliary[unit].pipes[pipe] = {floorname: 1}
result [unit].pipes[pipe] = 1
} else if (!auxiliary[unit].pipes[pipe][floorname]) {
auxiliary[unit].pipes[pipe][floorname] = 1
} else {
auxiliary[unit].pipes[pipe][floorname]++;
if (auxiliary[unit].pipes[pipe][floorname] > result[unit].pipes[pipe]) {
result[unit].pipes[pipe] = auxiliary[unit].pipes[pipe][floorname]
}
}
})
console.log('结果是-',result)
this.towerInfo = result
}
}