searchResults.js 11 KB

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