| | |
| | | // pages/detailDis/product.js |
| | | import { |
| | | shareContent, |
| | | getProductInfo, |
| | | actionDo, |
| | | refreshEnjoy |
| | | } from '../../api/index' |
| | | import moment from "moment"; |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | bottomLift: 0 |
| | | bottomLift: 0, |
| | | current: 0, |
| | | id: '', |
| | | info: {}, |
| | | spaceList: [], |
| | | member: {}, |
| | | showShare: false, |
| | | isFold: false, |
| | | enjoyList: [] |
| | | }, |
| | | |
| | | onShow(){ |
| | | console.log('onShow') |
| | | refreshEnjoy(this) |
| | | }, |
| | | onHide() { |
| | | console.log('onHide') |
| | | }, |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | |
| | | this.setData({ |
| | | bottomLift: app.bottomLift |
| | | }) |
| | | this.getDetail(options.id) |
| | | actionDo({ |
| | | actionType: 'view', |
| | | id: options.id |
| | | }) |
| | | const member = wx.getStorageSync('member') |
| | | this.setData({ |
| | | id: options.id, |
| | | member |
| | | }) |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面初次渲染完成 |
| | | */ |
| | | onReady() { |
| | | |
| | | |
| | | // 组件事件 |
| | | 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); |
| | | if(type == 'enjoy'){ |
| | | // 点击了喜欢 |
| | | const index = enjoyList.findIndex( i => i.id === info.id ) |
| | | if(index === -1){ |
| | | info.isEnjoy = true |
| | | this.setData({ info }) |
| | | enjoyList.push({ |
| | | ...info, |
| | | joinType: '0', |
| | | timestamp: new Date().getTime() |
| | | }) |
| | | }else{ |
| | | info.isEnjoy = false |
| | | this.setData({ info }) |
| | | 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 ? '收藏成功' : '取消收藏', icon: 'none'}) |
| | | this.setData({ |
| | | info |
| | | }) |
| | | wx.setStorageSync('conentCountTemp', this.data.info) |
| | | }) |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | |
| | | priviewBanner(e) { |
| | | const url = e.currentTarget.dataset.url |
| | | const { |
| | | info |
| | | } = this.data |
| | | 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() { |
| | | console.log('用户点击了分享'); |
| | | }, |
| | | getDetail(id) { |
| | | const enjoyList = wx.getStorageSync('enjoyList') || [] |
| | | getProductInfo({ |
| | | id |
| | | }).then(res => { |
| | | 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 |
| | | }) |
| | | }) |
| | | }, |
| | | playVideo() { |
| | | wx.previewMedia({ |
| | | sources: [{ |
| | | url: this.data.info.video, |
| | | type: 'video' |
| | | }] |
| | | }) |
| | | }, |
| | | bannerbindload(e) { |
| | | const { |
| | | height, |
| | | width |
| | | } = e.detail |
| | | let activeHeight = height * 670 / width |
| | | this.setData({ |
| | | bannerHeight: activeHeight |
| | | }) |
| | | }, |
| | | handleDesign() { |
| | | wx.navigateTo({ |
| | | url: '/pages/design/design', |
| | | }) |
| | | }, |
| | | openShare() { |
| | | this.setData({ |
| | | showShare: true |
| | | }) |
| | | }, |
| | | handleShare() { |
| | | console.log('点击了分享'); |
| | | actionDo({ |
| | | actionType: 'share', |
| | | id: this.data.info.id |
| | | }) |
| | | // shareContent({id: this.data.info.id || this.data.id}).then(res => { |
| | | // 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' |
| | | // } |
| | | // }, |
| | | handleDown() { |
| | | let { |
| | | info |
| | | } = this.data |
| | | wx.showToast({ |
| | | title: '下载中', |
| | | icon: 'loading' |
| | | }) |
| | | console.log('info.picUrls', info) |
| | | wx.downloadFile({ |
| | | url: info.picUrls, |
| | | success(res) { |
| | | // console.log(res) |
| | | wx.saveImageToPhotosAlbum({ |
| | | filePath: res.tempFilePath, |
| | | success(data) { |
| | | that.toSaveCaseShare() |
| | | wx.showToast({ |
| | | title: '下载成功', |
| | | }) |
| | | }, |
| | | fail(error) { |
| | | console.log(error) |
| | | wx.showToast({ |
| | | title: '下载失败', |
| | | icon: 'error' |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | fail(err) { |
| | | console.log(err.errMsg) |
| | | wx.showToast({ |
| | | title: '下载失败', |
| | | icon: 'error' |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | onHide() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面卸载 |
| | | */ |
| | | goTestPage(){ |
| | | wx.navigateTo({ |
| | | url: '/pages/webView/index', |
| | | success: function(res) { |
| | | // 通过eventChannel向被打开页面传送数据 |
| | | res.eventChannel.emit('data',{link:'http://crmtest.zhibang.com:8000/core/oauth/authorize/jump?timestamp=-465385833&agent_phone_number=18055151023&bindKey=mpAddIntention&sign=cdfe13abfe2727b40eee160085c80d11'} ); |
| | | } |
| | | }) |
| | | }, |
| | | onUnload() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 页面相关事件处理函数--监听用户下拉动作 |
| | | */ |
| | | onPullDownRefresh() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 页面上拉触底事件的处理函数 |
| | | */ |
| | | onReachBottom() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 用户点击右上角分享 |
| | | */ |
| | | onShareAppMessage() { |
| | | |
| | | } |
| | | }) |