var city = "" var myCollectCitys = []; var lat; var lng; var allCity = [] var myDatasVue = new Vue({ el: '#contentTabDiv', data: { title:"", cityDatas : [] } }) 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 getPosition(){ plus.geolocation.getCurrentPosition(function(p){ city = p.address.city; myCollectCitys.push(city); lng = p.coords.longitude;//获取到当前位置的经度 lat = p.coords.latitude;//获取到当前位置的纬度; }, function(e){ }, { provider:'baidu', enableHighAccuracy:true, coordsType:'bd09ll' } ); } 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){ var ret = [] for(var i in curDatas){ var curCity = curDatas[i] if(!IsInArray(myCollectCitys, curCity)){ allCity.push(curCity) var j = 1; axios.all([loadCityPriceInfo(curCity), detail(curCity), loadCityPricesAndCounts(curCity)]) .then(axios.spread(function (acct, perms, trends) { var cityObj = new Object(); var data1 = acct.data.data cityObj.numId_up_chart = j+"_up_chart"; cityObj.numId_down_chart = j+"_down_chart"; cityObj.numId_price_chart = j+"_price_chart"; j = j+1; 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 } ret.push(cityObj); myDatasVue.$data.cityDatas = ret; //console.log(myDatasVue.$data.cityDatas.length); })); } } //myDatasVue.$data.cityDatas = ret; } }).catch(function (error) { alert(error) console.log(error); }); } 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 loadNearDistrict(){ return axios.get("/rest/districts/nearDistrict?lat="+lat+"&lng="+lng) } $(".button").click(function(){ console.log("type:"+$(this).text()) var type = (this).attr("v") var city = (this).attr("city") axios.get("/rest/quotations/loadCityPriceTrends", { params: { city: city, type:type } }).then(function (response) { var datas = trends.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){ prices.push(pm[time]) } if(cm){ counts.push(cm[time]); } } showChart(num+"_price_chart", obj.times, prices, counts) }).catch(function (error) { alert(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 var d2 = allCity.length; if(d2>0 && d2==d1){ loadUpOrDownChart(); loadTrends(); window.clearInterval(t1); } } function loadUpOrDownChart(){ var datas = myDatasVue.$data.cityDatas for(var i in datas){ var obj = datas[i] var num = parseInt(i)+1; 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) 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) } } 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, { title: { text: '城市均价及挂牌走势', y: -30 }, colors: ['#F88C9F', '#78CDE6'], xAxis: { type: 'datetime', categories: categories, boundaryGap: false, tickInterval: 2, tickLength: 6, crosshair: true }, yAxis: [{ // 第一个Y轴,放置在左边 title: { text: '元/㎡', align: 'high', offset: 4, rotation: 0, y: -20 }, plotLines: [{ value: 0, width: 1, color: '#808080' }], allowDecimals: false }, { // 第二个Y轴,放置在右边 linkedTo: 0, opposite: true, // 通过此参数设置坐标轴显示在对立面 title: { text: '套', align: 'high', offset: 25, rotation: 0, y: -20 }, plotLines: [{ value: 0, width: 1, color: '#808080' }], allowDecimals: false }], 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" } } }, tooltip: { shared: true }, series: [{ name: '均价', zIndex: 1, data: prices, tooltip: { valueSuffix: '元/㎡' } }, { name: '挂牌量', type: 'column', borderColor: null, data: counts, tooltip: { valueSuffix: '套' } }] }); }