diff --git a/fangija-zsyf/yfindex.html b/fangija-zsyf/yfindex.html index 664734e..e7dc6f9 100644 --- a/fangija-zsyf/yfindex.html +++ b/fangija-zsyf/yfindex.html @@ -1528,7 +1528,8 @@ function initNews(page){ axios.get("/rest/news/list", { params: { city: $("#input_city").text(), - page:page + page:page, + deviceId:plus.device.uuid } }) .then(function (response) { @@ -1578,44 +1579,85 @@ $("#region").click(function(e){ })*/ $("body").delegate(".vote01 .icon-light-grey", "click", function () { + if($(".vote01 .icon-light-grey").attr("class").indexOf("red") > 0){ + $.toast("已投票"); + return; + } var id = $(this).attr("data-val"); var voteFavorCount = parseInt($("#voteFavorCount_"+id).text().split(" ")[0].replace("票",""))+1; var voteNoFavorCount = parseInt($("#voteNoFavorCount_"+id).text().split(" ")[0].replace("票","")); var voteFavorCountRate = Math.round((voteFavorCount*100)/(voteFavorCount+voteNoFavorCount)); var voteNoFavorCountRate = 100-voteFavorCountRate; - $("#voteFavorCount_"+id).text(voteFavorCount+'票 '+voteFavorCountRate+'%'); - $("#voteFavorCountRate_"+id).css("width",voteFavorCountRate+'%'); - $("#voteNoFavorCount_"+id).text(voteNoFavorCount+'票 '+voteNoFavorCountRate+'%'); - $("#voteNoFavorCountRate_"+id).css("width",voteNoFavorCountRate+'%'); - doVote(id,0); + axios.get("/rest/news/vote", { + params: { + newsId: id, + type:0, + deviceId:plus.device.uuid + } + }) + .then(function (response) { + if(!response.data.status){ + $.toast(response.data.message); + } else { + if (!response.data.data){ + $(".vote01 .icon-light-grey").addClass("icon-light-red"); + $(".vote02 .icon-light-grey").removeClass("icon-light-blue"); + $("#voteFavorCount_"+id).text(voteFavorCount+'票 '+voteFavorCountRate+'%'); + $("#voteFavorCountRate_"+id).css("width",voteFavorCountRate+'%'); + $("#voteNoFavorCount_"+id).text(voteNoFavorCount+'票 '+voteNoFavorCountRate+'%'); + $("#voteNoFavorCountRate_"+id).css("width",voteNoFavorCountRate+'%'); + } else { + $.toast("已投票"); + } + } + }) + .catch(function (error) { + console.log(error); + $.toast("投票失败,请重试"); + }); + }); $("body").delegate(".vote02 .icon-light-grey", "click", function () { + if($(".vote01 .icon-light-grey").attr("class").indexOf("blue") > 0){ + $.toast("已投票"); + return; + } var id = $(this).attr("data-val"); var voteFavorCount = parseInt($("#voteFavorCount_"+id).text().split(" ")[0].replace("票","")); var voteNoFavorCount = parseInt($("#voteNoFavorCount_"+id).text().split(" ")[0].replace("票",""))+1; var voteFavorCountRate = Math.round((voteFavorCount*100)/(voteFavorCount+voteNoFavorCount)); var voteNoFavorCountRate = 100-voteFavorCountRate; - $("#voteFavorCount_"+id).text(voteFavorCount+'票 '+voteFavorCountRate+'%'); - $("#voteFavorCountRate_"+id).css("width",voteFavorCountRate+'%'); - $("#voteNoFavorCount_"+id).text(voteNoFavorCount+'票 '+voteNoFavorCountRate+'%'); - $("#voteNoFavorCountRate_"+id).css("width",voteNoFavorCountRate+'%'); - doVote(id,1); -}); - -function doVote(id,flag){ axios.get("/rest/news/vote", { params: { newsId: id, - type:flag + type:1, + deviceId:plus.device.uuid } }) .then(function (response) { + if(!response.data.status){ + $.toast(response.data.message); + } else { + if (!response.data.data){ + $("#voteFavorCount_"+id).text(voteFavorCount+'票 '+voteFavorCountRate+'%'); + $("#voteFavorCountRate_"+id).css("width",voteFavorCountRate+'%'); + $("#voteNoFavorCount_"+id).text(voteNoFavorCount+'票 '+voteNoFavorCountRate+'%'); + $("#voteNoFavorCountRate_"+id).css("width",voteNoFavorCountRate+'%'); + $(".vote01 .icon-light-grey").removeClass("icon-light-red"); + $(".vote02 .icon-light-grey").addClass("icon-light-blue"); + } else { + $.toast("已投票"); + } + } }) .catch(function (error) { console.log(error); + $.toast("投票失败,请重试"); }); -} + +}); + function changeRegion(){ axios.get("/rest/index/home", { @@ -1850,11 +1892,20 @@ function addItems(number, lastIndex) { voteNoFavorCountRate = 100-voteFavorCountRate; } + var colorClass = "icon-light-grey"; + var colorClass2 = "icon-light-grey"; + if (dataObj[i].vote) { + if (dataObj[i].voteType == 0) { + colorClass = "icon-light-grey icon-light-red"; + } else { + colorClass2 = "icon-light-grey icon-light-blue"; + } + } html += '