index.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Image, Text, Navigator } from '@tarojs/components'
  3. import { AtSearchBar } from 'taro-ui'
  4. import ListMore from '@/c/pageDataList/listMore'
  5. import Footer from '@/c/footer'
  6. import './index.scss'
  7. import { arrToObj } from '@utils'
  8. class Index extends Component {
  9. onShareAppMessage() {
  10. return {
  11. title: '洪楼Plus-查学区',
  12. }
  13. }
  14. onShareTimeline () {
  15. return {
  16. title: '让买房,更省心!',
  17. }
  18. }
  19. constructor (props) {
  20. super(props)
  21. const { areaType } = this.$router.params
  22. let area_type = []
  23. if (areaType) area_type = [areaType]
  24. this.state = {
  25. searchKey: '',
  26. page_size: 10,
  27. page: 1,
  28. isListEnd: false,
  29. isListLoading: false,
  30. isListEmpty: false,
  31. dataList: [],
  32. curNav: 1,
  33. isDShow: false,
  34. curObj: {},
  35. searchIndex: -1,
  36. area_type,
  37. school_type: [],
  38. school_attrib: [],
  39. searchText1: '',
  40. searchText2: '',
  41. searchText3: '',
  42. }
  43. }
  44. config = {
  45. navigationBarTitleText: '查学校',
  46. }
  47. componentWillMount () {
  48. const { areaName } = this.$router.params
  49. if (areaName) {
  50. this.setState({
  51. searchText1: areaName
  52. })
  53. Taro.setNavigationBarTitle({
  54. title: `${areaName}的学校`
  55. })
  56. }
  57. this.getDataList()
  58. }
  59. componentDidShow () { }
  60. componentDidHide () { }
  61. renderSearch () {
  62. const { searchKey } = this.state
  63. return (
  64. <AtSearchBar
  65. value={searchKey}
  66. fixed={true}
  67. placeholder="请输入学校名称"
  68. onChange={this.onSeachChange.bind(this)}
  69. onClear={this.onClearHandle.bind(this)}
  70. onActionClick={this.onSelectActionClick.bind(this)}
  71. />
  72. )
  73. }
  74. onSeachChange (value) {
  75. this.setState({
  76. searchKey: value
  77. })
  78. }
  79. onClearHandle () {
  80. this.setState({
  81. searchKey: '',
  82. page: 1
  83. }, () => {
  84. this.getDataList()
  85. })
  86. }
  87. onSelectActionClick () {
  88. this.setState({
  89. page: 1,
  90. }, () => {
  91. this.getDataList()
  92. })
  93. }
  94. searchIndex1Render () {
  95. const { area_type } = this.state
  96. const dictData = Taro.getStorageSync('dictData')
  97. const edIcon = require('@img/images/icon_g_ed.png')
  98. const rangeViews = dictData.area_type.map(item =>{
  99. let curClassName = "stc-op"
  100. area_type.forEach(curVal =>{
  101. if (curVal === item.val) {
  102. curClassName = "stc-op cur"
  103. }
  104. })
  105. return (
  106. <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'area_type')}>{item.key}
  107. <Image className="img" src={edIcon} />
  108. </View>
  109. )
  110. })
  111. let allClassName = area_type.length === 0 ? 'stc-op cur' : 'stc-op'
  112. return (
  113. <View className="stc-wrap">
  114. <View className="stc-item">
  115. <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'area_type')}>不限</View>
  116. {rangeViews}
  117. </View>
  118. </View>
  119. )
  120. }
  121. searchIndex2Render () {
  122. const { school_type } = this.state
  123. const dictData = Taro.getStorageSync('dictData')
  124. const edIcon = require('@img/images/icon_g_ed.png')
  125. const rangeViews = dictData.school_type.map(item =>{
  126. let curClassName = "stc-op"
  127. school_type.forEach(curVal =>{
  128. if (curVal === item.val) {
  129. curClassName = "stc-op cur"
  130. }
  131. })
  132. return (
  133. <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'school_type')}>{item.key}
  134. <Image className="img" src={edIcon} />
  135. </View>
  136. )
  137. })
  138. let allClassName = school_type.length === 0 ? 'stc-op cur' : 'stc-op'
  139. return (
  140. <View className="stc-wrap">
  141. <View className="stc-item">
  142. <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'school_type')}>不限</View>
  143. {rangeViews}
  144. </View>
  145. </View>
  146. )
  147. }
  148. searchIndex3Render () {
  149. const { school_attrib } = this.state
  150. const dictData = Taro.getStorageSync('dictData')
  151. const edIcon = require('@img/images/icon_g_ed.png')
  152. const rangeViews = dictData.school_attrib.map(item =>{
  153. let curClassName = "stc-op"
  154. school_attrib.forEach(curVal =>{
  155. if (curVal === item.val) {
  156. curClassName = "stc-op cur"
  157. }
  158. })
  159. return (
  160. <View className={curClassName} key={item.val} onClick={this.comSelectHandle.bind(this, item, 'school_attrib')}>{item.key}
  161. <Image className="img" src={edIcon} />
  162. </View>
  163. )
  164. })
  165. let allClassName = school_attrib.length === 0 ? 'stc-op cur' : 'stc-op'
  166. return (
  167. <View className="stc-wrap">
  168. <View className="stc-item">
  169. <View className={allClassName} onClick={this.comSelectHandle.bind(this, 'all', 'school_attrib')}>不限</View>
  170. {rangeViews}
  171. </View>
  172. </View>
  173. )
  174. }
  175. renderTop () {
  176. const { areaName } = this.$router.params
  177. const { searchIndex } = this.state
  178. const {
  179. searchText1,
  180. searchText2,
  181. searchText3,
  182. } = this.state
  183. return (
  184. <View className="l-search-top t2">
  185. <View className="st-nav">
  186. {
  187. areaName
  188. ?
  189. <View className="stn-op col-3 cur">
  190. <View className="stn-label t2">{areaName}</View>
  191. </View>
  192. :
  193. <View className={(searchIndex === 1 || searchText1) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 1)}>
  194. <View className="stn-label">{searchText1 || '区域'}</View>
  195. <View className="stn-sign"></View>
  196. </View>
  197. }
  198. <View className={(searchIndex === 2 || searchText2) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 2)}>
  199. <View className="stn-label">{searchText2 || '类型'}</View>
  200. <View className="stn-sign"></View>
  201. </View>
  202. <View className={(searchIndex === 3 || searchText3) ? 'stn-op col-3 cur' : 'stn-op col-3'} onClick={this.searchNavHandle.bind(this, 3)}>
  203. <View className="stn-label">{searchText3 || '属性'}</View>
  204. <View className="stn-sign"></View>
  205. </View>
  206. </View>
  207. <View className={searchIndex > 0 ? 'st-content show' : 'st-content'}>
  208. {
  209. searchIndex === 1
  210. &&
  211. this.searchIndex1Render()
  212. }
  213. {
  214. searchIndex === 2
  215. &&
  216. this.searchIndex2Render()
  217. }
  218. {
  219. searchIndex === 3
  220. &&
  221. this.searchIndex3Render()
  222. }
  223. <View className="l-floor-footer t2">
  224. <View className="lff-flex">
  225. <View className="lff-btn t3" onClick={this.resetHandle.bind(this)} >重置</View>
  226. <View className="lff-btn" onClick={this.saveHandle.bind(this)}>搜索</View>
  227. </View>
  228. </View>
  229. </View>
  230. </View>
  231. )
  232. }
  233. searchNavHandle (index) {
  234. let { searchIndex } = this.state
  235. searchIndex = index === searchIndex ? -1 : index
  236. this.setState({
  237. searchIndex
  238. })
  239. }
  240. resetHandle () {
  241. const { searchIndex } = this.state
  242. // this.setState({
  243. // searchIndex: -1,
  244. // })
  245. if (searchIndex === 1) {
  246. this.setState({
  247. area_type: [],
  248. searchText1: '',
  249. })
  250. }
  251. if (searchIndex === 2) {
  252. this.setState({
  253. school_type: [],
  254. searchText2: '',
  255. })
  256. }
  257. if (searchIndex === 3) {
  258. this.setState({
  259. school_attrib: [],
  260. searchText3: '',
  261. })
  262. }
  263. }
  264. comSelectHandle (curOp, str) {
  265. if (curOp === 'all') {
  266. this.setState({
  267. [str]: []
  268. })
  269. } else {
  270. const state = this.state
  271. let curStr = state[str]
  272. let ed = false
  273. let curI = 0
  274. curStr.forEach((item, index) => {
  275. if (curOp.val === item) {
  276. ed = true
  277. curI = index
  278. }
  279. })
  280. if (ed) {
  281. curStr.splice(curI, 1)
  282. } else {
  283. curStr.push(curOp.val)
  284. }
  285. this.setState({
  286. [str]: curStr
  287. })
  288. }
  289. }
  290. saveHandle () {
  291. const dictData = Taro.getStorageSync('dictData')
  292. const { searchIndex } = this.state
  293. const {
  294. area_type,
  295. school_type,
  296. school_attrib,
  297. } = this.state
  298. if (searchIndex === 1) {
  299. let tagArr = []
  300. area_type.forEach(v => {
  301. tagArr.push(arrToObj(dictData.area_type)[v])
  302. })
  303. if (tagArr) {
  304. this.setState({
  305. searchText1: tagArr.join(',')
  306. })
  307. }
  308. }
  309. if (searchIndex === 2) {
  310. let tagArr = []
  311. school_type.forEach(v => {
  312. tagArr.push(arrToObj(dictData.school_type)[v])
  313. })
  314. if (tagArr) {
  315. this.setState({
  316. searchText2: tagArr.join(',')
  317. })
  318. }
  319. }
  320. if (searchIndex === 3) {
  321. let tagArr = []
  322. school_attrib.forEach(v => {
  323. tagArr.push(arrToObj(dictData.school_attrib)[v])
  324. })
  325. if (tagArr) {
  326. this.setState({
  327. searchText3: tagArr.join(',')
  328. })
  329. }
  330. }
  331. this.setState({
  332. page: 1,
  333. searchIndex: -1,
  334. }, () => {
  335. this.getDataList()
  336. })
  337. }
  338. getDataList () {
  339. let { page_size, page, dataList, isListEmpty } = this.state
  340. const {
  341. searchKey,
  342. area_type,
  343. school_type,
  344. school_attrib,
  345. } = this.state
  346. Taro.api.house.admschoollist({
  347. page,
  348. page_size,
  349. school_name: searchKey,
  350. area_type: area_type.join(','),
  351. school_type: school_type.join(','),
  352. school_attrib: school_attrib.join(','),
  353. }).then(res => {
  354. const curData = res.list || []
  355. let isListEnd = false
  356. if (curData.length > 0) {
  357. if (page === 1) {
  358. dataList = curData
  359. } else {
  360. dataList = dataList.concat(curData)
  361. }
  362. if (curData.length === page_size && res.total !== curData.length) {
  363. isListEnd = false
  364. } else {
  365. isListEnd = true
  366. }
  367. }
  368. if (curData.length === 0 && page === 1) {
  369. isListEmpty = true
  370. dataList = []
  371. } else {
  372. isListEmpty = false
  373. }
  374. this.setState({
  375. dataList,
  376. isListEnd,
  377. isListEmpty,
  378. isListLoading: false
  379. })
  380. })
  381. }
  382. onScrollToLower (e) {
  383. let { isListEnd, isListLoading, page } = this.state
  384. if (!isListEnd && !isListLoading) {
  385. page++
  386. this.setState({
  387. page,
  388. isListLoading: true
  389. }, () => {
  390. this.getDataList()
  391. })
  392. }
  393. }
  394. renderList () {
  395. const dictData = Taro.getStorageSync('dictData')
  396. const { dataList, isListEnd, isListLoading, isListEmpty } = this.state
  397. const rankList = dataList.map((item, index) => {
  398. return (
  399. <Navigator url={'/pagesSchool/indexDtl?id=' + item.id} className="lb-item" key={index}>
  400. <View className="lb-img">
  401. <Image className="img" src={item.pri_image + '_xs'} mode="aspectFit" />
  402. </View>
  403. <View className="lb-info">
  404. <View className="lb-p1">{item.school_name}</View>
  405. <View className="lb-p2">{item.address}</View>
  406. <View className="lb-tag">
  407. <View className="t t1">{arrToObj(dictData.school_attrib)[item.school_attrib]}</View>
  408. <View className="t t4">{arrToObj(dictData.school_type)[item.school_type]}</View>
  409. </View>
  410. </View>
  411. </Navigator>
  412. )
  413. })
  414. return (
  415. <ScrollView
  416. className='l-scroll-view'
  417. scrollY
  418. scrollWithAnimation
  419. scrollTop="0"
  420. lowerThreshold="30"
  421. onScrollToLower={this.onScrollToLower.bind(this)}
  422. >
  423. <View className="l-list-box">
  424. {rankList}
  425. </View>
  426. <ListMore isListEnd={isListEnd} isListLoading={isListLoading} isListEmpty={isListEmpty} />
  427. </ScrollView>
  428. )
  429. }
  430. render () {
  431. return (
  432. <View className="l-box has-footer">
  433. {this.renderSearch()}
  434. {this.renderTop()}
  435. {this.renderList()}
  436. <Footer current={3} />
  437. </View>
  438. )
  439. }
  440. }
  441. export default Index