Skip to content

Commit

Permalink
update the post page
Browse files Browse the repository at this point in the history
1.request to the voting the post
2.display whether the voting state has changed or not .
3.reset the voting weight of  the post
  • Loading branch information
Cha0s0000 committed Apr 27, 2018
1 parent 528aee4 commit c09afbc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
Binary file added images/icon/loading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 78 additions & 5 deletions pages/post/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,85 @@ Page({

//clicking the voting button to select the vote weight
showVoteWeightSlider:function(e){
var name = wx.getStorageSync('name');
if (name) {
var voteOrNot = e.currentTarget.dataset.voteornot;
if (voteOrNot != 2){
var index = e.currentTarget.dataset.index;
var state = e.currentTarget.dataset.state;
var addVoteToPostData = this.data.postsData;
addVoteToPostData[index].vote =(state==1?0:1);
addVoteToPostData[index].voteWeight = 10000;
console.log(state);
this.setData({ postsData: addVoteToPostData})
}
}
else {
wx.showModal({
title: 'Login',
content: 'Please login first',
success: function (res) {
if (res.confirm) {
console.log('confirm')
} else if (res.cancel) {
console.log('cancel')
}
}
})
}
},

//slide the slider to set the vote wight
setVoteWeight:function(e){
var index = e.currentTarget.dataset.index;
var voteWeight = e.detail.value *100;
var addVoteWeightToPostData = this.data.postsData;
addVoteWeightToPostData[index].voteWeight = voteWeight;
console.log(voteWeight);
this.setData({ postsData: addVoteWeightToPostData })
},

//vote the post
voteThePost:function(e){
var index = e.currentTarget.dataset.index;
var state = e.currentTarget.dataset.state;
var addVoteToPostData = this.data.postsData;
addVoteToPostData[index].vote =(state==1?0:1);
console.log(state);
this.setData({ postsData: addVoteToPostData})
var addVoteStateToPostData = this.data.postsData;
addVoteStateToPostData[index].voteOrNot = 2;
addVoteStateToPostData[index].vote = 0;
this.setData({ postsData: addVoteStateToPostData })

var item = e.currentTarget.dataset.item;
console.log("vote detail : author:" + item.author + "&permlink:" + item.permlink + "&weight:" + item.voteWeight);
var author = item.author;
var permlink = item.permlink;
var voteWeight = item.voteWeight;
var name = wx.getStorageSync('name');
var key = wx.getStorageSync('pass');
var that = this;
wx.request({
url: 'http://192.168.137.138:3000/operation/vote?voter=' + name + '&author=' + author + '&permlink=' + permlink + '&weight=' + voteWeight+'&key='+key,
method:'GET',
success:function(res){
console.log(res);
if(res.statusCode == '200' && res.data.message == 'success'){
addVoteStateToPostData[index].voteOrNot = (voteWeight == 0 ? 0 : 1);
that.setData({ postsData: addVoteStateToPostData })
}
else{
wx.showModal({
title: 'Error',
content: 'Something error with connection!',
success: function (res) {
if (res.confirm) {
console.log('Something error with connection!')
} else if (res.cancel) {
console.log('Something error with connection!')
}
}
})

}
}
})
}
})

6 changes: 3 additions & 3 deletions pages/post/post.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@

<view class= "foot-data">
<view class="vote-slider" hidden='{{item.vote == 1?false:true}}'>
<image mode="aspectFill" class="vote-confirm" src="../../images/icon/selected.png"></image>
<image mode="aspectFill" class="vote-confirm" bindtap='voteThePost' data-index ='{{index}}' data-item='{{item}}' src="../../images/icon/selected.png"></image>
<view class="vote-slider-view">
<slider bindchange="setVoteWeight" block-size='20' value='100' min="0" max="100" show-value/>
<slider bindchange="setVoteWeight" data-index='{{index}}' block-size='20' value='100' min="0" max="100" show-value/>
</view>
<image mode="aspectFill" bindtap='showVoteWeightSlider' data-state='{{item.vote}}' data-index='{{index}}' class="vote-cancel" src="../../images/icon/xx.png"></image>
</view>
<view class="post-like">
<!-- <icon type="success_circle" size="18"/> -->
<image mode="aspectFill" bindtap='showVoteWeightSlider' data-state='{{item.vote}}' data-index='{{index}}' class="icon" src="../../images/icon/{{item.voteOrNot == 1?'good-filling':'good'}}.png"></image>
<image mode="aspectFill" bindtap='showVoteWeightSlider' data-voteornot='{{item.voteOrNot}}' data-state='{{item.vote}}' data-index='{{index}}' class="icon" src="../../images/icon/{{item.voteOrNot == 1?'good-filling':(item.voteOrNot == 2 ?'loading':'good')}}.png"></image>
<!-- <icon type="success" size="18"/> -->
<text class="post-like-font" bindtap="showPayout" data-statu="open" data-detail="{{item}}"> {{item.pending_payout_value}}</text>
</view>
Expand Down

0 comments on commit c09afbc

Please sign in to comment.