list.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 './list.scss'
  7. import { arrToObj } from '@utils'
  8. class Index extends Component {
  9. onShareAppMessage() {
  10. return {
  11. title: '常见答疑',
  12. }
  13. }
  14. onShareTimeline () {
  15. return {
  16. title: '常见答疑-洪楼解惑',
  17. }
  18. }
  19. constructor (props) {
  20. super(props)
  21. this.state = {
  22. searchKey: '',
  23. page_size: 10,
  24. page: 1,
  25. isListEnd: false,
  26. isListLoading: false,
  27. isListEmpty: false,
  28. dataList: [],
  29. curNav: 1,
  30. isDShow: false,
  31. curObj: {},
  32. }
  33. }
  34. config = {
  35. navigationBarTitleText: '常见答疑',
  36. }
  37. componentWillMount () {
  38. this.getDataList()
  39. }
  40. componentDidShow () { }
  41. componentDidHide () { }
  42. renderSearch () {
  43. const { searchKey } = this.state
  44. return (
  45. <AtSearchBar
  46. value={searchKey}
  47. fixed={true}
  48. placeholder="请输入问题名称搜索"
  49. onChange={this.onSeachChange.bind(this)}
  50. onActionClick={this.onSelectActionClick.bind(this)}
  51. onClear={this.onClearHandle.bind(this)}
  52. />
  53. )
  54. }
  55. onSeachChange (value) {
  56. this.setState({
  57. searchKey: value
  58. })
  59. }
  60. onClearHandle () {
  61. this.setState({
  62. searchKey: '',
  63. page: 1
  64. }, () => {
  65. this.getDataList()
  66. })
  67. }
  68. onSelectActionClick () {
  69. this.setState({
  70. page: 1,
  71. }, () => {
  72. this.getDataList()
  73. })
  74. }
  75. getDataList () {
  76. let { page_size, page, dataList, isListEmpty } = this.state
  77. const {
  78. searchKey
  79. } = this.state
  80. Taro.api.news.qalist({
  81. page,
  82. page_size,
  83. question_cont: searchKey,
  84. }).then(res => {
  85. const curData = res.list || []
  86. let isListEnd = false
  87. if (curData.length > 0) {
  88. if (page === 1) {
  89. dataList = curData
  90. } else {
  91. dataList = dataList.concat(curData)
  92. }
  93. if (curData.length === page_size && res.total !== curData.length) {
  94. isListEnd = false
  95. } else {
  96. isListEnd = true
  97. }
  98. }
  99. if (curData.length === 0 && page === 1) {
  100. isListEmpty = true
  101. dataList = []
  102. } else {
  103. isListEmpty = false
  104. }
  105. this.setState({
  106. dataList,
  107. isListEnd,
  108. isListEmpty,
  109. isListLoading: false
  110. })
  111. })
  112. }
  113. onScrollToLower (e) {
  114. let { isListEnd, isListLoading, page } = this.state
  115. if (!isListEnd && !isListLoading) {
  116. page++
  117. this.setState({
  118. page,
  119. isListLoading: true
  120. }, () => {
  121. this.getDataList()
  122. })
  123. }
  124. }
  125. renderList () {
  126. const { dataList, isListEnd, isListLoading, isListEmpty } = this.state
  127. const dictData = Taro.getStorageSync('dictData')
  128. const qtObj = arrToObj(dictData.question_tag)
  129. const iconQ = require('@img/qa_q.png')
  130. const iconA = require('@img/qa_a2.png')
  131. const itemsList = dataList.map((item, index) => {
  132. let curStr2 = item.answer_cont || ''
  133. if (curStr2) {
  134. item.titleStr2 = curStr2.length > 36 ? `${curStr2.substring(0, 36)}...` : curStr2
  135. }
  136. const qt = item.question_tag || ''
  137. const signItems = qt.split(',').map((tag, tIndex) => {
  138. return (
  139. <View className="sign" key={tIndex}>{qtObj[tag] || '提问'}</View>
  140. )
  141. })
  142. return (
  143. <View className="ql-item" key={index}>
  144. <View className="ql-header">
  145. {signItems}
  146. </View>
  147. <View className="ql-info">
  148. <View className="ql-p1">
  149. <Image className="img" src={iconQ} />
  150. <View className="t">{item.question_cont}</View>
  151. </View>
  152. {
  153. item.isMoreAllShow
  154. ?
  155. <View className="ql-p1">
  156. <Image className="img" src={iconA} />
  157. <View className="t">{item.answer_cont}
  158. <View className="ql-more t2" onClick={this.changeMoreHandle.bind(this, index)}>收起
  159. <View className="sign"></View>
  160. </View>
  161. </View>
  162. </View>
  163. :
  164. <View className="ql-p2">
  165. <Image className="img" src={iconA} />
  166. <View className="t">{item.titleStr2}
  167. <View className="ql-more" onClick={this.changeMoreHandle.bind(this, index)}>展开
  168. <View className="sign"></View>
  169. </View>
  170. </View>
  171. </View>
  172. }
  173. </View>
  174. {/* <View className="ql-footer">
  175. <View className="s">{item.create_at.substring(0, 10)}</View>
  176. </View> */}
  177. </View>
  178. )
  179. })
  180. return (
  181. <ScrollView
  182. className='l-scroll-view'
  183. scrollY
  184. scrollWithAnimation
  185. scrollTop="0"
  186. lowerThreshold="30"
  187. onScrollToLower={this.onScrollToLower.bind(this)}
  188. >
  189. <View className="q-list">
  190. {itemsList}
  191. </View>
  192. <ListMore isListEnd={isListEnd} isListLoading={isListLoading} isListEmpty={isListEmpty} />
  193. </ScrollView>
  194. )
  195. }
  196. changeMoreHandle (index) {
  197. const { dataList } = this.state
  198. let mList = dataList || []
  199. mList.map((item, i) => {
  200. if (index === i) item.isMoreAllShow = !item.isMoreAllShow
  201. })
  202. this.setState({
  203. dataList: [...mList]
  204. })
  205. }
  206. renderQaAdd () {
  207. const iconGif = require('@img/icon_g_qa.gif')
  208. return (
  209. <Navigator url={'/pagesQa/add'} className="scoped-fix-q2 t2">
  210. <Image className="img" src={iconGif} />
  211. </Navigator>
  212. )
  213. }
  214. renderShare () {
  215. const iconShare = require('@img/images/icon_g_share6.png')
  216. return (
  217. <Button className="g-icon-share btn-to-div" openType="share">
  218. <Image className="img" src={iconShare} />
  219. </Button>
  220. )
  221. }
  222. render () {
  223. return (
  224. <View className="l-box has-footer">
  225. {this.renderQaAdd()}
  226. {this.renderShare()}
  227. {this.renderSearch()}
  228. {this.renderList()}
  229. <Footer current={4} />
  230. </View>
  231. )
  232. }
  233. }
  234. export default Index