123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // pages/search/search.js
- import {searchList, getFireList} from '../../config/api'
- import util from '../../utils/util'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showClear: false,
- showDepSuccess: false,
- keyword: '',
- showRet: false,
- departments: [],
- projects: [],
- depProjects: []
- },
- async depClick(ev) {
- this.setData({showDepSuccess: true})
- this.setData({keyword: ev.currentTarget.dataset.keyword})
- let res = await util.request(getFireList, {
- pageNum: 1,
- organizerDeptId: ev.currentTarget.dataset.id,
- pageSize: 10000000000
- }, 'POST')
-
- this.setData({depProjects: this.formBrandList(res.data.list)})
- },
- formBrandList(data) {
- return data.map(item => {
- let icon = ~item.projectSite.indexOf('非建构筑物') ? '/static/images/fire_other.png' :
- ~item.projectSite.indexOf('交通工具') ? '/static/images/fire_bus.png' :
- ~item.projectSite.indexOf('垃圾及废弃物') ? '/static/images/fire_recycle.png' : '/static/images/fire_building.png'
- return {
- ...item,
- icon,
- createTime: item.createTime.substr(0, 11)
- }
- })
- },
- onShow() {
- if (this.options.keyword) {
- this.inputChange({detail: {value: this.options.keyword}})
- }
- },
- clearKeyword() {
- this.setData({
- keyword: ''
- })
-
- this.setData({showClear: false, showDepSuccess: false, projects: [], departments: []})
- this.search()
- },
-
- gotoWV: function (event) {
- let {
- id,
- scene
- } = event.currentTarget.dataset
- if (!scene) {
- return wx.showToast({
- icon: 'none',
- title: '暂无VR数据,无法查看',
- })
- }
-
- wx.navigateTo({
- url: `/pages/webview/index?id=${id}&scene=${scene}`,
- // url: `/pages/reserve/reserve?id=${id}`
- })
- },
- inputChange: function (e) {
- let val = e.detail.value
- this.setData({
- keyword: val
- })
- this.setData({showClear: !!val.length})
- if (val) {
- this.search()
- } else {
- this.clearKeyword()
- }
-
- },
- async search() {
- this.setData({showRet: false})
- let data = await util.request(searchList, {key: this.data.keyword}, 'GET')
- let projects = data.data.projects.map(item => {
- let showTitle = '<div>' + item.projectName.split(this.data.keyword).join('<span style="color: #26559B">' + this.data.keyword + '</span>') + '</div>'
- return { ...item, showTitle}
- })
- let departments = data.data.departments.map(item => {
- let showTitle = '<div>' + item.name.split(this.data.keyword).join('<span style="color: #26559B">' + this.data.keyword + '</span>') + '</div>'
- return { ...item, showTitle}
- })
- this.setData({projects: projects, showRet: true})
- this.setData({departments: departments})
- },
- tapHandle(e) {
- let prev = getCurrentPages()[getCurrentPages().length - 2]
- prev.inputChange.call(prev, {detail: {value: e.currentTarget.dataset.keyword}})
- wx.navigateBack()
- }
- })
|