import Taro, { Component } from '@tarojs/taro' import { View, Image, Text, Navigator } from '@tarojs/components' import { AtSearchBar } from 'taro-ui' import ListMore from '@/c/pageDataList/listMore' import Footer from '@/c/footer' import './index.scss' import { arrToObj } from '@utils' class Index extends Component { onShareAppMessage() { return { title: '洪楼Plus-查学区', } } onShareTimeline () { return { title: '让买房,更省心!', } } constructor (props) { super(props) const { areaType } = this.$router.params let area_type = [] if (areaType) area_type = [areaType] this.state = { searchKey: '', page_size: 10, page: 1, isListEnd: false, isListLoading: false, isListEmpty: false, dataList: [], curNav: 1, isDShow: false, curObj: {}, searchIndex: -1, area_type, school_type: [], school_attrib: [], searchText1: '', searchText2: '', searchText3: '', } } config = { navigationBarTitleText: '查学校', } componentWillMount () { const { areaName } = this.$router.params if (areaName) { this.setState({ searchText1: areaName }) Taro.setNavigationBarTitle({ title: `${areaName}的学校` }) } this.getDataList() } componentDidShow () { } componentDidHide () { } renderSearch () { const { searchKey } = this.state return ( ) } onSeachChange (value) { this.setState({ searchKey: value }) } onClearHandle () { this.setState({ searchKey: '', page: 1 }, () => { this.getDataList() }) } onSelectActionClick () { this.setState({ page: 1, }, () => { this.getDataList() }) } searchIndex1Render () { const { area_type } = this.state const dictData = Taro.getStorageSync('dictData') const edIcon = require('@img/images/icon_g_ed.png') const rangeViews = dictData.area_type.map(item =>{ let curClassName = "stc-op" area_type.forEach(curVal =>{ if (curVal === item.val) { curClassName = "stc-op cur" } }) return ( {item.key} ) }) let allClassName = area_type.length === 0 ? 'stc-op cur' : 'stc-op' return ( 不限 {rangeViews} ) } searchIndex2Render () { const { school_type } = this.state const dictData = Taro.getStorageSync('dictData') const edIcon = require('@img/images/icon_g_ed.png') const rangeViews = dictData.school_type.map(item =>{ let curClassName = "stc-op" school_type.forEach(curVal =>{ if (curVal === item.val) { curClassName = "stc-op cur" } }) return ( {item.key} ) }) let allClassName = school_type.length === 0 ? 'stc-op cur' : 'stc-op' return ( 不限 {rangeViews} ) } searchIndex3Render () { const { school_attrib } = this.state const dictData = Taro.getStorageSync('dictData') const edIcon = require('@img/images/icon_g_ed.png') const rangeViews = dictData.school_attrib.map(item =>{ let curClassName = "stc-op" school_attrib.forEach(curVal =>{ if (curVal === item.val) { curClassName = "stc-op cur" } }) return ( {item.key} ) }) let allClassName = school_attrib.length === 0 ? 'stc-op cur' : 'stc-op' return ( 不限 {rangeViews} ) } renderTop () { const { areaName } = this.$router.params const { searchIndex } = this.state const { searchText1, searchText2, searchText3, } = this.state return ( { areaName ? {areaName} : {searchText1 || '区域'} } {searchText2 || '类型'} {searchText3 || '属性'} 0 ? 'st-content show' : 'st-content'}> { searchIndex === 1 && this.searchIndex1Render() } { searchIndex === 2 && this.searchIndex2Render() } { searchIndex === 3 && this.searchIndex3Render() } 重置 搜索 ) } searchNavHandle (index) { let { searchIndex } = this.state searchIndex = index === searchIndex ? -1 : index this.setState({ searchIndex }) } resetHandle () { const { searchIndex } = this.state // this.setState({ // searchIndex: -1, // }) if (searchIndex === 1) { this.setState({ area_type: [], searchText1: '', }) } if (searchIndex === 2) { this.setState({ school_type: [], searchText2: '', }) } if (searchIndex === 3) { this.setState({ school_attrib: [], searchText3: '', }) } } comSelectHandle (curOp, str) { if (curOp === 'all') { this.setState({ [str]: [] }) } else { const state = this.state let curStr = state[str] let ed = false let curI = 0 curStr.forEach((item, index) => { if (curOp.val === item) { ed = true curI = index } }) if (ed) { curStr.splice(curI, 1) } else { curStr.push(curOp.val) } this.setState({ [str]: curStr }) } } saveHandle () { const dictData = Taro.getStorageSync('dictData') const { searchIndex } = this.state const { area_type, school_type, school_attrib, } = this.state if (searchIndex === 1) { let tagArr = [] area_type.forEach(v => { tagArr.push(arrToObj(dictData.area_type)[v]) }) if (tagArr) { this.setState({ searchText1: tagArr.join(',') }) } } if (searchIndex === 2) { let tagArr = [] school_type.forEach(v => { tagArr.push(arrToObj(dictData.school_type)[v]) }) if (tagArr) { this.setState({ searchText2: tagArr.join(',') }) } } if (searchIndex === 3) { let tagArr = [] school_attrib.forEach(v => { tagArr.push(arrToObj(dictData.school_attrib)[v]) }) if (tagArr) { this.setState({ searchText3: tagArr.join(',') }) } } this.setState({ page: 1, searchIndex: -1, }, () => { this.getDataList() }) } getDataList () { let { page_size, page, dataList, isListEmpty } = this.state const { searchKey, area_type, school_type, school_attrib, } = this.state Taro.api.house.admschoollist({ page, page_size, school_name: searchKey, area_type: area_type.join(','), school_type: school_type.join(','), school_attrib: school_attrib.join(','), }).then(res => { const curData = res.list || [] let isListEnd = false if (curData.length > 0) { if (page === 1) { dataList = curData } else { dataList = dataList.concat(curData) } if (curData.length === page_size && res.total !== curData.length) { isListEnd = false } else { isListEnd = true } } if (curData.length === 0 && page === 1) { isListEmpty = true dataList = [] } else { isListEmpty = false } this.setState({ dataList, isListEnd, isListEmpty, isListLoading: false }) }) } onScrollToLower (e) { let { isListEnd, isListLoading, page } = this.state if (!isListEnd && !isListLoading) { page++ this.setState({ page, isListLoading: true }, () => { this.getDataList() }) } } renderList () { const dictData = Taro.getStorageSync('dictData') const { dataList, isListEnd, isListLoading, isListEmpty } = this.state const rankList = dataList.map((item, index) => { return ( {item.school_name} {item.address} {arrToObj(dictData.school_attrib)[item.school_attrib]} {arrToObj(dictData.school_type)[item.school_type]} ) }) return ( {rankList} ) } render () { return ( {this.renderSearch()} {this.renderTop()} {this.renderList()}