Files
youfang-app/fangija-zsyf/js/quotations/cityDetail.js
T
2018-04-17 18:52:59 +08:00

557 lines
12 KiB
JavaScript

var ret = []
function loadMyCollectCity(){
plus.nativeUI.showWaiting();
axios.get("/rest/quotations/userCollectCitys",{}).then(function (response) {
var curDatas = response.data.data
if(curDatas && curDatas.length>0){
if(positionCity){
if(!IsInArray(curDatas, positionCity)){
curDatas.splice(0,0, positionCity)
}
}
cityDetaiVue.$data.citys = curDatas;
}else{
if(positionCity){
cityDetaiVue.$data.citys.push(positionCity);
}
}
$("#cityInfo").hide()
plus.nativeUI.closeWaiting();
}).catch(function (error) {
plus.nativeUI.closeWaiting();
console.log(error);
});
}
function loadCurCity(city){
plus.nativeUI.showWaiting();
axios.get("/rest/quotations/userCollectCitys",{}).then(function (response) {
var curDatas = response.data.data
if(curDatas && curDatas.length>0){
if(IsInArray(curDatas, city)){
cityInfoVue.$data.collecd = true;
}else{
cityInfoVue.$data.collecd = false;
}
}
plus.nativeUI.closeWaiting();
}).catch(function (error) {
plus.nativeUI.closeWaiting();
console.log(error);
});
}
function loadCityPriceInfo(city){
axios.get("/rest/quotations/cityPriceInfo", {
params: {
city: city
}
}).then(function (response) {
var data1 = response.data.data
if(data1){
var cityObj = new Object();
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
cityInfoVue.$data.myCityMap = cityObj;
$("#priceDiv").removeClass("dn");
}
}).catch(function (error) {
console.log(error);
});
}
function loadUpOrDown(city){
axios.get("/rest/quotations/hosueQuatations", {
params: {
city: city
}
}).then(function (response) {
var data2 = response.data.data
if(data2){
loadUpOrDownChart(data2.downRate, data2.upRate);
}
}).catch(function (error) {
console.log(error);
});
}
function loadCityPricesAndCounts(city){
axios.get("/rest/quotations/loadCityPriceTrends", {
params: {
city: city,
type:2
}
}).then(function (response) {
var data3 = response.data.data
if(data3){
loadTrends(data3.times, data3.cityPriceMap , data3.countMap);
}
}).catch(function (error) {
console.log(error);
});
}
function loadHotDistrict(city){
axios.get("/rest/districts/hotDistricts", {
params: {
city: city,
top:5
}
}).then(function (response) {
var data4 = response.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);
}
cityInfoVue.$data.nears = nears;
}
}).catch(function (error) {
console.log(error);
});
}
/*点击走势TAB页*/
function clickTrend(city, type){
if(type == 5){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
clickTrend(city, type);
})
return;
} else {
startingLoadCharts(city, type);
}
}else{
startingLoadCharts(city, type);
}
}
function startingLoadCharts(city, type){
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);
}
}
}
$("#trendDiv a").removeClass("active");
$("a[v='"+type+"']").addClass("active")
showChart("price_chart", times, prices, counts)
}).catch(function (error) {
console.log(error);
});
}
function loadUpOrDownChart(downRate, upRate){
if(upRate){
var cityObj1 = new Object();
cityObj1.name= ""
cityObj1.value = upRate
var cityObj2 = new Object();
cityObj2.name= ""
cityObj2.value = 100 - upRate
dataUp = [cityObj1, cityObj2]
addUpChart(dataUp)
$("#up_chart").parent().parent().show();
}else{
$("#up_chart").parent().parent().hide()
}
if(downRate){
var cityObj3 = new Object();
cityObj3.name= ""
cityObj3.value = downRate
var cityObj4 = new Object();
cityObj4.name= ""
cityObj4.value = 100 - downRate
dataDown = [cityObj3, cityObj4]
addDownChart(dataDown)
$("#down_chart").parent().parent().show();
}else{
$("#down_chart").parent().parent().hide()
}
}
function loadTrends(times, cityPriceMap, countMap){
var prices = []
var counts = []
for(var i in times){
var time = times[i]
time = parseInt(time.replace("-",""))
var pm = cityPriceMap;
var cm = 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);
}
}
}
showChart("price_chart", times, prices, counts)
}
/*跳转区域列表*/
function showRegionInfo(city){
clicked('../house/regions.html',true,false,{},{city:city});
}
/*跳转小区详情*/
function showDistrictDetail(city, region, name){
clicked('../district/detail.html',true,false,{},{city:city,region:region,name:name});
}
function showChart(idDom, categories, prices, counts){
if(!prices){
prices = []
}
if(!counts){
counts = []
}
if(prices.length==0 && counts.length == 0){
$("#trendChartDiv").hide();
}else{
/* 城市均价及挂牌走势 */
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 nameConver(textName){
var length = textName.length;
var textStr = textName;
if(length > 5){
textStr = textName.substr(0,5)+ "...";
}
return textStr;
}
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('up_chart'));
myChartUp.setOption(optionUp,true);
}
function addDownChart(dataDown){
/* 小区下跌 */
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('down_chart'));
myChartUp.setOption(optionDown,true);
}
function collectCity(city, type){
if (localStorage.getItem("user_token") == null || localStorage.getItem("user_token") == "") {
clicked('../user/codeSms.html',true,false,{},{},function(){
collectCity(city)
})
return;
} else {
var title = ""
if(type == 0){
title = "您确定要添加关注?"
}else{
title = "您确定要取消关注?"
}
$.confirm(title, function () {
docollectCity(city, type)
});
}
}
function docollectCity(city, type){
axios.get("/rest/quotations/collectCity",{
params:{
city : city,
type:type
}
}).then(function (response) {
var msg = response.data.message;
if(msg){
if(msg == "取消关注成功"){
try{
cityInfoVue.$data.collecd = false;
var da = cityDetaiVue.$data.citys
if(da && da.length>0){
var index = da.indexOf(city)
if(index>=0){
da.splice(index, 1)
cityDetaiVue.$data.citys = da;
if(da.length==0){
$("a[href='#tabQuotation0']").click();
}
}
}
}catch(e){
}
//loadMyCollectCity();
$("a[href='#tabQuotation1']").click();
//plus.webview.getWebviewById('views/house/houseDetail.html').reload();
reloadMyFocus();
reloadCityPotentialRanking()
reloadCityIncreaseRanking()
}else if(msg == "关注成功"){
cityInfoVue.$data.collecd = true;
plus.webview.getWebviewById('views/house/houseDetail.html').reload();
reloadMyFocus();
reloadCityPotentialRanking()
reloadCityIncreaseRanking()
}else{
$.toast(msg);
}
}
})
.catch(function (error) {
console.log(error);
});
}