OrderHome.js 16 KB

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