import React, { Component } from 'react' import { StyleSheet, View, Text, Dimensions, StatusBar, TouchableOpacity, PixelRatio, FlatList, Platform, DatePickerAndroid, RefreshControl, ActivityIndicator, } from 'react-native' import { connect } from 'react-redux' import Input from '../../../components/input/index' import Icon from '../../../components/Iconfont/Iconfont' import { NavigationActions, createAction } from '../../../utils' import { ReturnDate, setNowFormatDate } from '../../../utils/utils' import Collapsible from 'react-native-collapsible' import SelectTime from '../../common/SelectTime' import moment from 'moment' const { width, height } = Dimensions.get('window') /** * 查询条件 * search_IN_financeOrg:'', 财务组织 Id * search_EQ_billStatus:'', 订单状态 Code * search_EQ_billCode:'', Code * search_EQ_paymentMethod:'', 费用冲抵 Code * search_IN_saleOrg:'', 销售组织 Id * search_GTE_billDate_date, 开始时间 * search_LT_billDate_date 结束时间 */ @connect(({ theme, mine_header, mine }) => ({ ...theme, ...mine_header, ...mine, })) class Cost extends Component { constructor(props) { const date = new Date() super(props) this.state = { data: [], activeSection: true, //筛选条件折叠-true为关 dateActive: true, //时间折叠-true为关 filiter: 0, showSearch: false, // 应收组织Index receiveIndex: 0, // 销售组织Index saleIndex: 0, // 状态Index stateIndex: 0, // 冲抵Index offsetIndex: 0, // 应收组织 receivableOrgan: props.FinancialOrg.length > 0 ? props.FinancialOrg[0].organizationName : '', // 销售组织 saleOrgan: props.SupplierInfo.length > 0 ? props.SupplierInfo[0].saleOrganizationName : '', // 状态 stateSelect: '订单状态', // 冲抵 offsetSelect: '费用冲抵', // 开始时间 startTime: setNowFormatDate(true), // 结束时间 endTime: setNowFormatDate(), // 查询条件 offsetSelectCode: '', stateSelectCode: '', saleOrganId: '', // props.SupplierInfo.length > 0 // ? props.SupplierInfo[0].saleOrganizationId // : "", receivableOrganId: props.FinancialOrg.length > 0 ? props.FinancialOrg[0].finanOrgId : '', } this.startTime = 0 // date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); this.endTime = 0 // date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(); this.page = 0 this.size = 5 } componentDidMount = () => { // 可用财务组织、销售组织 this.props.dispatch( createAction('mine/getCusSup')({ customerId: CUSTOMERINFO.id, customerRankCode: CUSTOMERINFO.customerRankCode, comeFrom: 'castBalance', }) ) this.props.dispatch( createAction('mine_header/CastSaga')({ pageInfo: { size: 5, page: 0 }, searchInfo: this.searchInfo(), castData: [], }) ) } searchInfo() { let searchInfo = { search_EQ_financeOrg: this.state.receivableOrganId, // search_IN_saleOrg: this.state.saleOrganId, search_EQ_customer: CUSTOMERINFO.id, } if (this.state.saleOrganId) { searchInfo.search_EQ_saleOrg = this.state.saleOrganId } if (this.state.offsetSelectCode) { searchInfo.search_EQ_paymentMethod = this.state.offsetSelectCode } if (this.state.stateSelectCode) { searchInfo.search_EQ_billStatus = this.state.stateSelectCode } if (this.startTime !== 0) { searchInfo.search_GTE_billDate_date = new Date(this.startTime).getTime() } if (this.endTime !== 0) { searchInfo.search_LT_billDate_date = new Date(this.endTime).getTime() } return searchInfo } onRefresh() { this.props.dispatch( createAction('mine_header/CastSaga')({ castData: [], pageInfo: { page: 0, size: this.size }, searchInfo: this.searchInfo(), }) ) this.page = 0 } // 头部 header() { return ( this.props.dispatch(NavigationActions.back())} > 返回 {this.state.showSearch ? ( { this.setState({ activeSection: true }) }} /> ) : ( 费用余额 )} {this.state.showSearch ? ( this.setState({ showSearch: false, activeSection: true }) } style={{ position: 'absolute', right: 10, flexDirection: 'row' }} > 取消 ) : ( this.setState({ showSearch: true, activeSection: true, dateActive: true, }) } > this.setState({ dateActive: !this.state.dateActive, activeSection: true, }) } > )} ) } costList(item) { return ( { this.props.dispatch( createAction('mine_header/CastDetailSaga')({ id: item.id }) ) this.props.dispatch( NavigationActions.navigate({ routeName: 'CostDetail', params: { castData: item }, }) ) }} style={{ padding: 10, marginTop: 10, backgroundColor: '#FFF' }} > {item.billCode} {item.castTypeName} 保存 {ReturnDate(item.billDate, true)} {item.customerName} 费用金额 {item.castAmount} 余额 {item.castBalance} ) } collapsibleData(item, index) { return ( { switch (this.state.filiter) { case 'Receivable': this.state.receivableOrganId = item.finanOrgId this.setState({ receivableOrgan: item.finanOrgName, receivableOrganId: item.finanOrgId, activeSection: true, receiveIndex: index, }) break case 'Sale': this.state.saleOrganId = item.saleOrganizationId this.setState({ saleOrgan: item.saleOrganizationName, saleOrganId: item.saleOrganizationId, activeSection: true, saleIndex: index, }) break case 'State': this.state.stateSelectCode = item.code this.setState({ stateSelect: item.name, // stateSelectCode: item.id, activeSection: true, stateIndex: index, }) break case 'Offset': this.state.offsetSelectCode = item.code this.setState({ offsetSelect: item.name, // offsetSelectCode: item.id, activeSection: true, offsetIndex: index, }) break } this.props.dispatch( createAction('mine_header/CastSaga')({ castData: [], pageInfo: { page: 0, size: this.size }, searchInfo: this.searchInfo(), }) ) this.page = 0 }} style={{ flexDirection: 'row', padding: 10, justifyContent: 'space-between', }} > {item.saleOrganizationName || item.finanOrgName || item.name} {this.state.filiter == 'Receivable' && this.state.receiveIndex == index ? ( ) : null} {this.state.filiter == 'Sale' && this.state.saleIndex == index ? ( ) : null} {this.state.filiter == 'State' && this.state.stateIndex == index ? ( ) : null} {this.state.filiter == 'Offset' && this.state.offsetIndex == index ? ( ) : null} ) } HeadScreening(from, data) { if (this.state.filiter !== from) { this.setState({ activeSection: false }) } else if (this.state.filiter == from) { if (this.state.activeSection == false) { this.setState({ activeSection: true }) } else { this.setState({ activeSection: false }) } } switch (from) { case 'Receivable': this.state.filiter = 'Receivable' this.setState({ data: data, showSearch: false }) break case 'Sale': this.state.filiter = 'Sale' this.setState({ data: data, showSearch: false }) break case 'State': this.state.filiter = 'State' this.setState({ data: data, showSearch: false }) break case 'Offset': this.state.filiter = 'Offset' this.setState({ data: data, showSearch: false }) break } } async TimeAndroid(mark) { const { action, year, month, day } = await DatePickerAndroid.open({ date: new Date(), // minDate: new Date(), mode: 'spinner', }) if (action !== DatePickerAndroid.dismissedAction) { let newDate = `${year}-${month + 1}-${day}` if (mark == 'start') { if (newDate <= this.state.endTime) { this.setState({ startTime: newDate, }) } } else if (mark == 'end') { if (this.state.startTime <= newDate) { this.setState({ endTime: newDate, }) } } // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day } } // 底部 footerCom() { if (this.props.showFoot == 0) { return } else if (this.props.showFoot == 1) { return ( 没有更多数据 ) } else if (this.props.showFoot == 2) { return ( 正在加载更多数据... ) } } render() { const { appTheme, castData, totalPages, FinancialOrg, SaleOrg, Balance, OffsetMod, StateMod, SupplierInfo, } = this.props return ( {this.header()} {/* 头部筛选条件 */} this.HeadScreening('Receivable', FinancialOrg)} style={{ flex: 1, justifyContent: 'center', flexDirection: 'row', borderRightColor: '#EEE', borderRightWidth: 1, paddingHorizontal: 10, }} > {this.state.receivableOrgan} this.HeadScreening('Sale', SupplierInfo)} style={{ flex: 1, justifyContent: 'center', flexDirection: 'row', borderRightColor: '#EEE', borderRightWidth: 1, paddingHorizontal: 10, }} > {this.state.saleOrgan} this.HeadScreening('State', StateMod)} > {this.state.stateSelect} this.HeadScreening('Offset', OffsetMod)} > {this.state.offsetSelect} {/* 票扣及货补余额 */} 票扣余额 {Balance['票扣余额']} 货补余额 {Balance['货补余额']} {/* 列表 */} item.id + index} data={castData} renderItem={({ item, index }) => this.costList(item, index)} ListFooterComponent={this.footerCom.bind(this)} // initialNumToRender={5} onEndReachedThreshold={0.1} onEndReached={e => { if (this.props.showFoot != 0) { return } if (this.page != 1 && this.page >= totalPages) { return } else { this.page++ } this.props.dispatch( createAction('mine_header/CastSaga')({ castData: castData, pageInfo: { page: this.page, size: this.size }, searchInfo: this.searchInfo(), forUse: 'slipOn', }) ) }} refreshControl={ this.onRefresh)或者通过bind来绑定this引用来调用方法 tintColor="red" title={this.props.isRefreshing ? '刷新中....' : '下拉刷新'} /> } /> {/* 下拉遮罩 */} {!this.state.activeSection || !this.state.dateActive ? ( ) : null} {/* 筛选条件下拉 */} item.id + index} data={this.state.data} extraData={this.state} renderItem={({ item, index }) => this.collapsibleData(item, index) } /> {/* 时间弹窗 */} (this.showTime = showTime)} cb={(date, mark) => { let newDate = moment(date).format('YYYY-MM-DD') if (mark == 'start') { if (newDate <= this.state.endTime) { this.setState({ startTime: newDate, }) } } else if (mark == 'end') { if (this.state.startTime <= newDate) { this.setState({ endTime: newDate, }) } } }} /> {/* 时间选择下拉 */} 开始时间 Platform.OS == 'ios' ? this.showTime._openModal('start') : this.TimeAndroid('start') } style={{ paddingHorizontal: 40, paddingVertical: 7, marginTop: 16, borderColor: '#DDD', borderWidth: 1, borderRadius: 100, }} > {this.state.startTime} ~ 结束时间 Platform.OS == 'ios' ? this.showTime._openModal('end') : this.TimeAndroid('end') } style={{ paddingHorizontal: 40, paddingVertical: 7, marginTop: 16, borderColor: '#DDD', borderWidth: 1, borderRadius: 100, }} > {this.state.endTime} this.setState({ dateActive: true, startTime: this.startTime, endTime: this.endTime, }) } style={{ width: width / 2, backgroundColor: '#FFF', justifyContent: 'center', }} > 取消 { this.setState({ dateActive: true }) this.startTime = this.state.startTime this.endTime = this.state.endTime this.props.dispatch( createAction('mine_header/CastSaga')({ castData: [], pageInfo: { page: 0, size: this.size }, searchInfo: this.searchInfo(), }) ) this.page = 0 }} style={{ width: width / 2, backgroundColor: '#E70013', justifyContent: 'center', }} > 确定 ) } } const styles = StyleSheet.create({ container: { flex: 1, }, footer: { flexDirection: 'row', height: 24, justifyContent: 'center', alignItems: 'center', marginBottom: 10, marginTop: 10, }, }) export default Cost