Commit d2c4dae4 by 姜雷

Merge branch 'develop' into 'test'

添加下拉刷新 See merge request !11
parents c39df64c da60d25e
import React, { Component } from 'react'; import React, { Component } from 'react';
import { fetchPublicCarList } from '../../api/index'; import { fetchPublicCarList } from '../../api/index';
import { PullToRefresh, Toast } from 'antd-mobile'; import { ListView, PullToRefresh, Toast } from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import PublicCarItem from './components/PublicCarItem'; import PublicCarItem from './components/PublicCarItem';
class PublicCarList extends Component { class PublicCarList extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const list = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
});
this.state = { this.state = {
refreshing: false, refreshing: false,
down: true, down: true,
height: document.documentElement.clientHeight, height: document.documentElement.clientHeight,
list: [], list: list,
sourceList: [],
pagination: { pagination: {
nowDate: '', nowDate: '',
pageNum: 1, pageNum: 1,
pageSize: 50, pageSize: 10,
}, },
}; };
} }
...@@ -32,6 +36,12 @@ class PublicCarList extends Component { ...@@ -32,6 +36,12 @@ class PublicCarList extends Component {
); );
this.fetchList(); this.fetchList();
} }
updateList = () => {
const { sourceList } = this.state;
this.setState(({ list }) => ({
list: list.cloneWithRows(sourceList),
}));
};
fetchList = fetchMore => { fetchList = fetchMore => {
const { pagination } = this.state; const { pagination } = this.state;
const nowDate = new Date().toISOString(); const nowDate = new Date().toISOString();
...@@ -48,11 +58,11 @@ class PublicCarList extends Component { ...@@ -48,11 +58,11 @@ class PublicCarList extends Component {
fetchPublicCarList(entity) fetchPublicCarList(entity)
.then(res => { .then(res => {
this.setState( this.setState(
({ list, pagination }) => ({ sourceList, pagination }) =>
fetchMore fetchMore
? res.data.length ? res.data.length
? { ? {
list: [...list, ...res.data], sourceList: [...sourceList, ...res.data],
pagination: { pagination: {
...pagination, ...pagination,
pageNum: pagination.pageNum + 1, pageNum: pagination.pageNum + 1,
...@@ -63,14 +73,16 @@ class PublicCarList extends Component { ...@@ -63,14 +73,16 @@ class PublicCarList extends Component {
refreshing: false, refreshing: false,
} }
: { : {
list: res.data, sourceList: res.data,
pagination: { pagination: {
...pagination, ...pagination,
pageNum: 1,
nowDate, nowDate,
}, },
refreshing: false, refreshing: false,
} }
); );
this.updateList();
}) })
.catch(err => { .catch(err => {
Toast.fail(err.msg || '请求失败!'); Toast.fail(err.msg || '请求失败!');
...@@ -82,29 +94,45 @@ class PublicCarList extends Component { ...@@ -82,29 +94,45 @@ class PublicCarList extends Component {
refreshHandle = () => { refreshHandle = () => {
this.fetchList(true); this.fetchList(true);
}; };
MyBody = props => {
return (
<div className={styles.repairList}>
<div className={styles.listInfo}>显示最近半年的报修记录</div>
{props.children}
</div>
);
};
render() { render() {
const { list, pagination } = this.state;
return ( return (
<div className={styles.publicCarList}> <ListView
<PullToRefresh
damping={60}
ref={el => (this.ptr = el)}
style={{ style={{
height: this.state.height, height: this.state.height,
overflow: 'auto',
}} }}
indicator={{ deactivate: '上拉可以刷新' }} className={styles.scrollWrap}
direction={'up'} dataSource={list}
refreshing={this.state.refreshing} pageSize={pagination.pageSize}
onRefresh={this.refreshHandle} renderBodyComponent={() => <this.MyBody />}
> renderRow={rowData => (
<div className={styles.listInfo}>显示最近半年的报修记录</div> <PublicCarItem
{this.state.list.length ? ( key={rowData.id}
this.state.list.map(i => <PublicCarItem key={i.id} data={i} />) data={rowData}
) : ( showView={this.showViewHandle}
<div className={styles.noData}>暂无数据</div> />
)} )}
</PullToRefresh> onEndReached={this.refreshHandle}
</div> pullToRefresh={
<PullToRefresh
refreshing={this.state.refreshing}
onRefresh={this.fetchList}
/>
}
// renderFooter={() => (
// <div style={{ textAlign: 'center' }}>
// {this.state.refreshing ? 'Loading...' : 'Loaded'}
// </div>
// )}
/>
); );
} }
} }
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
composes: noData from '../Repair/style.css'; composes: noData from '../Repair/style.css';
} }
/* apply */ /* apply */
.scrollWrap {
background-color: #f2f2f2;
}
.content { .content {
padding: 30px 40px 20px; padding: 30px 40px 20px;
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { PullToRefresh, Modal, Toast, TextareaItem } from 'antd-mobile'; import {
ListView,
PullToRefresh,
Modal,
Toast,
TextareaItem,
} from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import PublicCarItem from '../PublicCar/components/PublicCarItem'; import PublicCarItem from '../PublicCar/components/PublicCarItem';
import { import {
...@@ -16,15 +22,19 @@ import Select from './Select'; ...@@ -16,15 +22,19 @@ import Select from './Select';
class PublicCarDeal extends Component { class PublicCarDeal extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const list = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
});
this.state = { this.state = {
refreshing: false, refreshing: false,
down: true, down: true,
height: document.documentElement.clientHeight, height: document.documentElement.clientHeight,
pagination: { pagination: {
pageNum: 1, pageNum: 1,
pageSize: 50, pageSize: 10,
}, },
list: [], list: list,
sourceList: [],
dealDialogVisible: false, dealDialogVisible: false,
selected: { selected: {
id: '', id: '',
...@@ -38,6 +48,12 @@ class PublicCarDeal extends Component { ...@@ -38,6 +48,12 @@ class PublicCarDeal extends Component {
componentDidMount() { componentDidMount() {
this.fetchList(); this.fetchList();
} }
updateList = () => {
const { sourceList } = this.state;
this.setState(({ list }) => ({
list: list.cloneWithRows(sourceList),
}));
};
fetchList = fetchMore => { fetchList = fetchMore => {
this.setState({ refreshing: true }); this.setState({ refreshing: true });
const { pagination } = this.state; const { pagination } = this.state;
...@@ -55,29 +71,24 @@ class PublicCarDeal extends Component { ...@@ -55,29 +71,24 @@ class PublicCarDeal extends Component {
fetchApplyPublicCarList(entity) fetchApplyPublicCarList(entity)
.then(res => { .then(res => {
this.setState( this.setState(
({ list, pagination }) => ({ sourceList }) =>
fetchMore fetchMore
? res.data.length ? res.data.length
? { ? {
list: [...list, ...res.data], sourceList: [...sourceList, ...res.data],
pagination: { pagination: entity,
...pagination,
pageNum: pagination.pageNum + 1,
},
refreshing: false, refreshing: false,
} }
: { : {
refreshing: false, refreshing: false,
} }
: { : {
list: res.data, sourceList: res.data,
pagination: { pagination: entity,
...pagination,
nowDate,
},
refreshing: false, refreshing: false,
} }
); );
this.updateList();
}) })
.catch(err => { .catch(err => {
Toast.fail(err.msg || '请求失败!'); Toast.fail(err.msg || '请求失败!');
...@@ -197,33 +208,16 @@ class PublicCarDeal extends Component { ...@@ -197,33 +208,16 @@ class PublicCarDeal extends Component {
}, },
})); }));
}; };
render() { MyBody = props => {
const { const {
selected: { value, dealOpinion, carPlate }, selected: { value, dealOpinion, carPlate },
dealDialogVisible, dealDialogVisible,
carPlateList, carPlateList,
} = this.state; } = this.state;
return ( return (
<PullToRefresh <div className={styles.repairList}>
damping={60}
ref={el => (this.ptr = el)}
style={{
height: this.state.height,
overflow: 'auto',
}}
indicator={{ deactivate: '上拉可以刷新' }}
direction={'up'}
refreshing={this.state.refreshing}
onRefresh={this.refreshHandle}
>
<div className={styles.listInfo}>显示最近半年的报修记录</div> <div className={styles.listInfo}>显示最近半年的报修记录</div>
{this.state.list.length ? ( {props.children}
this.state.list.map(i => (
<PublicCarItem key={i.id} data={i} dealHandle={this.dealHandle} />
))
) : (
<div className={styles.noData}>暂无数据</div>
)}
<Modal <Modal
className={styles.dealDialog} className={styles.dealDialog}
visible={dealDialogVisible} visible={dealDialogVisible}
...@@ -300,7 +294,40 @@ class PublicCarDeal extends Component { ...@@ -300,7 +294,40 @@ class PublicCarDeal extends Component {
) : null} ) : null}
</div> </div>
</Modal> </Modal>
</PullToRefresh> </div>
);
};
render() {
const { list, pagination } = this.state;
return (
<ListView
style={{
height: this.state.height,
}}
className={styles.scrollWrap}
dataSource={list}
pageSize={pagination.pageSize}
renderBodyComponent={() => <this.MyBody />}
renderRow={rowData => (
<PublicCarItem
key={rowData.id}
data={rowData}
dealHandle={this.dealHandle}
/>
)}
onEndReached={this.refreshHandle}
pullToRefresh={
<PullToRefresh
refreshing={this.state.refreshing}
onRefresh={this.fetchList}
/>
}
// renderFooter={() => (
// <div style={{ textAlign: 'center' }}>
// {this.state.refreshing ? 'Loading...' : 'Loaded'}
// </div>
// )}
/>
); );
} }
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { PullToRefresh, Modal, Toast } from 'antd-mobile'; import { ListView, PullToRefresh, Modal, Toast } from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import RepairItem from './components/RepairItem'; import RepairItem from './components/RepairItem';
import { fetchRepairList } from '../../api/index'; import { fetchRepairList } from '../../api/index';
...@@ -8,14 +8,9 @@ import Perview from '../../components/Perview/Perview'; ...@@ -8,14 +8,9 @@ import Perview from '../../components/Perview/Perview';
class RepairList extends Component { class RepairList extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
// const getSectionData = (dataBlob, sectionID) => dataBlob[sectionID]; const list = new ListView.DataSource({
// const getRowData = (dataBlob, sectionID, rowID) => dataBlob[rowID]; rowHasChanged: (row1, row2) => row1 !== row2,
// const list = new ListView.DataSource({ });
// getRowData,
// getSectionHeaderData: getSectionData,
// rowHasChanged: (row1, row2) => row1 !== row2,
// sectionHeaderHasChanged: (s1, s2) => s1 !== s2,
// });
this.state = { this.state = {
refreshing: false, refreshing: false,
down: true, down: true,
...@@ -23,13 +18,15 @@ class RepairList extends Component { ...@@ -23,13 +18,15 @@ class RepairList extends Component {
pagination: { pagination: {
nowDate: '', nowDate: '',
pageNum: 1, pageNum: 1,
pageSize: 50, pageSize: 10,
}, },
list: [], list: list,
sourceList: [],
perviewVisibility: false, perviewVisibility: false,
selectedImgList: [], selectedImgList: [],
perviewIndex: 0, perviewIndex: 0,
}; };
// this.sourceList = [];
} }
componentDidMount() { componentDidMount() {
let wrap = document.querySelector('.RepairContent'); let wrap = document.querySelector('.RepairContent');
...@@ -43,6 +40,12 @@ class RepairList extends Component { ...@@ -43,6 +40,12 @@ class RepairList extends Component {
); );
this.fetchList(); this.fetchList();
} }
updateList = () => {
const { sourceList } = this.state;
this.setState(({ list }) => ({
list: list.cloneWithRows(sourceList),
}));
};
fetchList = fetchMore => { fetchList = fetchMore => {
const { pagination } = this.state; const { pagination } = this.state;
const nowDate = new Date().toISOString(); const nowDate = new Date().toISOString();
...@@ -59,11 +62,11 @@ class RepairList extends Component { ...@@ -59,11 +62,11 @@ class RepairList extends Component {
fetchRepairList(entity) fetchRepairList(entity)
.then(res => { .then(res => {
this.setState( this.setState(
({ list, pagination }) => ({ sourceList, pagination }) =>
fetchMore fetchMore
? res.data.length ? res.data.length
? { ? {
list: [...list, ...res.data], sourceList: [...sourceList, ...res.data],
pagination: { pagination: {
...pagination, ...pagination,
pageNum: pagination.pageNum + 1, pageNum: pagination.pageNum + 1,
...@@ -74,14 +77,16 @@ class RepairList extends Component { ...@@ -74,14 +77,16 @@ class RepairList extends Component {
refreshing: false, refreshing: false,
} }
: { : {
list: res.data, sourceList: res.data,
pagination: { pagination: {
...pagination, ...pagination,
pageNum: 1,
nowDate, nowDate,
}, },
refreshing: false, refreshing: false,
} }
); );
this.updateList();
}) })
.catch(err => { .catch(err => {
Toast.fail(err.msg || '请求失败!'); Toast.fail(err.msg || '请求失败!');
...@@ -105,20 +110,37 @@ class RepairList extends Component { ...@@ -105,20 +110,37 @@ class RepairList extends Component {
perviewVisibility: false, perviewVisibility: false,
}); });
}; };
render() { MyBody = props => {
const { const { perviewVisibility, selectedImgList, perviewIndex } = this.state;
list,
perviewVisibility,
selectedImgList,
perviewIndex,
} = this.state;
return ( return (
<div className={styles.repairList}> <div className={styles.repairList}>
{/* <ListView <div className={styles.listInfo}>显示最近半年的报修记录</div>
{props.children}
<Modal
className={styles.perViewDialog}
visible={perviewVisibility}
transparent
maskClosable={true}
onClose={this.resetDialog}
title=""
>
<Perview data={selectedImgList} index={perviewIndex} />
</Modal>
</div>
);
};
render() {
const { list, pagination } = this.state;
return (
<ListView
style={{ style={{
height: this.state.height, height: this.state.height,
}} }}
className={styles.scrollWrap}
dataSource={list} dataSource={list}
pageSize={pagination.pageSize}
renderBodyComponent={() => <this.MyBody />}
renderRow={rowData => ( renderRow={rowData => (
<RepairItem <RepairItem
key={rowData.id} key={rowData.id}
...@@ -126,39 +148,19 @@ class RepairList extends Component { ...@@ -126,39 +148,19 @@ class RepairList extends Component {
showView={this.showViewHandle} showView={this.showViewHandle}
/> />
)} )}
/> */} onEndReached={this.refreshHandle}
pullToRefresh={
<PullToRefresh <PullToRefresh
damping={60}
ref={el => (this.ptr = el)}
style={{
height: this.state.height,
overflow: 'auto',
}}
indicator={{ deactivate: '上拉可以刷新' }}
direction={'up'}
refreshing={this.state.refreshing} refreshing={this.state.refreshing}
onRefresh={this.refreshHandle} onRefresh={this.fetchList}
> />
<div className={styles.listInfo}>显示最近半年的报修记录</div> }
{list.length ? ( // renderFooter={() => (
list.map(i => ( // <div style={{ textAlign: 'center' }}>
<RepairItem key={i.id} data={i} showView={this.showViewHandle} /> // {this.state.refreshing ? 'Loading...' : 'Loaded'}
)) // </div>
) : ( // )}
<div className={styles.noData}>暂无数据</div> />
)}
</PullToRefresh>
<Modal
className={styles.perViewDialog}
visible={perviewVisibility}
transparent
maskClosable={true}
onClose={this.resetDialog}
title=""
>
<Perview data={selectedImgList} index={perviewIndex} />
</Modal>
</div>
); );
} }
} }
......
...@@ -86,7 +86,7 @@ class RepairItem extends Component { ...@@ -86,7 +86,7 @@ class RepairItem extends Component {
</div> </div>
</div> </div>
</div>, </div>,
<div key="uploadImg" className={styles.listLine}> <div key="uploadImg" className={`${styles.listLine} ${styles.listLineImg}`}>
{imgList[0] && {imgList[0] &&
imgList.map((item, idx) => ( imgList.map((item, idx) => (
<div <div
......
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
line-height: 30px; line-height: 30px;
margin-bottom: 30px; margin-bottom: 30px;
} }
.listLineImg {
justify-content: space-between;
}
.listLine:last-child { .listLine:last-child {
margin-bottom: 0; margin-bottom: 0;
} }
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
flex: auto; flex: auto;
overflow-y: auto; overflow-y: auto;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
padding-bottom: 20px; }
.scrollWrap {
background-color: #f2f2f2;
} }
.footerTopLine { .footerTopLine {
position: absolute; position: absolute;
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { PullToRefresh, Modal, Toast } from 'antd-mobile'; import { ListView, PullToRefresh, Modal, Toast } from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import RepairItem from '../Repair/components/RepairItem'; import RepairItem from '../Repair/components/RepairItem';
import { fetchReportRepairList, dealRepair } from '../../api/index'; import { fetchReportRepairList, dealRepair } from '../../api/index';
...@@ -9,6 +9,9 @@ import onCheckIcon from '../../images/Check/radio_on_btn@2x.png'; ...@@ -9,6 +9,9 @@ import onCheckIcon from '../../images/Check/radio_on_btn@2x.png';
class RepairDeal extends Component { class RepairDeal extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const list = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
});
this.state = { this.state = {
refreshing: false, refreshing: false,
down: true, down: true,
...@@ -16,14 +19,21 @@ class RepairDeal extends Component { ...@@ -16,14 +19,21 @@ class RepairDeal extends Component {
pagination: { pagination: {
nowDate: '', nowDate: '',
pageNum: 1, pageNum: 1,
pageSize: 50, pageSize: 10,
}, },
list: [], list: list,
sourceList: [],
}; };
} }
componentDidMount() { componentDidMount() {
this.fetchList(); this.fetchList();
} }
updateList = () => {
const { sourceList } = this.state;
this.setState(({ list }) => ({
list: list.cloneWithRows(sourceList),
}));
};
fetchList = fetchMore => { fetchList = fetchMore => {
this.setState({ refreshing: true }); this.setState({ refreshing: true });
const { pagination } = this.state; const { pagination } = this.state;
...@@ -41,29 +51,24 @@ class RepairDeal extends Component { ...@@ -41,29 +51,24 @@ class RepairDeal extends Component {
fetchReportRepairList(entity) fetchReportRepairList(entity)
.then(res => { .then(res => {
this.setState( this.setState(
({ list, pagination }) => ({ sourceList }) =>
fetchMore fetchMore
? res.data.length ? res.data.length
? { ? {
list: [...list, ...res.data], sourceList: [...sourceList, ...res.data],
pagination: { pagination: entity,
...pagination,
pageNum: pagination.pageNum + 1,
},
refreshing: false, refreshing: false,
} }
: { : {
refreshing: false, refreshing: false,
} }
: { : {
list: res.data, sourceList: res.data,
pagination: { pagination: entity,
...pagination,
nowDate,
},
refreshing: false, refreshing: false,
} }
); );
this.updateList();
}) })
.catch(err => { .catch(err => {
Toast.fail(err.msg || '请求失败!'); Toast.fail(err.msg || '请求失败!');
...@@ -116,36 +121,12 @@ class RepairDeal extends Component { ...@@ -116,36 +121,12 @@ class RepairDeal extends Component {
perviewVisibility: false, perviewVisibility: false,
}); });
}; };
render() { MyBody = props => {
const { perviewVisibility, selectedImgList, perviewIndex } = this.state; const { perviewVisibility, selectedImgList, perviewIndex } = this.state;
return [ return (
<PullToRefresh <div className={styles.repairList}>
key="repairList"
damping={60}
ref={el => (this.ptr = el)}
style={{
height: this.state.height,
overflow: 'auto',
}}
indicator={{ deactivate: '上拉可以刷新' }}
direction={'up'}
refreshing={this.state.refreshing}
onRefresh={this.refreshHandle}
>
<div className={styles.listInfo}>显示最近半年的报修记录</div> <div className={styles.listInfo}>显示最近半年的报修记录</div>
{this.state.list.length ? ( {props.children}
this.state.list.map(i => (
<RepairItem
key={i.id}
data={i}
dealHandle={this.dealHandle}
showView={this.showViewHandle}
/>
))
) : (
<div className={styles.noData}>暂无数据</div>
)}
</PullToRefresh>,
<Modal <Modal
key="repairImgPerview" key="repairImgPerview"
className={styles.perViewDialog} className={styles.perViewDialog}
...@@ -156,8 +137,38 @@ class RepairDeal extends Component { ...@@ -156,8 +137,38 @@ class RepairDeal extends Component {
title="" title=""
> >
<Perview data={selectedImgList} index={perviewIndex} /> <Perview data={selectedImgList} index={perviewIndex} />
</Modal>, </Modal>
]; </div>
);
};
render() {
const { list, pagination } = this.state;
return (
<ListView
style={{
height: this.state.height,
}}
className={styles.scrollWrap}
dataSource={list}
pageSize={pagination.pageSize}
renderBodyComponent={() => <this.MyBody />}
renderRow={rowData => (
<RepairItem
key={rowData.id}
data={rowData}
dealHandle={this.dealHandle}
showView={this.showViewHandle}
/>
)}
onEndReached={this.refreshHandle}
pullToRefresh={
<PullToRefresh
refreshing={this.state.refreshing}
onRefresh={this.fetchList}
/>
}
/>
);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment