Files
youfang-app/fangija-zsyf/js/district/districtDetail.js
T
2018-07-05 13:19:24 +08:00

905 lines
22 KiB
JavaScript

var colorList = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
var labelFont = 'bold 12px Sans-serif';
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var dates;
var data;
var volumes;
var curOption;
var mapLoadCount = 0;
/* 关注&已关注切换 */
function doAddCollect(){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
if(plus.webview.getWebviewById('views/house/houseDetail.html')!= null) {
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
}
if(plus.webview.getWebviewById('views/house/houseManageList.html') != null) {
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
doAddCollect();
})
return;
} else {
addCollect();
}
}
function addCollect(){
axios.post("/rest/districts/addCollect",{city:city,region:region,name:name,lat:lat,lng:lng,address:address, poiTags:tags}).then(function (response) {
var msg = response.data.message
if(msg){
$.toast(msg);
}else{
$(".collection01").hide();
$(".collection02").show();
$.toast("随时掌握小区动态");
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
}
})
.catch(function (error) {
console.log(error);
});
}
$(".collection02").on("click", function () {
removeCollect();
});
function doRemoveCollect(){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
doRemoveCollect();
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
})
return;
} else {
removeCollect();
}
}
function removeCollect(){
axios.post("/rest/districts/removeCollect",{city:city,region:region,name:name}).then(function (response) {
var msg = response.data.message
if(msg){
$.toast(msg);
}else{
$(".collection02").hide();
$(".collection01").show();
$.toast("取消关注");
}
if(plus.webview.getWebviewById('views/house/houseManageList.html') != null) {
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
plus.webview.getWebviewById('yfindex.html').reload();
})
.catch(function (error) {
console.log(error);
});
}
//图表 初始化
function inintChart(){
var type = $("#trendDiv1 a.active").attr("t-v");
/* 小区均价分析 */
loadLineData(city, region, name, type)
/* 小区租金走势 */
loadRentTrends(city, region, name,2);
}
function clickLineChart(type){
if(mode == "kLine"){
loadKLineData(city, region, name, type)
}else if(mode == "line"){
loadLineData(city, region, name, type);
}
}
/* 图表切换 */
/*function lineChart() {
mode = "kLine"
$(".icon-chart01a").hide();
$(".icon-chart01").show();
//$("#chart01a").css("z-index","-1");
//$("#chart01").css("z-index","1");
var type = $("#trendDiv1 a.active").attr("t-v");
$("#chart01a").hide();
$("#chart01").show();
loadKLineData(city, region, name, type);
}
function kLineChart() {
mode = "line"
$(".icon-chart01").hide();
$(".icon-chart01a").show();
//$("#chart01").css("z-index","-1");
//$("#chart01a").css("z-index","1");
var type = $("#trendDiv1 a.active").attr("t-v");
$("#chart01a").show();
$("#chart01").hide();
loadLineData(city, region, name, type);
};*/
$("body").delegate(".icon-chart01a-no", "click", function () {
$(this).addClass("icon-chart01a");
$(this).removeClass("icon-chart01a-no");
$(this).parent().find(".icon-chart01").addClass("icon-chart01-no")
$(this).parent().find("i").removeClass("icon-chart01")
mode = "line"
var type = $("#trendDiv1 a.active").attr("t-v");
$("#chart01a").show();
$("#chart01").hide();
loadLineData(city, region, name, type);
})
$("body").delegate(".icon-chart01-no", "click", function () {
$(this).addClass("icon-chart01");
$(this).removeClass("icon-chart01-no");
$(this).parent().find(".icon-chart01a").addClass("icon-chart01a-no")
$(this).parent().find("i").removeClass("icon-chart01a")
mode = "kLine"
var type = $("#trendDiv1 a.active").attr("t-v");
$("#chart01a").hide();
$("#chart01").show();
loadKLineData(city, region, name, type);
})
function showLoadRentTrends(type) {
if(type == 3) {
document.getElementById("trendDivTab3").setAttribute("class","tab-link button active");
document.getElementById("trendDivTab2").setAttribute("class","tab-link button");
} else {
document.getElementById("trendDivTab3").setAttribute("class","tab-link button");
document.getElementById("trendDivTab2").setAttribute("class","tab-link button active");
}
loadRentTrends(city, region, name,type);
}
function loadKLineData(city, region, name, type){
if(type == "36"){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
if(localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == ""){
}else{
$("#trendDiv1 a").removeClass("active")
$("a[t-v='36']").addClass("active")
doLoadKLineData(city, region, name, type)
plus.webview.getWebviewById('views/user/userInfo.html').reload();
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
})
return;
} else {
$("#trendDiv1 a").removeClass("active")
$("a[t-v='36']").addClass("active")
doLoadKLineData(city, region, name, type)
}
}else{
$("#trendDiv1 a").removeClass("active")
if(type == 12){
$("a[t-v='12']").addClass("active")
}else{
$("a[t-v='6']").addClass("active")
}
doLoadKLineData(city, region, name, type)
}
}
function doLoadKLineData(city, region, name, type){
axios.get("/rest/trend/kData", {
params: {
city: city,
region:region,
name:name,
type: type
}
}).then(function (response) {
var datas = response.data.data
if(datas){
var trends = [];
var counts = [];
var times = []
var haveCount = false;
var curMonth;
if(month<10){
curMonth = year+"-0"+month;
}else{
curMonth = year+"-"+month;
}
for(var d in datas){
if(d == curMonth){
continue;
}
times.push(d);
var prices = new Array();
for(var m in datas[d]){
prices.push(datas[d][m]);
}
trends.push(prices);
if(haveCount==false && datas[d][4]){
haveCount = true;
}
counts.push(datas[d][4]);
}
option01.xAxis[0].data = times
option01.xAxis[1].data = times
//option01.series[0].data = counts
option01.series[0].data = trends
curOption = option01;
var myChart01 = echarts.init(document.getElementById('chart01'));
myChart01.setOption(option01,true);
}
}).catch(function (error) {
console.log(error);
});
}
function showTrends(v){
if(v == "36"){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
showTrends(v);
if(plus.webview.getWebviewById('views/house/houseDetail.html')!= null) {
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
}
if(plus.webview.getWebviewById('views/house/houseManageList.html') != null) {
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
if(plus.webview.getWebviewById('views/user/userInfo.html')!= null){
plus.webview.getWebviewById('views/user/userInfo.html').reload();
}
})
return;
} else {
$("#trendDiv1 a").removeClass("active")
$("a[t-v='36']").addClass("active")
//curOption.dataZoom[0].start = 0
loadKLineData(city, region, name)
}
}else{
$("#trendDiv1 a").removeClass("active")
//myChart01.setOption(curOption,true);
if(v == 12){
$("a[t-v='12']").addClass("active")
}else{
$("a[t-v='6']").addClass("active")
}
loadKLineData(city, region, name)
}
}
var option01 = {
color: colorList,
title: {
text: null,
left: 'center'
},
legend: {
show: false,
top: 30,
data: ['均价']
},
tooltip: {
bordeRadius: 4,
borderWidth: 1,
borderColor: '#333',
backgroundColor: 'rgba(255,255,255,0.9)',
textStyle: {
fontSize: 12,
color: '#333'
},
formatter: function (params) {
var res = params.seriesName + ' ' + params.name;
var vals = params.value;
if(vals == undefined){
var obj = params[0];
res = obj.seriesName + ' ' + obj.name;
vals = obj.value;
}
if(vals){
res += '<br/> 月初 : ' + vals[1]+ '元/㎡';
res += '<br/> 月末 : ' + vals[2]+ '元/㎡';
res += '<br/> 最低 : ' + vals[3]+ '元/㎡';
res += '<br/> 最高 : ' + vals[4]+ '元/㎡';
return res;
}
}
},
axisPointer: {
link: [{
xAxisIndex: [0, 1]
}]
},
dataZoom: [{
type: 'inside',
xAxisIndex: [0, 1],
start: 1,
end: 99,
top: 30,
height: 20
}],
xAxis: [{
type: 'category',
data: dates,
boundaryGap : false,
axisLine: { lineStyle: { color: '#666' } },
axisLabel: {
formatter: function (value) {
return echarts.format.formatTime('yyyy-MM', value);
}
},
min: 'dataMin',
max: 'dataMax',
axisPointer: {
show: true
}
}, {
type: 'category',
gridIndex: 1,
data: dates,
scale: false,
boundaryGap : false,
splitLine: {show: false},
axisLabel: {show: false},
axisTick: {show: false},
axisLine: {lineStyle: { color: '#fff' } },
splitNumber: 20,
min: 'dataMin',
max: 'dataMax',
axisPointer: {
type: 'line',
lineStyle: {
color: '#fff',
width: 1,
type: 'solid'
},
label: {show: false},
triggerTooltip: true,
handle: {
show: true,
margin: -90,
color: '#F18D00'
}
}
}],
yAxis: [{
name: '均价(元/㎡)',
nameRotate: 90,
nameLocation: 'center',
nameGap: 5,
position: 'right',
nameTextStyle: {
color: '#999'
},
scale: true,
splitNumber: 2,
axisLine: { lineStyle: { color: '#999' } },
splitLine: { show: true },
axisTick: { show: false },
axisLabel: {
inside: true,
formatter: '{value}\n'
}
}, {
name: '',
nameRotate: 90,
nameLocation: 'center',
nameGap: 5,
position: 'right',
nameTextStyle: {
color: '#999'
},
scale: true,
gridIndex: 1,
splitNumber: 2,
axisLabel: {show: false},
axisLine: {show: false},
axisTick: {show: false},
splitLine: {show: false}
}],
grid: [{
left: 20,
right: 20,
top: 30,
height: 120
}, {
left: 20,
right: 20,
height: 40,
top: 260
}],
graphic: [{
type: 'group',
left: 'center',
top: 70,
width: 300,
bounding: 'raw'
}],
series: [/*{
name: '成交量',
type: 'bar',
xAxisIndex: 1,
yAxisIndex: 1,
itemStyle: {
normal: {
color: '#87cefa'
},
emphasis: {
color: 'black'
}
},
data: volumes
}, */{
type: 'candlestick',
name: '均价',
data: data,
itemStyle: {
normal: {
color: '#EB5F34',
color0: '#88D053',
borderColor: '#EB5F34',
borderColor0: '#88D053'
},
emphasis: {
color: '#F18D00',
color0: '#666',
borderColor: '#F18D00',
borderColor0: '#666'
}
}
}]
};
/* 小区租金走势 */
function loadRentTrends(city, region, name, type){
if(type == undefined) type= 2;
axios.get("/rest/trend/distRentTrends", {
params: {
city: city,
region:region,
name:name,
type:type
}
}).then(function (response) {
var re = response.data.data
var categories = new Array();
var series = new Array();
var m = re.times;
var pm = re.distMap
var rooms = re.rooms;
var estateType = re.estateType
var roomKeys = []
if(m && rooms.length>0){
for(var i=0;i<m.length;i++){
categories.push(m[i]);
}
for(var k in rooms){
var room = rooms[k]
roomKeys.push(room + "室");
if(estateType && estateType.indexOf("别墅")>-1){
if(room > 8){
continue;
}
}else{
if(room > 5){
continue;
}
}
var distM = pm[room];
var distObj = new Object();
var distDatas = new Array();
for(var i=0;i<m.length;i++){
if(distM[m[i]] == undefined){
distDatas.push(null);
} else {
distDatas.push(distM[m[i]]);
}
}
distObj.name = room+"室"
distObj.data = distDatas;
distObj.type = 'line';
distObj.symbolSize = 6;
distObj.symbol = 'circle';
series.push(distObj);
}
showRentChart2(categories, series, roomKeys);
}else{
//没数据
//$("#tabChart2").hide();
$("#trendDiv2").parent().parent().addClass("dn")
$("#chart02").addClass("dn")
$("#rentTrendDiv").addClass("dn")
}
}).catch(function (error) {
console.log(error);
});
}
function showRentChart2(categories, series, roomDatas){
var option03 = {
tooltip: {
trigger: 'axis',
textStyle: {
fontFamily: 'arial,华文细黑',
fontSize: 12
},
formatter: function (params) {
if(params && params.length>0){
var s = "";
for(var i in params){
var ob = params[i]
if(i == 0){
s += ob.name+"<br/>";
}
if(ob.value){
s += ob.seriesName+ ": "+ ob.value + '元/月<br/>';
}
}
if(s){
return s;
}
}
}
},
grid:{
x: 54,
y: 10,
x2: 16,
y2: 60,
borderWidth: 1
},
color: ['#F88C9F', '#FFBF5C', '#AAD672', '#78CDE6', '#AE94E9'],
legend: {
data: roomDatas,
y: 'bottom',
textStyle: {
fontFamily: '华文细黑',
fontWeight: 'bold'
},
itemWidth: 16,
itemHeight: 8
},
xAxis: {
type: 'category',
boundaryGap: false,
axisLine: {
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
textStyle: {
fontFamily: 'arial',
color: '#666'
}
},
data: categories,
},
yAxis: {
type: 'value',
scale: true,
axisLine: {
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
textStyle: {
fontFamily: 'arial',
color: '#666'
}
}
},
series:series
};
var myChart02 = echarts.init(document.getElementById('chart02'));
myChart02.setOption(option03,true);
}
/* 小区评级 */
function loadDistrictLevel(datas){
var option03 = {
tooltip: {
trigger: 'axis',
formatter: '{d} : {c}'
},
calculable: true,
radar: [
{
indicator: [
{text: '楼盘潜力评级', max: 100},
{text: '板块评级', max: 100},
{text: '教育评级', max: 100},
{text: '生活便利评级', max: 100},
],
radius: 70,
name: {
textStyle: {
color: '#333'
}
},
splitArea: {
areaStyle: {
color: ['rgba(136,208,83,0.20)',
'rgba(255,255,255,1)', 'rgba(136,208,83,0.20)',
'rgba(255,255,255,1)', 'rgba(136,208,83,0.20)'],
shadowColor: 'rgba(136,208,83,0.20)',
shadowBlur: 10
}
},
axisLine: {
lineStyle: {
color: 'rgba(136,208,83,0.50)'
}
},
splitLine: {
lineStyle: {
color: 'rgba(136,208,83,0.25)'
}
}
}
],
series: [
{
name: '',
type: 'radar',
itemStyle: {
normal: {
areaStyle: {
type: 'default'
},
color: 'rgba(136,208,83,0.9)'
}
},
data: [
{
name: '',
value: datas
}
]
}
]
};
var myChart03 = echarts.init(document.getElementById('chart03'));
myChart03.setOption(option03,true);
}
//曲线图
function loadLineData(city, region, name, type){
//var type = $("#trendDiv1 a.active").attr("t-v");
if(type == "36"){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
if(localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == ""){
}else{
$("#trendDiv1 a").removeClass("active")
$("a[t-v='36']").addClass("active")
doLoadLineData(city, region, name, type)
plus.webview.getWebviewById('views/user/userInfo.html').reload();
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
plus.webview.getWebviewById('views/house/houseManageList.html').reload();
}
})
return;
} else {
$("#trendDiv1 a").removeClass("active")
$("a[t-v='36']").addClass("active")
doLoadLineData(city, region, name, type)
}
}else{
$("#trendDiv1 a").removeClass("active")
if(type == 12){
$("a[t-v='12']").addClass("active")
}else{
$("a[t-v='6']").addClass("active")
}
doLoadLineData(city, region, name, type)
}
}
function doLoadLineData(city, region, name, type){
axios.get("/rest/trend/distTrends", {
params: {
city: city,
region:region,
name:name,
type: type
}
}).then(function (response) {
var distDatas = response.data.data.districtAvgZouShi
var times = response.data.data.timeKeys
if(times){
var districtTrends = [];
for(var d in times){
var t = times[d]
var distPrice = distDatas[t]
if(distPrice){
districtTrends.push(distPrice);
}else{
districtTrends.push(null);
}
}
//option01b.xAxis.data = times
//option01b.series.data = districtTrends
showLineChart(times, districtTrends);
}
}).catch(function (error) {
console.log(error);
});
}
function showLineChart(times, datas){
var option01b = {
tooltip: {
//triggerOn: 'none',
transitionDuration: 0,
confine: true,
bordeRadius: 4,
borderWidth: 1,
borderColor: '#666',
backgroundColor: 'rgba(255,255,255,0.9)',
textStyle: {
fontSize: 12,
color: '#666'
},
formatter: function (params) {
var res = params[0].name + ' <br/>' + "均价:"+(typeof(params[0].value)=="undefined"?"暂无":(params[0].value+ '元/㎡')) ;
return res;
},
position: function (pos, params, el, elRect, size) {
var obj = {
top: 60
};
obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
return obj;
}
},
grid:{
x: 20,
y: 10,
x2: 20,
y2: 60,
top: 30,
height: 120
},
color: ['#78CDE6'],
/*dataZoom: [{
realtime: false,
start: 1,
end: 99,
top: 5,
height: 20,
handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
handleSize: '120%'
}],*/
xAxis: {
type: 'category',
boundaryGap: false,
axisLine: {
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
textStyle: {
fontFamily: 'Arial, Verdana, sans-serif',
color: '#666'
}
},
axisPointer: {
type: 'line',
label: {show: false},
triggerTooltip: true,
handle: {
show: true,
margin: 50,
color: '#F18D00'
}
},
data: times,
},
yAxis: {
type: 'value',
scale: true,
position: 'right',
axisLine: {
lineStyle: {
color: '#ccc'
}
},
axisLabel: {
inside: true,
textStyle: {
fontFamily: 'Arial, Verdana, sans-serif',
color: '#666'
}
}
},
series: [
{
name: '',
type: 'line',
smooth: true,
symbol: 'none',
sampling: 'average',
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#78CDE6'
}, {
offset: 1,
color: '#fff'
}])
}
},
data: datas
}
]
};
var myChart01b = echarts.init(document.getElementById('chart01a'));
myChart01b.setOption(option01b,true);
}