From 28c43d717c341ae45dca155dcf4e1952c60bc3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E5=90=89=E6=AC=A2?= Date: Wed, 18 Apr 2018 13:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=95=E7=A5=A8=E7=B1=BB=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fangija-zsyf/yfindex.html | 97 ++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 27 deletions(-) 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 += '
'+dataObj[i].title+ '
'+ - ''+dataObj[i].voteFavorText+''+ + ''+dataObj[i].voteFavorText+''+ '
'+ - '
'+dataObj[i].voteNoFavorText+''+ + '
'+dataObj[i].voteNoFavorText+''+ '
V.S
'; } } @@ -2638,15 +2689,7 @@ function openDistWindow(city, region, name){ } });*/ -/* 投票 */ -$("body").delegate(".vote01 .icon-light-grey", "click", function () { - $(".vote01 .icon-light-grey").addClass("icon-light-red"); - $(".vote02 .icon-light-grey").removeClass("icon-light-blue"); -}); -$("body").delegate(".vote02 .icon-light-grey", "click", function () { - $(".vote01 .icon-light-grey").removeClass("icon-light-red"); - $(".vote02 .icon-light-grey").addClass("icon-light-blue"); -}); + $("body").delegate("#hotList ul li", "click", function () { var select_city = $(this).find("a").attr("data-city");