123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- const pages = require('../../mixin/pages')
- const { postFollowUser, postAddComment, postGood } = require('./api/index')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- ...pages.data(),
- listUrl: '/api/user/track/list',
- searchForm: {
- 'key_words': ''
- // 'follow_type': 1
- },
- nav: [
- {
- name: '推荐',
- value: '1'
- },
- {
- name: '关注',
- value: '2'
- }
- ],
- active: '1',
- booLock: false,
- autoFocus: false,
- inputBoxStyle: 'bottom:0;',
- form: {
- track_comment: '' // 评论内容
- },
- placeholderText: '评论',
- booPopop: false
- },
- currentItem: {}, // 当前选中的动态
- ...pages.methods,
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.fetchOrderList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.getTabBar().init()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- if (this.data.freshing) {
- return
- }
- this.setData({
- freshing: true
- })
- this.bindCallBack()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- this.fetchOrderList()
- },
- bindCallBack() {
- this.refreshOrderList()
- },
- handleNav(e) {
- const { value } = e.detail
- const searchForm = JSON.parse(JSON.stringify(this.data.searchForm))
- if (value === '1' && searchForm.hasOwnProperty('follow_type')) {
- delete searchForm.follow_type
- } else if (value === '2') {
- searchForm.follow_type = 1
- }
- this.setData({
- active: value,
- searchForm: searchForm
- }, () => {
- this.refreshOrderList()
- })
- },
- // 关注
- async followUser(e) {
- const { item, index } = e.target.dataset
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postFollowUser(item.shop_id)
- if (status) {
- wx.showToast({
- title: '已关注',
- icon: 'none'
- })
- this.setData({
- ['listData[' + index + '].follow_status']: 1
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- showPopop(e) {
- const { item, index } = e.currentTarget.dataset
- this.currentItem = {
- ...item,
- _index: index
- }
- this.setData({
- booPopop: true
- })
- const timer = setTimeout(() => {
- clearTimeout(timer)
- this.setData({
- autoFocus: true
- })
- }, 500)
- },
- hidePopop() {
- this.setData({
- booPopop: false
- })
- },
- handleFocus(event) {
- const height = event.detail.height
- this.setData({ inputBoxStyle: `bottom:${height}px;` })
- },
- handleBlur() {
- this.setData({ inputBoxStyle: `bottom:0;` })
- },
- setComment(event) {
- const { value } = event.detail
- this.setData({
- 'form.track_comment': value.trim()
- })
- },
- // 评论
- async addComment() {
- const { track_comment } = this.data.form
- const postData = {
- 'track_id': this.currentItem.id,
- 'track_comment': track_comment
- }
- if (!track_comment) {
- wx.showToast({
- title: '请输入评论内容',
- icon: 'none'
- })
- return
- }
- if (this.data.booLock) {
- return
- }
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postAddComment(postData)
- if (status) {
- wx.showToast({
- title: '已评论',
- icon: 'none'
- })
- this.refreshOrderList()
- this.setData({
- 'form.track_comment': '',
- booPopop: false
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- // 点赞、取消点赞
- async trackGood(e) {
- const { item, index } = e.currentTarget.dataset
- const postData = {
- 'track_id': item.id,
- 'type': item.good_status === 0 ? 1 : 2 // 类型(1点赞2取消点赞)
- }
- if (this.data.booLock) {
- return
- }
- this.setData({
- booLock: true
- })
- try {
- const { status, msg } = await postGood(postData)
- if (status) {
- wx.showToast({
- title: item.good_status === 0 ? '已点赞' : '已取消点赞',
- icon: 'none'
- })
- this.setData({
- ['listData[' + index + '].good_status']: item.good_status === 0 ? 1 : 0,
- ['listData[' + index + '].good_count']: item.good_status === 0 ? item.good_count + 1 : item.good_count - 1
- })
- } else {
- wx.showToast({
- title: msg,
- icon: 'none'
- })
- }
- } catch (err) {}
- this.setData({
- booLock: false
- })
- },
- jumpAddNews() {
- wx.navigateTo({
- url: '/pages/addNews/addNews'
- })
- }
- })
|