product.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // myComponents/product/product.js
  2. const app = getApp()
  3. const api = require('../../api/index')
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. tableData:{
  10. type:Array,
  11. value:[],
  12. observers:function(val){
  13. // console.log(val)
  14. }
  15. },
  16. total:{
  17. type:Number,
  18. value:null
  19. },
  20. loading:{
  21. type:Boolean,
  22. value:false
  23. }
  24. },
  25. /**
  26. * 组件的初始数据
  27. */
  28. data: {
  29. imgHttp:app.globalData.imghttp
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. //查看图片
  36. previewImage(e) {
  37. const { current,imglist } = e.currentTarget.dataset
  38. var imgs = []
  39. for(var i =0;i<imglist.length;i++){
  40. imgs.push(this.data.imgHttp + imglist[i].guid)
  41. }
  42. current = this.data.imgHttp + current
  43. wx.previewImage({
  44. current,
  45. urls:imgs,
  46. })
  47. },
  48. //打开关注类型
  49. open(e){
  50. var index = e.currentTarget.dataset.index
  51. this.setData({
  52. ['tableData['+ index + '].show'] : true
  53. })
  54. },
  55. //关闭关注类型
  56. cancel(e){
  57. var index = e.currentTarget.dataset.index
  58. this.setData({
  59. ['tableData['+ index + '].show'] : false
  60. })
  61. },
  62. //关注
  63. attention(e){
  64. var {type,index} = e.currentTarget.dataset
  65. },
  66. //监控
  67. control(e){
  68. var index = e.currentTarget.dataset.index
  69. },
  70. //加载更多
  71. loadMore(){
  72. this.triggerEvent('loadMore')
  73. },
  74. //查看爆款产品专利
  75. checkMessage(e){
  76. var key = api.isLogin()
  77. if(!key){
  78. return false
  79. }
  80. var data = e.currentTarget.dataset.item
  81. var product = '{}'
  82. if(data){
  83. product = JSON.stringify(data)
  84. }
  85. wx.navigateTo({
  86. url: '/pages/searchResults/searchResults?type=1&product='+encodeURIComponent(product),
  87. })
  88. },
  89. },
  90. /**
  91. * 组件的生命周期函数列表
  92. */
  93. lifetimes: {
  94. // 在组件实例进入页面节点树时执行
  95. attached: function () {
  96. // 初始化操作
  97. console.log(this.properties.tableData);
  98. // ...
  99. },
  100. // 在组件实例被移除出页面节点树时执行
  101. detached: function () {
  102. // 清理工作
  103. console.log('组件销毁');
  104. // ...
  105. },
  106. // ...
  107. },
  108. })