AnnouncementTab.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. ScrollView,
  5. View,
  6. Image,
  7. ImageBackground,
  8. Text,
  9. Dimensions,
  10. StatusBar,
  11. TouchableOpacity,
  12. PixelRatio,
  13. Platform,
  14. DatePickerAndroid,
  15. } from 'react-native'
  16. import { connect } from 'react-redux'
  17. import Icon from '../../components/Iconfont/Iconfont'
  18. import TopTab from '../../components/toptab/TopTab'
  19. import { NavigationActions, ScaleUtil, createAction } from '../../utils'
  20. import Collapsible from 'react-native-collapsible'
  21. import SelectTime from '../common/SelectTime'
  22. import Input from '../../components/input'
  23. import AllAnnounce from './announcement/AllAnnounce'
  24. import { setNowFormatDate } from '../../utils/utils'
  25. const { width, height } = Dimensions.get('window')
  26. @connect(({ theme, announce }) => ({ ...theme, ...announce }))
  27. class AnnouncementTab extends Component {
  28. constructor(props) {
  29. const date = new Date()
  30. super(props)
  31. this.state = {
  32. setButton: 0,
  33. inputSearch: '',
  34. dateActive: true, //时间折叠-true为关
  35. typeId: '',
  36. // 开始时间
  37. startTime: setNowFormatDate(true),
  38. // 结束时间
  39. endTime: setNowFormatDate(),
  40. }
  41. this.startTime = ''
  42. this.endTime = ''
  43. // console.disableYellowBox = true;
  44. }
  45. componentDidMount() {
  46. this.topTouchFn()
  47. }
  48. topTouchFn() {
  49. let searchInfo = {
  50. page: 0,
  51. pageSize: 20,
  52. customerId: CUSTOMERINFO.id,
  53. search_EQ_statusCode: 2,
  54. search_EQ_pubdate: 1,
  55. }
  56. if (this.state.typeId) {
  57. searchInfo['search_EQ_bulletin.id'] = this.state.typeId
  58. }
  59. if (this.startTime) {
  60. searchInfo.search_GTE_pubdate_date = new Date(this.startTime).getTime()
  61. }
  62. if (this.endTime) {
  63. searchInfo.search_LT_pubdate_date = new Date(this.endTime).getTime()
  64. }
  65. if (this.state.inputSearch) {
  66. searchInfo.search_LIKE_title = `%${this.state.inputSearch}%`
  67. }
  68. this.props.dispatch(createAction('announce/getAnnounceContent')(searchInfo))
  69. }
  70. // 订单按钮组
  71. setList(setAtt) {
  72. let textColor = ['#333', '#E14C46']
  73. let border = ['transparent', '#E14C46']
  74. setArr = []
  75. // const setAtt = [
  76. // { touchName: "全部" },
  77. // { touchName: "物流" },
  78. // { touchName: "促销" },
  79. // { touchName: "新品" },
  80. // { touchName: "企业动态" }
  81. // ];
  82. for (let j = 0; j < setAtt.length; j++) {
  83. setArr.push(
  84. <TouchableOpacity
  85. onPress={() => {
  86. this.state.typeId = setAtt[j].noticeType
  87. this.topTouchFn()
  88. this.setState({ setButton: j })
  89. }}
  90. key={j}
  91. style={{ justifyContent: 'center' }}
  92. >
  93. <Text
  94. style={{
  95. fontSize: 14,
  96. lineHeight: 18,
  97. color: this.state.setButton == j ? textColor[1] : textColor[0],
  98. }}
  99. >
  100. {setAtt[j].noticeTypeName}
  101. </Text>
  102. <View
  103. style={{
  104. height: 2,
  105. backgroundColor:
  106. this.state.setButton == j ? border[1] : border[0],
  107. marginTop: 3,
  108. }}
  109. />
  110. </TouchableOpacity>
  111. )
  112. }
  113. return setArr
  114. }
  115. selectTimeFn() {
  116. return (
  117. <View
  118. style={{
  119. position: 'absolute',
  120. top: 61,
  121. left: 0,
  122. width: width,
  123. backgroundColor: '#FFF',
  124. }}
  125. >
  126. <Collapsible collapsed={this.state.dateActive}>
  127. <View>
  128. <View
  129. style={{
  130. flexDirection: 'row',
  131. justifyContent: 'space-between',
  132. padding: 20,
  133. marginBottom: 20,
  134. }}
  135. >
  136. <View>
  137. <Text
  138. style={{
  139. fontSize: 13,
  140. lineHeight: 18,
  141. letterSpacing: 0.16,
  142. color: '#333',
  143. alignSelf: 'center',
  144. }}
  145. >
  146. 开始时间
  147. </Text>
  148. <TouchableOpacity
  149. onPress={() =>
  150. Platform.OS == 'ios'
  151. ? this.showTime._openModal('start')
  152. : this.TimeAndroid('start')
  153. }
  154. style={{
  155. paddingHorizontal: 40,
  156. paddingVertical: 7,
  157. marginTop: 16,
  158. borderColor: '#DDD',
  159. borderWidth: 1,
  160. borderRadius: 100,
  161. }}
  162. >
  163. <Text
  164. style={{
  165. fontSize: 13,
  166. lineHeight: 18,
  167. letterSpacing: 0.16,
  168. color: '#333',
  169. }}
  170. >
  171. {this.state.startTime}
  172. </Text>
  173. </TouchableOpacity>
  174. </View>
  175. <View style={{ paddingTop: 37 }}>
  176. <Text
  177. style={{
  178. fontSize: 18,
  179. lineHeight: 25,
  180. letterSpacing: 0.22,
  181. color: '#333',
  182. }}
  183. >
  184. ~
  185. </Text>
  186. </View>
  187. <View>
  188. <Text
  189. style={{
  190. fontSize: 13,
  191. lineHeight: 18,
  192. letterSpacing: 0.16,
  193. color: '#333',
  194. alignSelf: 'center',
  195. }}
  196. >
  197. 结束时间
  198. </Text>
  199. <TouchableOpacity
  200. onPress={() =>
  201. Platform.OS == 'ios'
  202. ? this.showTime._openModal('end')
  203. : this.TimeAndroid('end')
  204. }
  205. style={{
  206. paddingHorizontal: 40,
  207. paddingVertical: 7,
  208. marginTop: 16,
  209. borderColor: '#DDD',
  210. borderWidth: 1,
  211. borderRadius: 100,
  212. }}
  213. >
  214. <Text
  215. style={{
  216. fontSize: 13,
  217. lineHeight: 18,
  218. letterSpacing: 0.16,
  219. color: '#333',
  220. }}
  221. >
  222. {this.state.endTime}
  223. </Text>
  224. </TouchableOpacity>
  225. </View>
  226. </View>
  227. <View style={{ height: 40, flexDirection: 'row' }}>
  228. <TouchableOpacity
  229. onPress={() =>
  230. this.setState({
  231. dateActive: true,
  232. startTime: this.startTime,
  233. endTime: this.endTime,
  234. })
  235. }
  236. style={{
  237. width: width / 2,
  238. backgroundColor: '#FFF',
  239. justifyContent: 'center',
  240. }}
  241. >
  242. <Text
  243. style={{
  244. fontSize: 14,
  245. lineHeight: 22,
  246. letterSpacing: 0.21,
  247. color: '#333',
  248. alignSelf: 'center',
  249. }}
  250. >
  251. 取消
  252. </Text>
  253. </TouchableOpacity>
  254. <TouchableOpacity
  255. onPress={() => {
  256. this.startTime = this.state.startTime
  257. this.endTime = this.state.endTime
  258. this.topTouchFn()
  259. this.setState({ dateActive: true })
  260. }}
  261. style={{
  262. width: width / 2,
  263. backgroundColor: '#E70013',
  264. justifyContent: 'center',
  265. }}
  266. >
  267. <Text
  268. style={{
  269. fontSize: 14,
  270. lineHeight: 22,
  271. letterSpacing: 0.21,
  272. color: '#FFF',
  273. alignSelf: 'center',
  274. }}
  275. >
  276. 确定
  277. </Text>
  278. </TouchableOpacity>
  279. </View>
  280. </View>
  281. </Collapsible>
  282. </View>
  283. )
  284. }
  285. // 头部
  286. header() {
  287. return (
  288. <View
  289. style={{
  290. // height: 60,
  291. height: HEADERSTYLE.height,
  292. paddingTop: HEADERSTYLE.paddingTop + 5,
  293. // paddingTop: 15,
  294. backgroundColor: '#fff',
  295. borderBottomColor: '#eee',
  296. borderBottomWidth: 1 / PixelRatio.get(),
  297. }}
  298. >
  299. <View
  300. style={{
  301. flex: 1,
  302. justifyContent: 'center',
  303. }}
  304. >
  305. <TouchableOpacity
  306. style={{
  307. position: 'absolute',
  308. left: 10,
  309. flexDirection: 'row',
  310. }}
  311. onPress={() => this.props.dispatch(NavigationActions.back())}
  312. >
  313. <Icon
  314. name="icon-icon-fanhui"
  315. size={20}
  316. color={'#666'}
  317. style={{ marginTop: 4 }}
  318. />
  319. <Text
  320. style={{
  321. fontSize: 14,
  322. lineHeight: 20,
  323. color: '#666',
  324. alignSelf: 'center',
  325. }}
  326. >
  327. 返回
  328. </Text>
  329. </TouchableOpacity>
  330. {this.state.showSearch ? (
  331. <Input
  332. autoFocus={this.state.showSearch}
  333. style={{
  334. marginLeft: 25,
  335. marginTop: 8,
  336. height: 28,
  337. width: width / 1.6,
  338. borderRadius: width / 2,
  339. alignSelf: 'center',
  340. marginBottom: 8,
  341. paddingLeft: 14,
  342. }}
  343. textStyle={{
  344. paddingLeft: 10,
  345. height: 32,
  346. fontSize: 11,
  347. padding: 0,
  348. }}
  349. iconSize={14}
  350. blurOnSubmit={true}
  351. textInputBacg={'#F5F5F5'}
  352. iconColor={'#CCC'}
  353. placeholderTextColor={'#CCC'}
  354. placeholderSize={8}
  355. onchangeFn={e => {
  356. this.state.inputSearch = e
  357. this.topTouchFn()
  358. this.setState({ activeSection: true })
  359. }}
  360. />
  361. ) : (
  362. <Text
  363. style={{
  364. alignSelf: 'center',
  365. fontSize: 18,
  366. lineHeight: 25,
  367. letterSpacing: 0.19,
  368. color: '#333',
  369. }}
  370. >
  371. 公告
  372. </Text>
  373. )}
  374. {this.state.showSearch ? (
  375. <TouchableOpacity
  376. onPress={() =>
  377. this.setState({ showSearch: false, activeSection: true })
  378. }
  379. style={{ position: 'absolute', right: 10, flexDirection: 'row' }}
  380. >
  381. <Text style={{ fontSize: 14, lineHeight: 20, color: '#666' }}>
  382. 取消
  383. </Text>
  384. </TouchableOpacity>
  385. ) : (
  386. <View
  387. style={{ position: 'absolute', right: 10, flexDirection: 'row' }}
  388. >
  389. <TouchableOpacity
  390. style={{ marginRight: 10 }}
  391. onPress={() =>
  392. this.setState({
  393. showSearch: true,
  394. activeSection: true,
  395. dateActive: true,
  396. })
  397. }
  398. >
  399. <Icon name="icon-icon-sousuo" size={24} color={'#666'} />
  400. </TouchableOpacity>
  401. <TouchableOpacity
  402. onPress={() =>
  403. this.setState({
  404. dateActive: !this.state.dateActive,
  405. activeSection: true,
  406. })
  407. }
  408. >
  409. <Icon name="icon-icon-rili" size={24} color={'#666'} />
  410. </TouchableOpacity>
  411. </View>
  412. )}
  413. </View>
  414. </View>
  415. )
  416. }
  417. async TimeAndroid(mark) {
  418. const { action, year, month, day } = await DatePickerAndroid.open({
  419. date: new Date(),
  420. // minDate: new Date(),
  421. mode: 'spinner',
  422. })
  423. if (action !== DatePickerAndroid.dismissedAction) {
  424. let newDate = `${year}-${month + 1}-${day}`
  425. if (mark == 'start') {
  426. if (newDate <= this.state.endTime) {
  427. this.setState({
  428. startTime: newDate,
  429. })
  430. }
  431. } else if (mark == 'end') {
  432. if (this.state.startTime <= newDate) {
  433. this.setState({
  434. endTime: newDate,
  435. })
  436. }
  437. }
  438. // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day
  439. }
  440. }
  441. render() {
  442. const { appTheme, announceDatas } = this.props
  443. return (
  444. <View
  445. style={[
  446. styles.container,
  447. { backgroundColor: appTheme.backgroundColor },
  448. ]}
  449. >
  450. <StatusBar
  451. animated={true}
  452. barStyle={appTheme.barStyle}
  453. // barStyle={"dark-content"}
  454. backgroundColor={'transparent'}
  455. translucent={true}
  456. />
  457. {/* 头部 */}
  458. {this.header()}
  459. {announceDatas && announceDatas.length > 1 ? (
  460. <View
  461. style={{
  462. height: 35,
  463. backgroundColor: '#FFF',
  464. flexDirection: 'row',
  465. justifyContent: 'space-around',
  466. }}
  467. >
  468. {this.setList(announceDatas)}
  469. </View>
  470. ) : null}
  471. <ScrollView style={{ flex: 1 }}>
  472. <AllAnnounce />
  473. </ScrollView>
  474. {/* 下拉遮罩 */}
  475. {!this.state.dateActive ? (
  476. <View
  477. style={{
  478. position: 'absolute',
  479. width: width,
  480. height: height,
  481. backgroundColor: '#000',
  482. opacity: 0.5,
  483. top: 101,
  484. }}
  485. />
  486. ) : null}
  487. {/* 时间弹窗 */}
  488. <SelectTime
  489. ref={showTime => (this.showTime = showTime)}
  490. cb={(date, mark) => {
  491. let newDate = moment(date).format('YYYY-MM-DD')
  492. if (mark == 'start') {
  493. if (newDate <= this.state.endTime) {
  494. this.setState({
  495. startTime: newDate,
  496. })
  497. }
  498. } else if (mark == 'end') {
  499. if (this.state.startTime <= newDate) {
  500. this.setState({
  501. endTime: newDate,
  502. })
  503. }
  504. }
  505. }}
  506. />
  507. {/* 时间选择下拉 */}
  508. {this.selectTimeFn()}
  509. </View>
  510. )
  511. }
  512. }
  513. const styles = StyleSheet.create({
  514. container: {
  515. flex: 1,
  516. },
  517. pngstyle: {
  518. width: width,
  519. },
  520. buttonStyle: {
  521. backgroundColor: 'transparent',
  522. flexDirection: 'column',
  523. alignItems: 'center',
  524. },
  525. buttonText: {
  526. marginTop: 9,
  527. fontSize: 14,
  528. color: '#FFF',
  529. },
  530. })
  531. export default AnnouncementTab