Files
youfang-app/fangija-zsyf/js/quotations/collectCity.js
T
2018-04-27 16:11:12 +08:00

606 lines
13 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var city = ""
var myCollectCitys = [];
var lat = 31.222578;
var lng = 121.359555;
var allCity = []
var collCount = 0;
var collecteds = [];
var ret = []
var myDatasVue = new Vue({
el: '#contentTabDiv',
data: {
title:"",
cityDatas : []
}
})
var citysVue = new Vue({
el: '#tabCityDiv',
data: {
citys:[]
}
})
var date = new Date();
var year = date.getFullYear()+'年';
var month = date.getMonth()+1+'月';
//document.addEventListener('plusready', onPlusReady, false);
////扩展API加载完毕,现在可以正常调用扩展API
//function onPlusReady(){
// getPosition();
// loadMyCollectCity();
//
//}
//loadMyCollectCity();
function addUpChart(dataUp, num){
/* 小区上涨 */
//var dataUp = [];
optionUp = {
title: {
text: dataUp[0].value + '%',
subtext: '小区上涨',
x: 'center',
y: 'center',
itemGap: -8,
textStyle: {
fontFamily: 'Arial, Verdana, sans-serif',
fontSize: 30,
color: '#333',
fontWeight: 'normal'
},
subtextStyle: {
fontFamily: '华文细黑',
fontSize: 12,
color: '#666'
}
},
color: ['#EB5F34', '#e7e7e7'],
series: [
{
name: '小区上涨',
type: 'pie',
radius: ['90%', '100%'],
itemStyle: {
normal: {
label: {
show: true
},
labelLine: {
show: false
}
}
},
data: dataUp
}
]
};
var myChartUp = echarts.init(document.getElementById(num+'_up_chart'));
myChartUp.setOption(optionUp,true);
}
function addDownChart(dataDown, num){
/* 小区下跌 */
//var dataDown = [{value: 31, name: ''}];
optionDown = {
title: {
text: dataDown[0].value + '%',
subtext: '小区下跌',
x: 'center',
y: 'center',
itemGap: -8,
textStyle: {
fontFamily: 'Arial, Verdana, sans-serif',
fontSize: 30,
color: '#333',
fontWeight: 'normal'
},
subtextStyle: {
fontFamily: '华文细黑',
fontSize: 12,
color: '#666'
}
},
color: ['#88D053', '#e7e7e7'],
series: [
{
name: '小区下跌',
type: 'pie',
radius: ['90%', '100%'],
itemStyle: {
normal: {
label: {
show: true
},
labelLine: {
show: false
}
}
},
data: dataDown
}
]
};
var myChartUp = echarts.init(document.getElementById(num+'_down_chart'));
myChartUp.setOption(optionDown,true);
}
//加载我关注的城市
function loadMyCollectCity(){
axios.get("/rest/quotations/userCollectCitys",{}).then(function (response) {
var curDatas = response.data.data
if(curDatas){
collCount = curDatas.length;
for(var i in curDatas){
var curCity = curDatas[i]
if(!IsInArray(myCollectCitys, curCity)){
allCity.push(curCity)
myCollectCitys.push(curCity);
}
collecteds.push(curCity);
}
}
if(myCollectCitys && myCollectCitys.length>0){
for(var j in myCollectCitys){
var curCity = myCollectCitys[j]
createData(curCity, j);
}
}
}).catch(function (error) {
console.log(error);
});
}
function createData(curCity, i){
var len = parseInt(i)
if(len<10){
axios.all([loadCityPriceInfo(curCity), detail(curCity), loadCityPricesAndCounts(curCity), loadHotDistrict(curCity)])
.then(axios.spread(function (acct, perms, trends, nearDists) {
var cityObj = new Object();
var data1 = acct.data.data
cityObj.hrefId = "tabQuotation"+(len+2)
cityObj.numId_up_chart = (len+1)+"_up_chart";
cityObj.numId_down_chart = (len+1)+"_down_chart";
cityObj.numId_price_chart = (len+1)+"_price_chart";
cityObj.colled = false;
if(IsInArray(collecteds, curCity)){
cityObj.colled = true;
}
if(data1){
cityObj.city = data1.city
cityObj.cityTopMonthAvgPrice = data1.cityTopMonthAvgPrice
cityObj.downChance = data1.downChance
cityObj.follow = data1.follow
cityObj.index = data1.index
cityObj.oneMonthUpDownRange = (data1.oneMonthUpDownRange*100).toFixed(2)
cityObj.oneYearUpDownRange = data1.oneYearUpDownRange
cityObj.rangeLevel = data1.rangeLevel
cityObj.time = year + month
}
var data2 = perms.data.data
if(data2){
cityObj.downRate = data2.downRate
cityObj.upRate = data2.upRate
}
var data3 = trends.data.data
if(data3){
cityObj.times = data3.times
cityObj.cityPriceMap = data3.cityPriceMap
cityObj.countMap = data3.countMap
}
var data4 = nearDists.data.data
if(data4){
var nears = []
for(var n in data4){
var v = data4[n]
var nearObj = new Object();
nearObj.city = v.city
nearObj.region = v.region
nearObj.name = v.name;
nearObj.sname = nameConver(v.name)
nearObj.avgPrice = v.avgPrice
nears.push(nearObj);
}
cityObj.nears = nears
}
ret.push(cityObj);
myDatasVue.$data.cityDatas = ret;
}));
}
}
function nameConver(textName){
var length = textName.length;
var textStr = textName;
if(length > 5){
textStr = textName.substr(0,5)+ "...";
}
return textStr;
}
function loadCityPriceInfo(city){
return axios.get("/rest/quotations/cityPriceInfo?city="+city);
}
function detail(city){
return axios.get("/rest/quotations/hosueQuatations?city="+city);
}
function loadCityPricesAndCounts(city){
return axios.get("/rest/quotations/loadCityPriceTrends?city="+city+"&type=2")
}
function loadHotDistrict(city){
return axios.get("/rest/districts/hotDistricts?city="+city+"&top=5")
}
function clickTrend(city, type, num){
if(type == 5){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
startingLoadCharts(city, type, num);
})
return;
} else {
startingLoadCharts(city, type, num);
}
}else{
startingLoadCharts(city, type, num);
}
}
function startingLoadCharts(city, type, num){
axios.get("/rest/quotations/loadCityPriceTrends", {
params: {
city: city,
type:type
}
}).then(function (response) {
var datas = response.data.data
var prices = []
var counts = []
var times = datas.times
for(var i in times){
var time = times[i]
time = parseInt(time.replace("-",""))
var pm = datas.cityPriceMap;
var cm = datas.countMap;
if(pm){
if(pm[time]){
prices.push(pm[time])
}else{
prices.push(null)
}
}
if(cm){
if(cm[time]){
counts.push(cm[time]);
}else{
counts.push(null);
}
}
}
$("div[tid='"+num+"']").find("a").removeClass("active")
$("div[tid='"+num+"']").find("a[v='"+type+"']").addClass("active")
showChart(num+"_price_chart", times, prices, counts)
}).catch(function (error) {
console.log(error);
});
}
function IsInArray(arr, val){
  var testStr=','+arr.join(",")+",";
  return testStr.indexOf(","+val+",")!=-1;
}
var t1 = window.setInterval(loadChart,1000);
function loadChart(){
var d1 = myDatasVue.$data.cityDatas.length
if(d1>0 && d1>=collCount){
loadTabCity();
loadUpOrDownChart();
loadTrends();
window.clearInterval(t1);
}
}
function loadTabCity(){
var datas = myDatasVue.$data.cityDatas
var citys = []
for(var i in datas){
var obj = datas[i]
var numObj = new Object();
numObj.hrefId = "tabQuotation"+(parseInt(i)+2)
numObj.city = obj.city
citys.push(numObj)
}
citysVue.$data.citys = citys;
}
function loadUpOrDownChart(){
var datas = myDatasVue.$data.cityDatas
for(var i in datas){
var obj = datas[i]
var num = parseInt(i)+1;
if(obj.upRate){
var cityObj1 = new Object();
cityObj1.name= ""
cityObj1.value = obj.upRate
var cityObj2 = new Object();
cityObj2.name= ""
cityObj2.value = 100 - obj.upRate
dataUp = [cityObj1, cityObj2]
addUpChart(dataUp, num)
}else{
$("#"+num+"_up_chart").parent().parent().hide()
}
if(obj.downRate){
var cityObj3 = new Object();
cityObj3.name= ""
cityObj3.value = obj.downRate
var cityObj4 = new Object();
cityObj4.name= ""
cityObj4.value = 100 - obj.downRate
dataDown = [cityObj3, cityObj4]
addDownChart(dataDown, num)
}else{
$("#"+num+"_down_chart").parent().parent().hide()
}
}
}
function loadTrends(){
var datas = myDatasVue.$data.cityDatas
for(var i in datas){
var obj = datas[i]
var num = parseInt(i)+1;
var prices = []
var counts = []
var times = obj.times
for(var i in times){
var time = times[i]
time = parseInt(time.replace("-",""))
var pm = obj.cityPriceMap;
var cm = obj.countMap;
if(pm){
prices.push(pm[time])
}
if(cm){
counts.push(cm[time]);
}
}
showChart(num+"_price_chart", obj.times, prices, counts)
}
}
function showChart(idDom, categories, prices, counts){
if(!prices){
prices = []
}
if(!counts){
counts = []
}
/* 城市均价及挂牌走势 */
var chart = Highcharts.chart(idDom, {
colors: ['#ff7f50','#87cefa'],
title: {
text: '城市楼市均价及挂牌走势',
y: -30
},
xAxis: [{
categories:categories,
crosshair: true
}],
yAxis: [{
title: {
text: '元/㎡',
align: 'high',
offset: 4,
rotation: 0,
y: -20
},
allowDecimals: false,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
}, { // Secondary yAxis
title: {
text: '套',
align: 'high',
offset: 25,
rotation: 0,
y: -20
},
allowDecimals: false,
opposite: true
}],
tooltip: {
shared: true
},
credits: {
enabled: false
},
plotOptions: {
line: {
connectNulls: true //该设置会连接空值点
},
series: {
events: {
legendItemClick: function(e) {
return false;
}
},
marker: {
radius: 3, //曲线点半径,默认是4
symbol: 'circle' //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
}
}
},
series: [{
name: '均价',
type: 'line',
zIndex: 1,
tooltip: {
valueSuffix: ' 元/㎡'
},
data: prices
},{
name: '挂牌量',
type: 'column',
yAxis: 1,
tooltip: {
valueSuffix: ' 套'
},
data: counts
}]
});
}
function showDistrictDetail(index, city){
var datas = myDatasVue.$data.cityDatas
if(datas){
for(var i in datas){
var obj = datas[i]
if(obj.city == city){
var dists = obj.nears
var dm = dists[index]
clicked('../district/detail.html',true,false,{},{city:dm.city,region:dm.region,name:dm.name});
}
}
}
}
function showRegionInfo(city){
clicked('../house/regions.html',true,false,{},{city:city});
}
function collectCity(city, index){
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();
}
collectCity(city)
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 {
docollectCity(city)
}
}
function docollectCity(city){
axios.get("/rest/quotations/collectCity",{
params:{
city : city
}
}).then(function (response) {
var msg = response.data.message;
if(msg){
var newRet1 = []
var newRet2 = []
if(msg == "取消关注成功"){
var datas = myDatasVue.$data.cityDatas
for(var i in datas){
var obj = datas[i]
if(obj.city != city){
newRet1.push(obj)
}
}
var data2s = citysVue.$data.citys
var isLast = false;
for(var i in data2s){
var obj = data2s[i]
if(obj.city != city){
newRet2.push(obj)
}else{
if(parseInt(i)+1==data2s.length){
isLast = true;
}
}
}
if(isLast){
//window.location.reload();
$("a[href='#tabQuotation0']").click();
}
myDatasVue.$data.cityDatas = newRet1;
citysVue.$data.citys = newRet2
}else{
var datas = myDatasVue.$data.cityDatas
for(var i in datas){
var obj = datas[i]
if(obj.city == city){
obj.colled = true;
}
}
}
}
})
.catch(function (error) {
console.log(error);
});
}