index.jsx 13 KB

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