collectPatent.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // pages/collectPatent/collectPatent.js
  2. const app = getApp()
  3. const api = require('../../api/index')
  4. const showImage = require('../../utils/showImage')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgHttp:app.globalData.imghttp,
  11. tableData:[],
  12. queryParams:{
  13. size:10,
  14. current:1
  15. },
  16. total:0,
  17. id:null,
  18. triggered:false,
  19. load:false,
  20. hasMore:true
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. this.setData(
  27. {
  28. id:options.productId
  29. }
  30. )
  31. this.init()
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow() {
  42. },
  43. /**
  44. * 页面功能
  45. */
  46. //初始化加载
  47. init(){
  48. var params = {
  49. current:1,
  50. size:10
  51. }
  52. this.setData(
  53. {
  54. queryParams:params,
  55. total:0,
  56. tableData:[],
  57. hasMore:true
  58. }
  59. )
  60. this.selectCollectPatent()
  61. },
  62. //下拉刷新
  63. onRefresh() {
  64. console.log('onRefresh')
  65. this.setData({
  66. triggered: true,
  67. })
  68. this.init()
  69. },
  70. //查看图片
  71. previewImage(e) {
  72. console.log(e)
  73. var { current,imglist } = e.currentTarget.dataset
  74. var imgs = []
  75. for(var i =0;i<imglist.length;i++){
  76. imgs.push(this.data.imgHttp + imglist[i].guid)
  77. }
  78. current = this.data.imgHttp + current
  79. showImage.showImageList(
  80. {
  81. current,
  82. urls: imgs.map((n) => ({ image: n, remark: n })),
  83. indicatorDots: true,
  84. indicatorColor: '#fff',
  85. indicatorActiveColor: '#04BE02',
  86. showDelete:false
  87. }
  88. )
  89. },
  90. //获取收藏的专利
  91. selectCollectPatent(type){
  92. if(!this.data.id){
  93. return false
  94. }
  95. var params = {
  96. ...this.data.queryParams,
  97. assoPersonProductId:this.data.id
  98. }
  99. wx.showLoading({
  100. title: '加载中',
  101. })
  102. api.selectCollectPatent(params).then(res=>{
  103. if(res.code == 200){
  104. var len1 = this.data.tableData.length
  105. var len = len1>0?len1: 0
  106. var data = this.data.tableData.concat(res.data.data)
  107. this.setData(
  108. {
  109. tableData:data,
  110. total:res.data.total,
  111. triggered: false,
  112. load:false
  113. }
  114. )
  115. if(this.data.total<=data.length){
  116. this.setData({
  117. hasMore:false
  118. })
  119. }
  120. for(let i = 0;i<res.data.data.length;i++){
  121. this.getPictureByNo(res.data.data[i],len)
  122. len += 1
  123. }
  124. // res.data.data(item=>{
  125. // this.getPictureByNo(item,len)
  126. // len += 1
  127. // })
  128. }
  129. }).catch(error=>{
  130. this.setData({
  131. triggered: false,
  132. load:false
  133. })
  134. })
  135. },
  136. //根据专利号获取相关图片
  137. getPictureByNo(data,index){
  138. var params = {
  139. appNo:data.appNo
  140. }
  141. api.getPictureByNo(params).then(res=>{
  142. if(res.code == 200){
  143. this.setData(
  144. {
  145. ["tableData["+index+"].imageList"]:res.data
  146. }
  147. )
  148. }
  149. })
  150. },
  151. //查看专利详情
  152. checkPatentDetail(e){
  153. var {patentno} = e.currentTarget.dataset
  154. wx.navigateTo({
  155. url: '/pages/patentDetails/patentDetails?patentNo='+patentno,
  156. })
  157. },
  158. //加载更多
  159. loadMore(){
  160. var current = this.data.queryParams.current
  161. this.setData(
  162. {
  163. ['queryParams.current']:current+1,
  164. load :true
  165. }
  166. )
  167. this.selectCollectPatent()
  168. },
  169. /**
  170. * 生命周期函数--监听页面隐藏
  171. */
  172. onHide() {
  173. },
  174. /**
  175. * 生命周期函数--监听页面卸载
  176. */
  177. onUnload() {
  178. },
  179. /**
  180. * 页面相关事件处理函数--监听用户下拉动作
  181. */
  182. onPullDownRefresh() {
  183. },
  184. /**
  185. * 页面上拉触底事件的处理函数
  186. */
  187. onReachBottom() {
  188. },
  189. /**
  190. * 用户点击右上角分享
  191. */
  192. onShareAppMessage() {
  193. }
  194. })