123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- 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 (
- <AtSearchBar
- value={searchKey}
- fixed={true}
- placeholder="请输入学校名称"
- onChange={this.onSeachChange.bind(this)}
- onClear={this.onClearHandle.bind(this)}
- onActionClick={this.onSelectActionClick.bind(this)}
- />
- )
- }
- 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 (
- <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'area_type')}>{item.key}
- <Image className="img" src={edIcon} />
- </View>
- )
- })
- let allClassName = area_type.length === 0 ? 'stc-op cur' : 'stc-op'
- return (
- <View className="stc-wrap">
- <View className="stc-item">
- <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'area_type')}>不限</View>
- {rangeViews}
- </View>
- </View>
- )
- }
- 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 (
- <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'school_type')}>{item.key}
- <Image className="img" src={edIcon} />
- </View>
- )
- })
- let allClassName = school_type.length === 0 ? 'stc-op cur' : 'stc-op'
- return (
- <View className="stc-wrap">
- <View className="stc-item">
- <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'school_type')}>不限</View>
- {rangeViews}
- </View>
- </View>
- )
- }
- 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 (
- <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'school_attrib')}>{item.key}
- <Image className="img" src={edIcon} />
- </View>
- )
- })
- let allClassName = school_attrib.length === 0 ? 'stc-op cur' : 'stc-op'
- return (
- <View className="stc-wrap">
- <View className="stc-item">
- <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'school_attrib')}>不限</View>
- {rangeViews}
- </View>
- </View>
- )
- }
- renderTop () {
- const { areaName } = this.$router.params
- const { searchIndex } = this.state
- const {
- searchText1,
- searchText2,
- searchText3,
- } = this.state
- return (
- <View className="l-search-top t2">
- <View className="st-nav">
- {
- areaName
- ?
- <View className="stn-op col-3 cur">
- <View className="stn-label t2">{areaName}</View>
- </View>
- :
- <View className={(searchIndex === 1 || searchText1) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 1)}>
- <View className="stn-label">{searchText1 || '区域'}</View>
- <View className="stn-sign"></View>
- </View>
- }
- <View className={(searchIndex === 2 || searchText2) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 2)}>
- <View className="stn-label">{searchText2 || '类型'}</View>
- <View className="stn-sign"></View>
- </View>
- <View className={(searchIndex === 3 || searchText3) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 3)}>
- <View className="stn-label">{searchText3 || '属性'}</View>
- <View className="stn-sign"></View>
- </View>
- </View>
- <View className={searchIndex > 0 ? 'st-content show' : 'st-content'}>
- {
- searchIndex === 1
- &&
- this.searchIndex1Render()
- }
- {
- searchIndex === 2
- &&
- this.searchIndex2Render()
- }
- {
- searchIndex === 3
- &&
- this.searchIndex3Render()
- }
- <View className="l-floor-footer t2">
- <View className="lff-flex">
- <View className="lff-btn t3" onClick={this.resetHandle.bind(this)} >重置</View>
- <View className="lff-btn" onClick={this.saveHandle.bind(this)}>搜索</View>
- </View>
- </View>
- </View>
- </View>
- )
- }
- 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 (
- <Navigator url={'/pagesSchool/indexDtl?id=' + item.id} className="lb-item" key={index}>
- <View className="lb-img">
- <Image className="img" src={item.pri_image + '_xs'} mode="aspectFit" />
- </View>
- <View className="lb-info">
- <View className="lb-p1">{item.school_name}</View>
- <View className="lb-p2">{item.address}</View>
- <View className="lb-tag">
- <View className="t t1">{arrToObj(dictData.school_attrib)[item.school_attrib]}</View>
- <View className="t t4">{arrToObj(dictData.school_type)[item.school_type]}</View>
- </View>
- </View>
- </Navigator>
- )
- })
- return (
- <ScrollView
- className='l-scroll-view'
- scrollY
- scrollWithAnimation
- scrollTop="0"
- lowerThreshold="30"
- onScrollToLower={this.onScrollToLower.bind(this)}
- >
- <View className="l-list-box">
- {rankList}
- </View>
- <ListMore isListEnd={isListEnd} isListLoading={isListLoading} isListEmpty={isListEmpty} />
- </ScrollView>
- )
- }
- render () {
- return (
- <View className="l-box has-footer">
- {this.renderSearch()}
- {this.renderTop()}
- {this.renderList()}
- <Footer current={3} />
- </View>
- )
- }
- }
- export default Index
|