searchResults.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. // pages/searchResults/searchResults.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. phone:app.globalData.phone,
  12. queryParams:{
  13. current:1,
  14. size:10
  15. },
  16. ifAddSearchRecord:true,
  17. total:0,
  18. loading:false,
  19. tableData:[],
  20. keyword:'',
  21. searchType:1,//检索类型1是爆款产品0是手动检索
  22. product:{},//产品信息
  23. patentNoList:[],
  24. patentList:[],
  25. buttons:[
  26. {
  27. label: '人工服务',
  28. method:'check',
  29. icon:'/static/image/工单.png'
  30. },
  31. {
  32. label: '一键导出',
  33. method:'export',
  34. icon:'/static/image/导出.png'
  35. },
  36. {
  37. label:'人工客服',
  38. method:'makePhoneCall',
  39. icon:'/static/image/人工客服.png'
  40. }
  41. ],
  42. concernType:{
  43. '0':'myIconicon-test',//黑
  44. '1':'myIconanquanbangzhu',//白
  45. '2':'myIcongroup43'//灰
  46. },
  47. showDialog:false,
  48. followType:null,
  49. isAdd:false,
  50. triggered:false,
  51. load:false,
  52. hasMore:true
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad(options) {
  58. var data = JSON.parse(decodeURIComponent(options.product))
  59. this.setData(
  60. {
  61. searchType:options.type,
  62. product:data,
  63. keyword:data.key
  64. }
  65. )
  66. console.log(this.data.product)
  67. this.init()
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow() {
  78. },
  79. /**
  80. * 页面功能
  81. */
  82. //初始化加载
  83. init(){
  84. var params = {
  85. current:1,
  86. size:10
  87. }
  88. this.setData(
  89. {
  90. queryParams:params,
  91. total:0,
  92. tableData:[],
  93. patentNoList:[],
  94. patentList:[],
  95. hasMore:true
  96. }
  97. )
  98. this.getPatentVectors()
  99. },
  100. //下拉刷新
  101. onRefresh() {
  102. console.log('onRefresh')
  103. this.setData({
  104. triggered: true,
  105. })
  106. this.init()
  107. },
  108. //查看图片
  109. previewImage(e) {
  110. console.log(e)
  111. var { current,imglist } = e.currentTarget.dataset
  112. var imgs = []
  113. for(var i =0;i<imglist.length;i++){
  114. imgs.push(this.data.imgHttp + imglist[i].guid)
  115. }
  116. current = this.data.imgHttp + current
  117. showImage.showImageList(
  118. {
  119. current,
  120. urls: imgs.map((n) => ({ image: n, remark: n })),
  121. indicatorDots: true,
  122. indicatorColor: '#fff',
  123. indicatorActiveColor: '#04BE02',
  124. showDelete:false
  125. }
  126. )
  127. },
  128. //修改输入的关键词
  129. changeKeyword(e){
  130. this.setData(
  131. {
  132. keyword:e.detail
  133. }
  134. )
  135. },
  136. //切换检索类型
  137. changeSearchType(e){
  138. console.log(e)
  139. var field = e.detail
  140. var str = this.data.product[field] || ''
  141. this.setData(
  142. {
  143. keyword:str
  144. }
  145. )
  146. },
  147. //点击搜索按钮
  148. search(e){
  149. console.log(e)
  150. var {value,field,lastField,filePath} = e.detail
  151. if(lastField){
  152. this.setData(
  153. {
  154. ["product."+lastField]:''
  155. }
  156. )
  157. }
  158. this.setData(
  159. {
  160. ["product."+field]:value,
  161. ["product.filePath"]:filePath,
  162. ifAddSearchRecord:true,
  163. concernType:null
  164. }
  165. )
  166. this.init()
  167. },
  168. //查询产品相关专利
  169. getPatentVectors(){
  170. console.log(this.data.product)
  171. var params = {
  172. pageNum:this.data.queryParams.current,
  173. pageSize:this.data.queryParams.size,
  174. ifAddSearchRecord:this.data.ifAddSearchRecord
  175. }
  176. if(this.data.searchType == 1){
  177. params.productId = this.data.product.id
  178. }else{
  179. params.description = this.data.product.description
  180. }
  181. params.key = this.data.product.key
  182. params.companyName = this.data.product.companyName
  183. var vectorDTO = JSON.stringify(params)
  184. var url = 'getPatentVectors'
  185. var data = {
  186. vectorDTO:vectorDTO
  187. }
  188. if(this.data.product.filePath){
  189. url = "getPatentVectorsByImage"
  190. }
  191. wx.showLoading({
  192. title: '加载中',
  193. })
  194. api[url](data,this.data.product.filePath).then(res=>{
  195. if(res.code == 200){
  196. console.log(res)
  197. var len1 = this.data.tableData.length
  198. var len = len1>0?len1: 0
  199. var data = this.data.tableData.concat(res.data.data)
  200. this.setData(
  201. {
  202. tableData:data,
  203. total:res.data.total,
  204. ifAddSearchRecord:false,
  205. triggered: false,
  206. load:false
  207. }
  208. )
  209. if(this.data.total<=data.length){
  210. this.setData({
  211. hasMore:false
  212. })
  213. }
  214. for(let i = 0;i<res.data.data.length;i++){
  215. this.getPictureByNo(res.data.data[i],len)
  216. len += 1
  217. }
  218. // res.data.data(item=>{
  219. // this.getPictureByNo(item,len)
  220. // len += 1
  221. // })
  222. }
  223. }).catch(error=>{
  224. this.setData({
  225. triggered: false,
  226. load:false
  227. })
  228. })
  229. },
  230. //根据专利号获取相关图片
  231. getPictureByNo(data,index){
  232. var params = {
  233. appNo:data.appNo
  234. }
  235. api.getPictureByNo(params).then(res=>{
  236. if(res.code == 200){
  237. this.setData(
  238. {
  239. ["tableData["+index+"].imageList"]:res.data
  240. }
  241. )
  242. }
  243. })
  244. },
  245. //加载更多
  246. loadMore(){
  247. var current = this.data.queryParams.current
  248. this.setData(
  249. {
  250. ['queryParams.current']:current+1,
  251. load :true
  252. }
  253. )
  254. this.getPatentVectors()
  255. },
  256. //查看专利详情
  257. checkPatentDetail(e){
  258. var {patentno} = e.currentTarget.dataset
  259. wx.navigateTo({
  260. url: '/pages/patentDetails/patentDetails?patentNo='+patentno,
  261. })
  262. },
  263. //选择专利
  264. changePatentNoList(event) {
  265. console.log(event)
  266. var {item,patentno} = event.currentTarget.dataset
  267. var data = event.detail
  268. var patent = this.data.patentList
  269. var index = data.indexOf(patentno)
  270. if(index == -1){
  271. var index1 = patent.findIndex(item=>{
  272. return item.patentno == patentno
  273. })
  274. patent.splice(index1,1)
  275. }else{
  276. patent.push(item)
  277. }
  278. this.setData({
  279. patentNoList: event.detail,
  280. patentList:patent
  281. });
  282. },
  283. onchange(e){
  284. console.log(1)
  285. },
  286. //查看已选择的专利
  287. clickButton(e){
  288. console.log(e)
  289. var that = this
  290. wx.navigateTo({
  291. url: '/pages/selectedPatents/selectedPatents',
  292. events: {
  293. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  294. acceptDataFromOpenedPage: function(data) {
  295. console.log(data)
  296. },
  297. someEvent: function(data) {
  298. console.log(data)
  299. }
  300. },
  301. success: function(res) {
  302. // 通过eventChannel向被打开页面传送数据
  303. res.eventChannel.emit('acceptDataFromOpenerPage', { data: that.data.patentList,patentNoList:that.data.patentNoList })
  304. }
  305. })
  306. },
  307. //关注产品
  308. open(){
  309. this.setData(
  310. {
  311. showDialog:true
  312. }
  313. )
  314. },
  315. //取消关注
  316. closeDialog(){
  317. this.setData(
  318. {
  319. showDialog:false,
  320. followType:null,
  321. }
  322. )
  323. },
  324. //关注类型
  325. attention(e){
  326. var {type} = e.currentTarget.dataset
  327. this.setData(
  328. {
  329. followType:type
  330. }
  331. )
  332. },
  333. //是否收藏
  334. changeIsAdd(e){
  335. this.setData(
  336. {
  337. isAdd:e.detail
  338. }
  339. )
  340. console.log(e)
  341. },
  342. //确认关注
  343. confirm(){
  344. console.log(this.data.followType)
  345. if(this.data.followType != 0 && !this.data.followType){
  346. api.notify(
  347. {
  348. type:'warning',
  349. message:'请选择关注类型',
  350. top:wx.getStorageSync('height')
  351. }
  352. )
  353. return false
  354. }
  355. var that = this
  356. if(this.data.searchType == 0){
  357. console.log(1)
  358. wx.navigateTo({
  359. url: `/pages/form/addProduct/addProduct`,
  360. success: function(res) {
  361. // 通过eventChannel向被打开页面传送数据
  362. var data = {
  363. ...that.data.product,
  364. concernType:that.data.followType
  365. }
  366. res.eventChannel.emit('acceptDataFromOpenerPage', data)
  367. }
  368. })
  369. return false
  370. }
  371. var params = {
  372. productId:this.data.product.id,
  373. concernType:this.data.followType
  374. }
  375. wx.showLoading({
  376. title: '加载中',
  377. })
  378. api.follow(params).then(res=>{
  379. if(res.code == 200){
  380. var obj = {
  381. type: 'success',
  382. message: '关注成功',
  383. top:wx.getStorageSync('height')
  384. }
  385. api.notify(obj)
  386. that.setData({
  387. ['product.concernType'] : that.data.followType,
  388. })
  389. that.closeDialog()
  390. // console.log(that.data.isAdd,this.data.patentNoList)
  391. this.collectPatent()
  392. }
  393. })
  394. },
  395. //收藏专利
  396. collectPatent(){
  397. if(this.data.isAdd ){
  398. this.setData(
  399. {
  400. idAdd:false
  401. }
  402. )
  403. if(this.data.patentNoList && this.data.patentNoList.length>0){
  404. var params1 = {
  405. productId:this.data.product.id,
  406. patentNos:this.data.patentNoList
  407. }
  408. api.collectPatent(params1).then(res=>{
  409. if(res.code == 200){
  410. }
  411. })
  412. }
  413. }
  414. },
  415. //取消关注
  416. cancelFollow(e){
  417. if(!this.data.product.id){
  418. return false
  419. }
  420. wx.showModal({
  421. title: '提示',
  422. content: '确认取消关注?',
  423. complete: (res) => {
  424. if (res.cancel) {}
  425. if (res.confirm) {
  426. var product = this.data.product
  427. var params = {
  428. productId:product.id
  429. }
  430. wx.showLoading({
  431. title: '取消中',
  432. })
  433. api.unFollow(params).then(res=>{
  434. if(res.code == 200){
  435. var obj = {
  436. type: 'success',
  437. message: '取关成功',
  438. }
  439. if(this.properties.isFollow){
  440. obj.top = wx.getStorageSync('height')
  441. }
  442. api.notify(obj)
  443. this.setData({
  444. ['product.concernType'] : null
  445. })
  446. if(this.data.searchType == 0){
  447. this.setData({
  448. ['product.id'] : null
  449. })
  450. }
  451. }
  452. })
  453. }
  454. }
  455. })
  456. },
  457. //监控
  458. control(e){
  459. // var index = e.currentTarget.dataset.index
  460. wx.showModal({
  461. title: '提示',
  462. content: '敬请期待!',
  463. complete: (res) => {
  464. if (res.cancel) {}
  465. if (res.confirm) {}
  466. }
  467. })
  468. },
  469. //点击button
  470. onClick(e){
  471. console.log(e)
  472. var btn = e.detail.value
  473. this[btn.method]()
  474. },
  475. //导出
  476. export(){
  477. if(!this.data.patentNoList || this.data.patentNoList.length==0){
  478. wx.showToast({
  479. title: '您未选择专利!',
  480. icon:'none',
  481. duration: 2000
  482. })
  483. return false
  484. }
  485. var params = {
  486. patentNos:this.data.patentNoList
  487. }
  488. wx.showLoading({
  489. title: '导出中',
  490. })
  491. var that = this
  492. api.exportPatent(params).then(res=>{
  493. if(res.code == 200){
  494. var url = that.data.imgHttp + res.data.data
  495. wx.setClipboardData({
  496. data: url,
  497. success(res) {
  498. wx.showToast({
  499. title: '复制成功,快到浏览器打开/下载!',
  500. icon: 'none',
  501. duration: 3000
  502. })
  503. }
  504. })
  505. // downLoad.downLoadFile(res.data.data).then(res=>{
  506. // })
  507. }
  508. })
  509. },
  510. //我要查风险
  511. check(){
  512. wx.navigateTo({
  513. url: '/pages/form/riskAssessment/riskAssessment',
  514. })
  515. },
  516. makePhoneCall(){
  517. wx.makePhoneCall({
  518. phoneNumber: this.data.phone
  519. })
  520. },
  521. /**
  522. * 生命周期函数--监听页面隐藏
  523. */
  524. onHide() {
  525. },
  526. /**
  527. * 生命周期函数--监听页面卸载
  528. */
  529. onUnload() {
  530. },
  531. /**
  532. * 页面相关事件处理函数--监听用户下拉动作
  533. */
  534. onPullDownRefresh() {
  535. },
  536. /**
  537. * 页面上拉触底事件的处理函数
  538. */
  539. onReachBottom() {
  540. },
  541. /**
  542. * 用户点击右上角分享
  543. */
  544. onShareAppMessage() {
  545. }
  546. })