search.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/search/search.js
  2. import {searchList, getFireList} from '../../config/api'
  3. import util from '../../utils/util'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. showClear: false,
  10. showDepSuccess: false,
  11. keyword: '',
  12. showRet: false,
  13. departments: [],
  14. projects: [],
  15. depProjects: []
  16. },
  17. async depClick(ev) {
  18. this.setData({showDepSuccess: true})
  19. this.setData({keyword: ev.currentTarget.dataset.keyword})
  20. let res = await util.request(getFireList, {
  21. pageNum: 1,
  22. organizerDeptId: ev.currentTarget.dataset.id,
  23. pageSize: 10000000000
  24. }, 'POST')
  25. this.setData({depProjects: this.formBrandList(res.data.list)})
  26. },
  27. formBrandList(data) {
  28. return data.map(item => {
  29. let icon = ~item.projectSite.indexOf('非建构筑物') ? '/static/images/fire_other.png' :
  30. ~item.projectSite.indexOf('交通工具') ? '/static/images/fire_bus.png' :
  31. ~item.projectSite.indexOf('垃圾及废弃物') ? '/static/images/fire_recycle.png' : '/static/images/fire_building.png'
  32. return {
  33. ...item,
  34. icon,
  35. createTime: item.createTime.substr(0, 11)
  36. }
  37. })
  38. },
  39. onShow() {
  40. if (this.options.keyword) {
  41. this.inputChange({detail: {value: this.options.keyword}})
  42. }
  43. },
  44. clearKeyword() {
  45. this.setData({
  46. keyword: ''
  47. })
  48. this.setData({showClear: false, showDepSuccess: false, projects: [], departments: []})
  49. this.search()
  50. },
  51. gotoWV: function (event) {
  52. let {
  53. id,
  54. scene
  55. } = event.currentTarget.dataset
  56. if (!scene) {
  57. return wx.showToast({
  58. icon: 'none',
  59. title: '暂无VR数据,无法查看',
  60. })
  61. }
  62. wx.navigateTo({
  63. url: `/pages/webview/index?id=${id}&scene=${scene}`,
  64. // url: `/pages/reserve/reserve?id=${id}`
  65. })
  66. },
  67. inputChange: function (e) {
  68. let val = e.detail.value
  69. this.setData({
  70. keyword: val
  71. })
  72. this.setData({showClear: !!val.length})
  73. if (val) {
  74. this.search()
  75. } else {
  76. this.clearKeyword()
  77. }
  78. },
  79. async search() {
  80. this.setData({showRet: false})
  81. let data = await util.request(searchList, {key: this.data.keyword}, 'GET')
  82. let projects = data.data.projects.map(item => {
  83. let showTitle = '<div>' + item.projectName.split(this.data.keyword).join('<span style="color: #26559B">' + this.data.keyword + '</span>') + '</div>'
  84. return { ...item, showTitle}
  85. })
  86. let departments = data.data.departments.map(item => {
  87. let showTitle = '<div>' + item.name.split(this.data.keyword).join('<span style="color: #26559B">' + this.data.keyword + '</span>') + '</div>'
  88. return { ...item, showTitle}
  89. })
  90. this.setData({projects: projects, showRet: true})
  91. this.setData({departments: departments})
  92. },
  93. tapHandle(e) {
  94. let prev = getCurrentPages()[getCurrentPages().length - 2]
  95. prev.inputChange.call(prev, {detail: {value: e.currentTarget.dataset.keyword}})
  96. wx.navigateBack()
  97. }
  98. })