|
| xqd
@@ -7,13 +7,16 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- time: '2018-06-26 9:06',
|
|
|
+ is_login:false,
|
|
|
+ reply_id:0,
|
|
|
+ focus:false,
|
|
|
+ placeholder:'随便说些什么...',
|
|
|
+ is_reply:false,
|
|
|
+ comment_content:'',
|
|
|
like: true,
|
|
|
- normal: true,
|
|
|
- dislike: true,
|
|
|
- zan: false,
|
|
|
news:{},
|
|
|
news_comments:{},
|
|
|
+ comments:[],
|
|
|
},
|
|
|
|
|
|
/**
|
|
| xqd
@@ -32,15 +35,44 @@ Page({
|
|
|
},
|
|
|
success:function(res){
|
|
|
that.setData({
|
|
|
+ next_page_url: res.data.data.news_comments.next_page_url,
|
|
|
news:res.data.data.news,
|
|
|
- news_comments:res.data.data.news_comments
|
|
|
+ news_comments:res.data.data.news_comments,
|
|
|
+ comments: res.data.data.news_comments.data
|
|
|
})
|
|
|
+ var c = that.data.comments
|
|
|
+ for(var i = 0;i<c.length;i++){
|
|
|
+ console.log(c[i].created_at)
|
|
|
+ var d = new Date(c[i].created_at).getTime()
|
|
|
+ var n = new Date().getTime()
|
|
|
+ var t = n - d
|
|
|
+ if(t < 60000){
|
|
|
+ var x = Math.round(t / 1000)
|
|
|
+ c[i].created_at = ''+x+ '秒前'
|
|
|
+ }else if(t >= 60000 && t < 3600000){
|
|
|
+ var x = Math.round(t / 60000)
|
|
|
+ c[i].created_at = '' + x + '分钟前'
|
|
|
+ } else if (t >= 3600000 && t < 86400000){
|
|
|
+ var x = Math.round(t / 3600000)
|
|
|
+ c[i].created_at = '' + x + '小时前'
|
|
|
+ } else if (t >= 86400000 && t < 86400000*3){
|
|
|
+ var x = Math.round(t / 86400000)
|
|
|
+ c[i].created_at = '' + x + '天前'
|
|
|
+ } else {
|
|
|
+ var e = new Date(d)
|
|
|
+ var x = ''+e.getFullYear()+'-'+(e.getMonth()+1)+'-'+e.getDate()
|
|
|
+ c[i].created_at = '' + x
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ comments:c
|
|
|
+ })
|
|
|
+ that.news_time()
|
|
|
var article = that.data.news.content
|
|
|
WxParse.wxParse('article', 'html', article, that, 5)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
| xqd
@@ -80,7 +112,57 @@ Page({
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
-
|
|
|
+ var that = this
|
|
|
+ if(that.data.next_page_url){
|
|
|
+ app.request({
|
|
|
+ url: that.data.next_page_url,
|
|
|
+ method: 'get',
|
|
|
+ data: {
|
|
|
+ store_id: 1,
|
|
|
+ newsid: that.data.news.id
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ that.setData({
|
|
|
+ next_page_url: res.data.data.news_comments.next_page_url,
|
|
|
+ news: res.data.data.news,
|
|
|
+ })
|
|
|
+ var c = res.data.data.news_comments.data
|
|
|
+ for (var i = 0; i < c.length; i++) {
|
|
|
+ console.log(c[i].created_at)
|
|
|
+ var d = new Date(c[i].created_at).getTime()
|
|
|
+ var n = new Date().getTime()
|
|
|
+ var t = n - d
|
|
|
+ if (t < 60000) {
|
|
|
+ var x = Math.round(t / 1000)
|
|
|
+ c[i].created_at = '' + x + '秒前'
|
|
|
+ } else if (t >= 60000 && t < 3600000) {
|
|
|
+ var x = Math.round(t / 60000)
|
|
|
+ c[i].created_at = '' + x + '分钟前'
|
|
|
+ } else if (t >= 3600000 && t < 86400000) {
|
|
|
+ var x = Math.round(t / 3600000)
|
|
|
+ c[i].created_at = '' + x + '小时前'
|
|
|
+ } else if (t >= 86400000 && t < 86400000 * 3) {
|
|
|
+ var x = Math.round(t / 86400000)
|
|
|
+ c[i].created_at = '' + x + '天前'
|
|
|
+ } else {
|
|
|
+ var e = new Date(d)
|
|
|
+ var x = '' + e.getFullYear() + '-' + (e.getMonth() + 1) + '-' + e.getDate()
|
|
|
+ c[i].created_at = '' + x
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ comments: [...that.data.comments.concat(c)]
|
|
|
+ })
|
|
|
+ that.news_time()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ wx.showToast({
|
|
|
+ title: '已经没有更多了',
|
|
|
+ icon:'none',
|
|
|
+ duration:1000
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
| xqd
@@ -91,69 +173,296 @@ Page({
|
|
|
},
|
|
|
like: function () {
|
|
|
var that = this
|
|
|
- console.log('hahhahhah')
|
|
|
if (that.data.like == true) {
|
|
|
that.setData({
|
|
|
like: false,
|
|
|
- normal: true,
|
|
|
- dislike: true
|
|
|
+ })
|
|
|
+ app.request({
|
|
|
+ url:'https://t6.9026.com/api/furniture/addtolike',
|
|
|
+ data:{
|
|
|
+ store_id:1,
|
|
|
+ newsid:that.data.news.id,
|
|
|
+ like:1
|
|
|
+ },
|
|
|
+ method:'get',
|
|
|
+ success:()=>{
|
|
|
+
|
|
|
+ }
|
|
|
})
|
|
|
} else {
|
|
|
- that.setData({
|
|
|
- like: true,
|
|
|
- normal: true,
|
|
|
- dislike: true
|
|
|
+ wx.showToast({
|
|
|
+ title: '已经喜欢过了呦~',
|
|
|
+ icon:'none',
|
|
|
+ duration:1000
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- normal: function () {
|
|
|
+ set_is_reply_false:function(){
|
|
|
var that = this
|
|
|
- if (that.data.normal == true) {
|
|
|
- that.setData({
|
|
|
- like: true,
|
|
|
- normal: false,
|
|
|
- dislike: true
|
|
|
- })
|
|
|
- } else {
|
|
|
- that.setData({
|
|
|
- like: true,
|
|
|
- normal: true,
|
|
|
- dislike: true
|
|
|
- })
|
|
|
+ that.setData({
|
|
|
+ focus:true,
|
|
|
+ is_reply:false,
|
|
|
+ placeholder:'随便说些什么'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ toConment: function (e) {
|
|
|
+ var that = this
|
|
|
+ console.log(e)
|
|
|
+ var id = e.currentTarget.id
|
|
|
+ wx.navigateTo({
|
|
|
+ url: 'conment/conment?id='+id+'&newsid='+that.data.news.id,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ reply:function(e){
|
|
|
+ console.log(e)
|
|
|
+ var that = this
|
|
|
+ that.setData({
|
|
|
+ focus:true,
|
|
|
+ is_reply:true,
|
|
|
+ reply_id:e.currentTarget.id,
|
|
|
+ placeholder:'回复 '+e.currentTarget.dataset.name
|
|
|
+ })
|
|
|
+ },
|
|
|
+ comment:function(e){
|
|
|
+ var that = this
|
|
|
+ var text = e.detail.value
|
|
|
+ if(that.data.is_reply == false){
|
|
|
+ if(text != ''){
|
|
|
+ app.request({
|
|
|
+ url: 'https://t6.9026.com/api/furniture/add_comments',
|
|
|
+ data: {
|
|
|
+ store_id: 1,
|
|
|
+ news_id: that.data.news.id,
|
|
|
+ content: text,
|
|
|
+ comment_id: 0
|
|
|
+ },
|
|
|
+ method: 'post',
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res.data)
|
|
|
+ if (res.data == 'Unauthorized .'){
|
|
|
+ that.setData({
|
|
|
+ is_login:true
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ app.request({
|
|
|
+ url: 'https://t6.9026.com/api/furniture/news_detail',
|
|
|
+ method: 'get',
|
|
|
+ data: {
|
|
|
+ store_id: 1,
|
|
|
+ newsid: that.data.news.id
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ that.setData({
|
|
|
+ news: res.data.data.news,
|
|
|
+ next_page_url: res.data.data.news_comments.next_page_url,
|
|
|
+ news_comments: res.data.data.news_comments,
|
|
|
+ comments: res.data.data.news_comments.data,
|
|
|
+ comment_content: ''
|
|
|
+ })
|
|
|
+ var c = that.data.comments
|
|
|
+ for (var i = 0; i < c.length; i++) {
|
|
|
+ console.log(c[i].created_at)
|
|
|
+ var d = new Date(c[i].created_at).getTime()
|
|
|
+ var n = new Date().getTime()
|
|
|
+ var t = n - d
|
|
|
+ if (t < 60000) {
|
|
|
+ var x = Math.round(t / 1000)
|
|
|
+ c[i].created_at = '' + x + '秒前'
|
|
|
+ } else if (t >= 60000 && t < 3600000) {
|
|
|
+ var x = Math.round(t / 60000)
|
|
|
+ c[i].created_at = '' + x + '分钟前'
|
|
|
+ } else if (t >= 3600000 && t < 86400000) {
|
|
|
+ var x = Math.round(t / 3600000)
|
|
|
+ c[i].created_at = '' + x + '小时前'
|
|
|
+ } else if (t >= 86400000 && t < 86400000 * 3) {
|
|
|
+ var x = Math.round(t / 86400000)
|
|
|
+ c[i].created_at = '' + x + '天前'
|
|
|
+ } else {
|
|
|
+ var e = new Date(d)
|
|
|
+ var x = '' + e.getFullYear() + '-' + (e.getMonth() + 1) + '-' + e.getDate()
|
|
|
+ c[i].created_at = '' + x
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ comments: c
|
|
|
+ })
|
|
|
+ that.news_time()
|
|
|
+ wx.showToast({
|
|
|
+ title: '评论成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }else if(that.data.is_reply == true){
|
|
|
+ console.log(that.data.reply_id)
|
|
|
+ if (text != '') {
|
|
|
+ app.request({
|
|
|
+ url: 'https://t6.9026.com/api/furniture/add_comments',
|
|
|
+ data: {
|
|
|
+ store_id: 1,
|
|
|
+ news_id: that.data.news.id,
|
|
|
+ content: text,
|
|
|
+ comments_id: that.data.reply_id
|
|
|
+ },
|
|
|
+ method: 'post',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.data == 'Unauthorized .') {
|
|
|
+ that.setData({
|
|
|
+ is_login: true
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ app.request({
|
|
|
+ url: 'https://t6.9026.com/api/furniture/news_detail',
|
|
|
+ method: 'get',
|
|
|
+ data: {
|
|
|
+ store_id: 1,
|
|
|
+ newsid: that.data.news.id
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ var id = that.data.reply_id
|
|
|
+ that.setData({
|
|
|
+ news: res.data.data.news,
|
|
|
+ next_page_url: res.data.data.news_comments.next_page_url,
|
|
|
+ is_reply: false,
|
|
|
+ reply_id: 0,
|
|
|
+ placeholder: '随便说些什么...',
|
|
|
+ news_comments: res.data.data.news_comments,
|
|
|
+ comments: res.data.data.news_comments.data,
|
|
|
+ comment_content: ''
|
|
|
+ })
|
|
|
+ var c = that.data.comments
|
|
|
+ for (var i = 0; i < c.length; i++) {
|
|
|
+ console.log(c[i].created_at)
|
|
|
+ var d = new Date(c[i].created_at).getTime()
|
|
|
+ var n = new Date().getTime()
|
|
|
+ var t = n - d
|
|
|
+ if (t < 60000) {
|
|
|
+ var x = Math.round(t / 1000)
|
|
|
+ c[i].created_at = '' + x + '秒前'
|
|
|
+ } else if (t >= 60000 && t < 3600000) {
|
|
|
+ var x = Math.round(t / 60000)
|
|
|
+ c[i].created_at = '' + x + '分钟前'
|
|
|
+ } else if (t >= 3600000 && t < 86400000) {
|
|
|
+ var x = Math.round(t / 3600000)
|
|
|
+ c[i].created_at = '' + x + '小时前'
|
|
|
+ } else if (t >= 86400000 && t < 86400000 * 3) {
|
|
|
+ var x = Math.round(t / 86400000)
|
|
|
+ c[i].created_at = '' + x + '天前'
|
|
|
+ } else {
|
|
|
+ var e = new Date(d)
|
|
|
+ var x = '' + e.getFullYear() + '-' + (e.getMonth() + 1) + '-' + e.getDate()
|
|
|
+ c[i].created_at = '' + x
|
|
|
+ }
|
|
|
+ }
|
|
|
+ that.setData({
|
|
|
+ comments: c
|
|
|
+ })
|
|
|
+ that.news_time
|
|
|
+ wx.showToast({
|
|
|
+ title: '回复成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ wx.navigateTo({
|
|
|
+ url: 'conment/conment?id=' + id + '&newsid=' + that.data.news.id,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ that.setData({
|
|
|
+ is_reply: false,
|
|
|
+ reply_id: 0,
|
|
|
+ placeholder: '随便说些什么...',
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
- dislike: function () {
|
|
|
+ news_time: function () {
|
|
|
var that = this
|
|
|
- if (that.data.dislike == true) {
|
|
|
- that.setData({
|
|
|
- like: true,
|
|
|
- normal: true,
|
|
|
- dislike: false
|
|
|
- })
|
|
|
+ var cc = that.data.news
|
|
|
+ var d = new Date(cc.created_at).getTime()
|
|
|
+ var n = new Date().getTime()
|
|
|
+ var t = n - d
|
|
|
+ if (t < 60000) {
|
|
|
+ var x = Math.round(t / 1000)
|
|
|
+ cc.created_at = '' + x + '秒前'
|
|
|
+ } else if (t >= 60000 && t < 3600000) {
|
|
|
+ var x = Math.round(t / 60000)
|
|
|
+ cc.created_at = '' + x + '分钟前'
|
|
|
+ } else if (t >= 3600000 && t < 86400000) {
|
|
|
+ var x = Math.round(t / 3600000)
|
|
|
+ cc.created_at = '' + x + '小时前'
|
|
|
+ } else if (t >= 86400000 && t < 86400000 * 3) {
|
|
|
+ var x = Math.round(t / 86400000)
|
|
|
+ cc.created_at = '' + x + '天前'
|
|
|
} else {
|
|
|
- that.setData({
|
|
|
- like: true,
|
|
|
- normal: true,
|
|
|
- dislike: true
|
|
|
- })
|
|
|
+ var e = new Date(d)
|
|
|
+ var x = '' + e.getFullYear() + '-' + (e.getMonth() + 1) + '-' + e.getDate()
|
|
|
+ cc.created_at = '' + x
|
|
|
}
|
|
|
+ that.setData({
|
|
|
+ news: cc
|
|
|
+ })
|
|
|
+ },
|
|
|
+ close_login: function () {
|
|
|
+ this.setData({
|
|
|
+ is_login: false
|
|
|
+ })
|
|
|
},
|
|
|
- zan: function () {
|
|
|
+ userLogin: function (e) {
|
|
|
+ this.setData({
|
|
|
+ is_login: false
|
|
|
+ })
|
|
|
+ wx.showLoading({
|
|
|
+ title: '登录中',
|
|
|
+ })
|
|
|
+ console.log(e.detail)
|
|
|
+ var un = JSON.parse(e.detail.rawData)
|
|
|
var that = this
|
|
|
- if (that.data.zan == true) {
|
|
|
- that.setData({
|
|
|
- zan: false
|
|
|
- })
|
|
|
- } else {
|
|
|
- that.setData({
|
|
|
- zan: true
|
|
|
+ try {
|
|
|
+ wx.login({
|
|
|
+ success: function (res) {
|
|
|
+ let code = res.code
|
|
|
+ console.log(code)
|
|
|
+ let tx = un.avatarUrl
|
|
|
+ let nn = un.nickName
|
|
|
+ app.request({
|
|
|
+ url: 'https://t6.9026.com/api/furniture/service_login',
|
|
|
+ method: 'POST',
|
|
|
+ data: {
|
|
|
+ code: code,
|
|
|
+ avatar: tx,
|
|
|
+ nickName: nn,
|
|
|
+ store_id: 1
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res.data)
|
|
|
+ wx.setStorageSync("token", res.data.data.token)
|
|
|
+ wx.setStorageSync('key', res.data.data.session_key)
|
|
|
+ wx.setStorageSync("user", res.data.data.user);
|
|
|
+ wx.setStorageSync('ma', 0)
|
|
|
+ wx.setStorageSync('pa', 0)
|
|
|
+ wx.setStorageSync('us', 0)
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({
|
|
|
+ title: '登录成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 1000,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e.message)
|
|
|
}
|
|
|
},
|
|
|
- toConment: function (e) {
|
|
|
- console.log(e)
|
|
|
- // wx.navigateTo({
|
|
|
- // url: 'conment/conment?',
|
|
|
- // })
|
|
|
- }
|
|
|
})
|