product.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. isFollow:{
  25. type:Boolean,
  26. value:false
  27. }
  28. },
  29. /**
  30. * 组件的初始数据
  31. */
  32. data: {
  33. imgHttp:app.globalData.imghttp,
  34. concernType:{
  35. '0':'myIconicon-test',//黑
  36. '1':'myIconanquanbangzhu',//白
  37. '2':'myIcongroup43'//灰
  38. },
  39. menu:[
  40. {
  41. label:'收藏的专利',
  42. method:'selectCollectPatent'
  43. }
  44. ],
  45. show:false
  46. },
  47. /**
  48. * 组件的方法列表
  49. */
  50. methods: {
  51. moreMenu: function (e) {
  52. var {index} = e.currentTarget.dataset
  53. var dom = this.selectComponent('#myPopover'+index)
  54. dom.showMenu()
  55. },
  56. // 响应popover组件中的子元素点击事件
  57. onClickA: function (e) {
  58. const {item,index} = e.currentTarget.dataset
  59. console.log(item,index)
  60. // 调用自定义组件 popover 中的 onHide 方法
  61. this[item.method](index)
  62. var dom = this.selectComponent('#myPopover'+index)
  63. dom.showMenu()
  64. },
  65. //查询已收藏的专利
  66. selectCollectPatent(index){
  67. var product = this.data.tableData[index]
  68. wx.navigateTo({
  69. url: '/pages/collectPatent/collectPatent?productId='+product.assoId,
  70. })
  71. },
  72. //查看图片
  73. previewImage(e) {
  74. const { current,imglist } = e.currentTarget.dataset
  75. var imgs = []
  76. for(var i =0;i<imglist.length;i++){
  77. imgs.push(this.data.imgHttp + imglist[i].guid)
  78. }
  79. current = this.data.imgHttp + current
  80. wx.previewImage({
  81. current,
  82. urls:imgs,
  83. })
  84. },
  85. //打开关注类型
  86. open(e){
  87. var key = api.isLogin()
  88. if(!key){
  89. return false
  90. }
  91. var index = e.currentTarget.dataset.index
  92. this.setData({
  93. ['tableData['+ index + '].show'] : true
  94. })
  95. },
  96. //关闭关注类型
  97. cancel(e){
  98. var index = e.currentTarget.dataset.index
  99. this.setData({
  100. ['tableData['+ index + '].show'] : false
  101. })
  102. },
  103. //关注
  104. attention(e){
  105. var {type,index} = e.currentTarget.dataset
  106. var product = this.data.tableData[index]
  107. var params = {
  108. productId:product.id,
  109. concernType:type
  110. }
  111. wx.showLoading({
  112. title: '加载中',
  113. })
  114. api.follow(params).then(res=>{
  115. if(res.code == 200){
  116. var obj = {
  117. type: 'success',
  118. message: '关注成功',
  119. }
  120. if(this.properties.isFollow){
  121. obj.top = wx.getStorageSync('height')
  122. }
  123. api.notify(obj)
  124. this.setData({
  125. ['tableData['+ index + '].show'] : false,
  126. ['tableData['+ index + '].concernType'] : type,
  127. })
  128. }
  129. })
  130. },
  131. //取消关注
  132. cancelFollow(e){
  133. var key = api.isLogin()
  134. if(!key){
  135. return false
  136. }
  137. wx.showModal({
  138. title: '提示',
  139. content: '确认取消关注?',
  140. complete: (res) => {
  141. if (res.cancel) {}
  142. if (res.confirm) {
  143. var index = e.currentTarget.dataset.index
  144. var product = this.data.tableData[index]
  145. var params = {
  146. productId:product.id
  147. }
  148. api.unFollow(params).then(res=>{
  149. if(res.code == 200){
  150. var obj = {
  151. type: 'success',
  152. message: '取关成功',
  153. }
  154. if(this.properties.isFollow){
  155. obj.top = wx.getStorageSync('height')
  156. this.triggerEvent('cancelFollow',index)
  157. }
  158. api.notify(obj)
  159. this.setData({
  160. ['tableData['+ index + '].concernType'] : null
  161. })
  162. }
  163. })
  164. }
  165. }
  166. })
  167. },
  168. //监控
  169. control(e){
  170. var index = e.currentTarget.dataset.index
  171. wx.showModal({
  172. title: '提示',
  173. content: '敬请期待!',
  174. complete: (res) => {
  175. if (res.cancel) {}
  176. if (res.confirm) {}
  177. }
  178. })
  179. },
  180. //加载更多
  181. loadMore(){
  182. this.triggerEvent('loadMore')
  183. },
  184. //查看爆款产品专利
  185. checkMessage(e){
  186. var key = api.isLogin()
  187. if(!key){
  188. return false
  189. }
  190. var data = e.currentTarget.dataset.item
  191. var product = '{}'
  192. if(data){
  193. product = JSON.stringify(data)
  194. }
  195. var type = 1
  196. wx.navigateTo({
  197. url: '/pages/searchResults/searchResults?type='+type+'&product='+encodeURIComponent(product),
  198. })
  199. },
  200. },
  201. /**
  202. * 组件的生命周期函数列表
  203. */
  204. lifetimes: {
  205. // 在组件实例进入页面节点树时执行
  206. attached: function () {
  207. // 初始化操作
  208. // ...
  209. },
  210. // 在组件实例被移除出页面节点树时执行
  211. detached: function () {
  212. // 清理工作
  213. console.log('组件销毁');
  214. // ...
  215. },
  216. // ...
  217. },
  218. })