123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- // 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()
- },
- // 响应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()
- },
- //查询已收藏的专利
- 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<imglist.length;i++){
- imgs.push(this.data.imgHttp + imglist[i].guid)
- }
- current = this.data.imgHttp + current
- wx.previewImage({
- current,
- urls:imgs,
- })
- },
- //打开关注类型
- open(e){
- var key = api.isLogin()
- if(!key){
- return false
- }
- var index = e.currentTarget.dataset.index
- this.setData({
- ['tableData['+ index + '].show'] : true
- })
- },
- //关闭关注类型
- cancel(e){
- var index = e.currentTarget.dataset.index
- this.setData({
- ['tableData['+ index + '].show'] : false
- })
- },
- //关注
- attention(e){
-
- var {type,index} = e.currentTarget.dataset
- var product = this.data.tableData[index]
- var params = {
- productId:product.id,
- concernType:type
- }
- wx.showLoading({
- title: '加载中',
- })
- api.follow(params).then(res=>{
- if(res.code == 200){
- var obj = {
- type: 'success',
- message: '关注成功',
- }
- if(this.properties.isFollow){
- obj.top = wx.getStorageSync('height')
- }
- 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 = wx.getStorageSync('height')
- 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('组件销毁');
- // ...
- },
- // ...
- },
- })
|