<block wx:if="{{item.tags==0}}">
<image class="vote_s" data-num="1" data-id="{{item.id}}" data-index="{{index}}" catchtap="getTagsArticle" src="../../../../images/upvote_s.png"></image>
<text style="margin-left:4rpx;">{{item.tags_num}}</text>
</block>
<block wx:else>
<image class="vote_s" data-num="-1" data-id="{{item.id}}" data-index="{{index}}" catchtap="getTagsArticle" src="../../../../images/vote_s.png"></image>
<text style="margin-left:4rpx;">{{item.tags_num}}</text>
</block>
getTagsArticle(e) {
console.log(e)
// 判断是否点赞 1 或者 -1
let num = e.currentTarget.dataset.num;
// 当前项的id
let id = e.currentTarget.dataset.id;
// 当前项的索引
let idx = e.currentTarget.dataset.index;
console.log(num, id, idx)
const that = this;
var postsData = {
id: id,
num: num
}
let dataInfo = requestSign.requestSign(postsData)
header.sign = dataInfo
wx.request({
url: api.get_tagsArticle,
data: postsData,
header: header,
method: 'POST',
dataType: 'json',
responseType: 'text',
success: ({
data
}) => {
console.log(data, '成功')
if (data.code == 1) {
if (num > 0) { //点赞
that.data.articleList[idx].tags = 1;
that.data.articleList[idx].tags_num++;
} else { //取消点赞
that.data.articleList[idx].tags = 0;
that.data.articleList[idx].tags_num--;
}
that.setData({
["articleList[" + idx + "]"]: that.data.articleList[idx]
})
} else {
wx.showToast({
title: data.message
})
}
}
});
}