Commit fd181f78 by 姜雷

完善页面

parent d6dcd9a5
import config from '../config/index';
import axios from 'axios';
const path = config.SERVER_URL;
export const reportRepair = entity =>
axios({
url: path + '/repair/app/addRepair',
method: 'post',
data: entity,
});
...@@ -8,34 +8,52 @@ class ImagePicker extends Component { ...@@ -8,34 +8,52 @@ class ImagePicker extends Component {
super(props); super(props);
this.state = { this.state = {
done: false, done: false,
hasValue:
Object.keys(props).find(i => i === 'value') === -1 ? false : true,
files: [], files: [],
}; };
} }
shouldComponentUpdate(nextProps, nextState) {
const { value } = nextProps;
const { files } = nextState;
if (!value && files.length) {
this.deleteImage();
}
return true;
}
selectImage = () => { selectImage = () => {
const { done } = this.state; const { done } = this.state;
const { showView } = this.props;
if (done) { if (done) {
console.log('showView'); showView();
} else { } else {
this.refs.input.dispatchEvent(new MouseEvent('click')); this.refs.input.dispatchEvent(new MouseEvent('click'));
} }
}; };
deleteImage = e => { deleteImage = e => {
e.stopPropagation(); e && e.stopPropagation();
const { onChange } = this.props;
console.log('del'); console.log('del');
this.refs.input.value = ''; this.refs.input.value = '';
this.setState(() => ({ this.setState(() => ({
files: [], files: [],
done: false, done: false,
})); }));
if (onChange) {
onChange(null);
}
}; };
uploadImg = e => { uploadImg = e => {
const { onChange } = this.props;
const filesList = e.target.files; const filesList = e.target.files;
console.log(filesList);
const fileUrl = this.createObjectURL(filesList[0]); const fileUrl = this.createObjectURL(filesList[0]);
this.setState(() => ({ this.setState(() => ({
files: [fileUrl], files: [fileUrl],
done: true, done: true,
})); }));
if (onChange) {
onChange(filesList);
}
}; };
createObjectURL = blob => { createObjectURL = blob => {
if (window.URL) { if (window.URL) {
......
...@@ -8,6 +8,8 @@ class Select extends Component { ...@@ -8,6 +8,8 @@ class Select extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
hasValue:
Object.keys(props).find(i => i === 'value') === -1 ? false : true,
value: [], value: [],
}; };
} }
...@@ -41,10 +43,14 @@ class Select extends Component { ...@@ -41,10 +43,14 @@ class Select extends Component {
okHandle = () => { okHandle = () => {
const { onChange } = this.props; const { onChange } = this.props;
const { value } = this.picker.state; const { value } = this.picker.state;
onChange && onChange(value); const { hasValue } = this.state;
this.setState({ if (hasValue) {
value: value, onChange && onChange(value);
}); } else {
this.setState({
value: value,
});
}
this.closePickerHandle(); this.closePickerHandle();
}; };
cancelHandle = () => { cancelHandle = () => {
...@@ -56,12 +62,23 @@ class Select extends Component { ...@@ -56,12 +62,23 @@ class Select extends Component {
}; };
render() { render() {
const { placeholder, data } = this.props; const { placeholder, data } = this.props;
const { value } = this.state; const { value, hasValue } = this.state;
let text = value.length
? data.find(item => item.value === value[0]).label let text = '';
: placeholder if (hasValue) {
? placeholder let val = this.props.value;
: ''; text = val.length
? data.find(item => item.value === val[0]).label
: placeholder
? placeholder
: '';
} else {
text = value.length
? data.find(item => item.value === value[0]).label
: placeholder
? placeholder
: '';
}
return ( return (
<div className={styles.selectWrap} onClick={this.showPickerView}> <div className={styles.selectWrap} onClick={this.showPickerView}>
{text} {text}
......
import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import styles from './style.css';
class Perview extends Component {
constructor(props) {
super(props);
let viewDom = document.getElementById('PerviewWrap');
if (viewDom) {
this.node = viewDom;
} else {
viewDom = document.createElement('div');
viewDom.id = 'PerviewWrap';
document.body.appendChild(viewDom);
this.node = viewDom;
}
}
componentWillUnmount() {
window.document.body.removeChild(this.node);
}
render() {
const { visibility } = this.props;
return visibility
? createPortal(
<div className={styles}>
<div className={styles.mask} />
<div className={styles.content}>
<div className={styles.imgBox} />
<div className={styles.footer}>
<div className={styles.per}>
<div className={styles.leftIcon} />
</div>
<div className={styles.pagination} />
<div className={styles.next}>
<div className={styles.rightIcon} />
</div>
</div>
</div>
</div>,
this.node
)
: null;
}
}
export default Perview;
.mask {
composes: mask from '../Popup/style.css';
}
.content {
}
...@@ -16,50 +16,6 @@ class RepairList extends Component { ...@@ -16,50 +16,6 @@ class RepairList extends Component {
pageSize: 50, pageSize: 50,
}, },
list: [], list: [],
demoList: [
{
address: '该卡北师大ask绝对不阿斯顿快捷巴士的科比爱的快捷巴士的空间',
applyCellphone: '18108099999',
applyIdentity: 'string',
area: 'string',
areaId: 0,
createDate: '2018-09-27T03:18:47.973Z',
dealDate: '2018-09-27T03:18:47.973Z',
dealState: 1,
endDate: '2018-09-27T03:18:47.973Z',
id: 0,
name: 'string',
pageNum: 0,
pageSize: 0,
repairCellphone: 'string',
startDate: '2018-09-27T03:18:47.973Z',
term: 'f阿斯顿 adasdasdasdasdasd',
termId: 0,
uploadImg: 'string',
userId: 0,
},
{
address: 'string',
applyCellphone: 'string',
applyIdentity: 'string',
area: 'string',
areaId: 0,
createDate: '2018-09-27T03:18:47.973Z',
dealDate: '2018-09-27T03:18:47.973Z',
dealState: 2,
endDate: '2018-09-27T03:18:47.973Z',
id: 1,
name: 'string',
pageNum: 0,
pageSize: 0,
repairCellphone: 'string',
startDate: '2018-09-27T03:18:47.973Z',
term: 'string',
termId: 0,
uploadImg: '',
userId: 0,
},
],
}; };
} }
componentDidMount() { componentDidMount() {
...@@ -77,6 +33,9 @@ class RepairList extends Component { ...@@ -77,6 +33,9 @@ class RepairList extends Component {
...pagination, ...pagination,
}).then(res => { }).then(res => {
console.log(res); console.log(res);
this.setState({
list: res.data,
});
}); });
} }
refreshHandle = () => { refreshHandle = () => {
......
...@@ -11,15 +11,14 @@ import imgIcon from './images/upload_pic_icon@2x.png'; ...@@ -11,15 +11,14 @@ import imgIcon from './images/upload_pic_icon@2x.png';
import ImagePicker from '../../components/Input/ImagePicker/ImagePicker'; import ImagePicker from '../../components/Input/ImagePicker/ImagePicker';
import Select from '../../components/Input/Select/Select'; import Select from '../../components/Input/Select/Select';
import { fetchRepairArea, fetchRepairTerm } from '../../api/index'; import { fetchRepairArea, fetchRepairTerm } from '../../api/index';
import { reportRepair } from '../../api/repairAdd';
import Perview from '../../components/Perview/Perview';
class ReprtRepair extends Component { class ReprtRepair extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
areaList: [ areaList: [],
{ value: 'ddsd1', label: 'fgfasd1' },
{ value: 'ddsd2', label: 'fgfasd2' },
],
termList: [], termList: [],
applyForm: { applyForm: {
name: '', name: '',
...@@ -31,8 +30,10 @@ class ReprtRepair extends Component { ...@@ -31,8 +30,10 @@ class ReprtRepair extends Component {
term: '', term: '',
termId: '', termId: '',
address: '', address: '',
uploadImg: [], uploadImg: [null, null, null],
}, },
perviewVisibility: true,
perviewIndex: 0,
}; };
} }
componentDidMount() { componentDidMount() {
...@@ -67,7 +68,22 @@ class ReprtRepair extends Component { ...@@ -67,7 +68,22 @@ class ReprtRepair extends Component {
console.log(err); console.log(err);
}); });
} }
resetApplyForm = () => {
this.setState({
applyForm: {
name: '',
userId: '',
repairCellphone: '',
applyIdentity: '学生',
area: '',
areaId: '',
term: '',
termId: '',
address: '',
uploadImg: [null, null, null],
},
});
};
onChangeHandle = e => { onChangeHandle = e => {
const { name, value } = e.target; const { name, value } = e.target;
this.setState(({ applyForm }) => ({ this.setState(({ applyForm }) => ({
...@@ -86,6 +102,25 @@ class ReprtRepair extends Component { ...@@ -86,6 +102,25 @@ class ReprtRepair extends Component {
}, },
})); }));
}; };
onImagePicker = (index, val) => {
console.log(index, val);
const { uploadImg } = this.state.applyForm;
uploadImg[index] = val;
this.setState(({ applyForm }) => ({
applyForm: {
...applyForm,
uploadImg: uploadImg,
},
}));
};
showViewHandle = index => {
console.log('showViewHandle');
console.log(index);
this.setState({
perviewVisibility: true,
perviewIndex: index,
});
};
validateForm = () => { validateForm = () => {
const { applyForm } = this.state; const { applyForm } = this.state;
if (!applyForm.name) { if (!applyForm.name) {
...@@ -118,9 +153,50 @@ class ReprtRepair extends Component { ...@@ -118,9 +153,50 @@ class ReprtRepair extends Component {
if (!this.validateForm()) { if (!this.validateForm()) {
return; return;
} }
let formData = new FormData();
this.state.applyForm.uploadImg.map(i => {
if (i) {
console.log(i);
formData.append('file', i[0]);
}
return i;
});
let area = this.state.areaList.find(
i => i.value === this.state.applyForm.areaId[0]
).label;
let term = this.state.termList.find(
i => i.value === this.state.applyForm.termId[0]
).label;
formData.append('userId', '1');
// product 需要登陆后的用户ID
formData.append('applyIdentity', this.state.applyForm.applyIdentity);
formData.append('area', area);
formData.append('term', term);
formData.append('address', this.state.applyForm.address);
formData.append('repairCellphone', this.state.applyForm.repairCellphone);
formData.append('termId', this.state.applyForm.termId);
formData.append('areaId', this.state.applyForm.areaId);
formData.append('name', this.state.applyForm.name);
reportRepair(formData)
.then(res => {
console.log(res);
console.log('resetForm');
this.resetApplyForm();
})
.catch(err => {
console.log(err);
});
}; };
render() { render() {
const { applyForm, areaList, termList } = this.state; const {
applyForm,
areaList,
termList,
perviewVisibility,
perviewIndex,
} = this.state;
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>
...@@ -194,7 +270,8 @@ class ReprtRepair extends Component { ...@@ -194,7 +270,8 @@ class ReprtRepair extends Component {
placeholder="请选择" placeholder="请选择"
data={areaList} data={areaList}
cols={1} cols={1}
onChange={val => this.onSelectHandle('area', val)} value={applyForm.areaId}
onChange={val => this.onSelectHandle('areaId', val)}
/> />
</div> </div>
</div> </div>
...@@ -209,7 +286,8 @@ class ReprtRepair extends Component { ...@@ -209,7 +286,8 @@ class ReprtRepair extends Component {
placeholder="请选择" placeholder="请选择"
data={termList} data={termList}
cols={1} cols={1}
onChange={val => this.onSelectHandle('term', val)} value={applyForm.termId}
onChange={val => this.onSelectHandle('termId', val)}
/> />
</div> </div>
</div> </div>
...@@ -224,6 +302,15 @@ class ReprtRepair extends Component { ...@@ -224,6 +302,15 @@ class ReprtRepair extends Component {
placeholder="输入报修地址" placeholder="输入报修地址"
rows={3} rows={3}
count={50} count={50}
value={this.state.applyForm.address}
onChange={val =>
this.setState(({ applyForm }) => ({
applyForm: {
...applyForm,
address: val,
},
}))
}
/> />
<div className={styles.listItem}> <div className={styles.listItem}>
<i className={styles.itemIcon}> <i className={styles.itemIcon}>
...@@ -232,13 +319,30 @@ class ReprtRepair extends Component { ...@@ -232,13 +319,30 @@ class ReprtRepair extends Component {
<span className={styles.itemLabel}>上传图片</span> <span className={styles.itemLabel}>上传图片</span>
</div> </div>
<div className={styles.imageArea}> <div className={styles.imageArea}>
<ImagePicker /> <ImagePicker
<ImagePicker /> value={applyForm.uploadImg[0]}
<ImagePicker /> showView={() => this.showViewHandle(0)}
onChange={fileList => this.onImagePicker(0, fileList)}
/>
<ImagePicker
value={applyForm.uploadImg[1]}
showView={() => this.showViewHandle(1)}
onChange={fileList => this.onImagePicker(1, fileList)}
/>
<ImagePicker
value={applyForm.uploadImg[2]}
showView={() => this.showViewHandle(2)}
onChange={fileList => this.onImagePicker(2, fileList)}
/>
</div> </div>
<Button className={styles.applyBtn} onClick={this.startApply}> <Button className={styles.applyBtn} onClick={this.startApply}>
提交 提交
</Button> </Button>
<Perview
visibility={perviewVisibility}
data={applyForm.uploadImg}
index={perviewIndex}
/>
</div> </div>
); );
} }
......
/* index */ /* index */
:global(.RepairContent) { :global(.RepairContent) {
flex: auto; flex: auto;
overflow: hidden; overflow-y: auto;
-webkit-overflow-scrolling: touch;
} }
.footer { .footer {
width: 100%; width: 100%;
......
...@@ -15,6 +15,7 @@ p { ...@@ -15,6 +15,7 @@ p {
img { img {
display: block; display: block;
width: 100%; width: 100%;
height: 100%;
} }
[aspectratio] { [aspectratio] {
position: relative; position: relative;
......
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