| | |
| | | import { |
| | | shareContent, |
| | | getProductInfo, |
| | | actionDo |
| | | actionDo, |
| | | refreshEnjoy |
| | | } from '../../api/index' |
| | | import moment from "moment"; |
| | | Page({ |
| | |
| | | */ |
| | | data: { |
| | | bottomLift: 0, |
| | | current: 0, |
| | | id: '', |
| | | info: {}, |
| | | spaceList: [], |
| | | member: {}, |
| | | showShare: false |
| | | showShare: false, |
| | | isFold: false, |
| | | enjoyList: [] |
| | | }, |
| | | onShow(){ |
| | | console.log('onShow') |
| | | refreshEnjoy(this) |
| | | }, |
| | | onHide() { |
| | | console.log('onHide') |
| | | }, |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | |
| | | member |
| | | }) |
| | | }, |
| | | |
| | | // 组件事件 |
| | | handleEnjoy(e) { |
| | | const info = this.data.info |
| | | if(info.id == null ){ |
| | | return |
| | | } |
| | | const enjoyList = wx.getStorageSync('enjoyList') || [] |
| | | const { type, flag } = e.detail |
| | | console.log('type', type); |
| | | console.log('flag', flag); |
| | | const info = this.data.info |
| | | console.log('flag', flag); |
| | | if(type == 'enjoy'){ |
| | | // 点击了喜欢 |
| | | const index = enjoyList.findIndex( i => i.id === info.id ) |
| | |
| | | this.setData({ info }) |
| | | enjoyList.push({ |
| | | ...info, |
| | | joinType: 'product', |
| | | joinType: '0', |
| | | timestamp: new Date().getTime() |
| | | }) |
| | | }else{ |
| | |
| | | enjoyList.splice(index, 1) |
| | | } |
| | | wx.setStorageSync('enjoyList', enjoyList) |
| | | refreshEnjoy(this) |
| | | }else{ |
| | | actionDo({ |
| | | id: info.id, |
| | | actionType: flag ? 'collect' : 'collect_cancel' |
| | | }).then(res => { |
| | | info.isCollection = flag |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏'}) |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏', icon: 'none'}) |
| | | this.setData({ |
| | | info |
| | | }) |
| | | wx.setStorageSync('conentCountTemp', this.data.info) |
| | | }) |
| | | } |
| | | }, |
| | | handleAction(e) { |
| | | const actionType = e.currentTarget.dataset.code |
| | | priviewBanner(e) { |
| | | const url = e.currentTarget.dataset.url |
| | | const { |
| | | info |
| | | } = this.data |
| | | actionDo({ |
| | | actionType, |
| | | id: this.data.info.id |
| | | }).then(res => { |
| | | info.isCollection = !info.isCollection |
| | | this.setData({ |
| | | info |
| | | }) |
| | | wx.showToast({ |
| | | title: actionType == 'collect' ? '收藏成功' : '取消收藏', |
| | | }) |
| | | wx.previewImage({ |
| | | urls: info.bannerImgList, |
| | | current: url |
| | | }) |
| | | }, |
| | | bindchange(e) { |
| | | this.setData({ current: e.detail.current }) |
| | | }, |
| | | priviewSpace(e) { |
| | | return |
| | | const url = e.currentTarget.dataset.url |
| | | const { |
| | | info |
| | | } = this.data |
| | | wx.previewImage({ |
| | | urls: info.spaceList.map(i => i.spaceImg), |
| | | current: url |
| | | }) |
| | | }, |
| | | onShareAppMessage() { |
| | |
| | | getProductInfo({ |
| | | id |
| | | }).then(res => { |
| | | const index = enjoyList.findIndex( i => i.id === res.data.id ) |
| | | const index = enjoyList.findIndex( i =>(res.data && i.id === res.data.id) ) |
| | | this.setData({ |
| | | spaceList: res.data.spaceList || [], |
| | | info: { |
| | | ...res.data, |
| | | isEnjoy: index > -1 |
| | | } |
| | | }) |
| | | const { info} = this.data |
| | | wx.setStorageSync('conentCountTemp', info) |
| | | wx.setNavigationBarTitle({ |
| | | title: res.data.title |
| | | }) |
| | |
| | | // this.setData({showShare: false}) |
| | | // }) |
| | | }, |
| | | changeFold() { |
| | | this.setData({ isFold: !this.data.isFold }) |
| | | }, |
| | | // onShareAppMessage: function () { |
| | | // // let { productDetail, userInfo } = this.data |
| | | // return { |
| | | // title: productDetail.title, |
| | | // path: '/pages/index/index?id=' + productDetail.id + '&shareuserid=' + userInfo.id + '&type=0' |
| | | // } |
| | | // }, |
| | | onClose() { |
| | | this.setData({ |
| | | showShare: false |
| | | }) |
| | | }, |
| | | // }, |
| | | handleDown() { |
| | | let { |
| | | info |
| | |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | |
| | | } |
| | | }) |