// myComponents/product/product.js const app = getApp() const api = require('../../api/index') Component({ /** * 组件的属性列表 */ properties: { tableData:{ type:Array, value:[], observers:function(val){ // console.log(val) } }, total:{ type:Number, value:null }, loading:{ type:Boolean, value:false }, isFollow:{ type:Boolean, value:false } }, /** * 组件的初始数据 */ data: { imgHttp:app.globalData.imghttp, concernType:{ '0':'myIconicon-test',//黑 '1':'myIconanquanbangzhu',//白 '2':'myIcongroup43'//灰 }, menu:[ { label:'收藏的专利', method:'selectCollectPatent' } ], show:false }, /** * 组件的方法列表 */ methods: { moreMenu: function (e) { var {index} = e.currentTarget.dataset var dom = this.selectComponent('#myPopover'+index) dom.showMenu(!this.data.show) }, // 响应popover组件中的子元素点击事件 onClickA: function (e) { const {item,index} = e.currentTarget.dataset console.log(item,index) // 调用自定义组件 popover 中的 onHide 方法 this[item.method](index) var dom = this.selectComponent('#myPopover'+index) dom.showMenu(false) }, //查询已收藏的专利 selectCollectPatent(index){ var product = this.data.tableData[index] wx.navigateTo({ url: '/pages/collectPatent/collectPatent?productId='+product.assoId, }) }, //查看图片 previewImage(e) { const { current,imglist } = e.currentTarget.dataset var imgs = [] for(var i =0;i{ if(res.code == 200){ var obj = { type: 'success', message: '关注成功', } if(this.properties.isFollow){ obj.top = '90' } api.notify(obj) this.setData({ ['tableData['+ index + '].show'] : false, ['tableData['+ index + '].concernType'] : type, }) } }) }, //取消关注 cancelFollow(e){ var key = api.isLogin() if(!key){ return false } wx.showModal({ title: '提示', content: '确认取消关注?', complete: (res) => { if (res.cancel) {} if (res.confirm) { var index = e.currentTarget.dataset.index var product = this.data.tableData[index] var params = { productId:product.id } api.unFollow(params).then(res=>{ if(res.code == 200){ var obj = { type: 'success', message: '取关成功', } if(this.properties.isFollow){ obj.top = '90' this.triggerEvent('cancelFollow',index) } api.notify(obj) this.setData({ ['tableData['+ index + '].concernType'] : null }) } }) } } }) }, //监控 control(e){ var index = e.currentTarget.dataset.index wx.showModal({ title: '提示', content: '敬请期待!', complete: (res) => { if (res.cancel) {} if (res.confirm) {} } }) }, //加载更多 loadMore(){ this.triggerEvent('loadMore') }, //查看爆款产品专利 checkMessage(e){ var key = api.isLogin() if(!key){ return false } var data = e.currentTarget.dataset.item var product = '{}' if(data){ product = JSON.stringify(data) } var type = 1 wx.navigateTo({ url: '/pages/searchResults/searchResults?type='+type+'&product='+encodeURIComponent(product), }) }, }, /** * 组件的生命周期函数列表 */ lifetimes: { // 在组件实例进入页面节点树时执行 attached: function () { // 初始化操作 // ... }, // 在组件实例被移除出页面节点树时执行 detached: function () { // 清理工作 console.log('组件销毁'); // ... }, // ... }, })