投票类新闻控制
This commit is contained in:
+70
-27
@@ -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 += '<div class="card cardInfo cardInfo03"><div class="card-header">'+dataObj[i].title+
|
||||
'</div><div class="card-content"><div class="card-content-inner row"><div class="vote01 col-50">'+
|
||||
'<i class="icon icon-light-grey" data-val="'+dataObj[i].id+'"></i><span>'+dataObj[i].voteFavorText+'</span>'+
|
||||
'<i class="icon '+colorClass+'" data-val="'+dataObj[i].id+'"></i><span>'+dataObj[i].voteFavorText+'</span>'+
|
||||
'<font style="width:'+voteFavorCountRate+'%;" id="voteFavorCountRate_'+dataObj[i].id+'"></font><label id="voteFavorCount_'+dataObj[i].id+'">'+voteFavorCount+'票 '+voteFavorCountRate+'%</label></div>'+
|
||||
'<div class="vote02 col-50"><i class="icon icon-light-grey" data-val="'+dataObj[i].id+'"></i><span>'+dataObj[i].voteNoFavorText+'</span>'+
|
||||
'<div class="vote02 col-50"><i class="icon '+colorClass2+'" data-val="'+dataObj[i].id+'"></i><span>'+dataObj[i].voteNoFavorText+'</span>'+
|
||||
'<font style="width:'+voteNoFavorCountRate+'%;" id="voteNoFavorCountRate'+dataObj[i].id+'"></font><label id="voteNoFavorCount_'+dataObj[i].id+'">'+voteNoFavorCount+'票 '+voteNoFavorCountRate+'%</label></div><em>V.S</em></div></div></div>';
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user