addEdit.js
7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import React, { Component } from 'react';
import { connect } from 'dva';
import { InputItem,Toast} from 'antd-mobile';
import { Upload, Icon, message } from 'antd';
import shareHide from "../../utils/shareHide";
import {getCardName} from '../../utils/dataFilter'
import request from '../../utils/request'
import css from './css.less';
import styles from '../../routes/GovernorTraining/css.less'
function beforeUpload(file) {
const isJPG = (file.type === 'image/jpeg'||file.type === 'image/png');
if (!isJPG) {
message.error('只能上传jpg和png格式的图片!');
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
message.error('图片大小不能大于5MB!');
}
return isJPG && isLt5M;
}
class AddCardEditor extends Component{
constructor(props) {
super(props);
let cardInfo = JSON.parse(sessionStorage.getItem("cardInfo"));
this.state = {
cardInfo:cardInfo,
headUrl:cardInfo.headUrl || "",//头像
name: cardInfo.name || "",//名字
postName: getCardName(cardInfo.roleId) || "",//职位
Orgwork:cardInfo.orgName || "",//机构
phone:cardInfo.number || "",//手机号
qrcode: cardInfo.qrcode || "",//微信二维码
loading: false,//头像的
loading2: false,//二维码的
userId:cardInfo.id || JSON.parse(localStorage.getItem("id")),//用户ID
}
}
componentDidMount() {
document.title = '我的信息';
let _this = this;
shareHide();
}
componentWillUnmount(){
Toast.hide();
}
handleChange = info => {
if (info.file.status === 'uploading') {
this.setState({ loading: true });
return;
}
if (info.file.status === 'done') {
this.setState({
loading: false,
})
}
}
handleChange2 = info => {
if (info.file.status === 'uploading') {
this.setState({ loading2: true });
return;
}
if (info.file.status === 'done') {
this.setState({
loading2: false,
})
}
}
saveHandle=()=>{
let _this = this;
this.props.dispatch({
type: 'BusinessCard/UpdateBusinessCardInfo',
payload: {
"id":this.state.userId,
"qrcode":this.state.qrcode,
"headUrl":this.state.headUrl,
},
callback(res) {
//保存卡片数据
Toast.info("保存成功",2)
setTimeout(function(){
_this.props.history.go(-1);
},2000)
}
})
}
render() {
let {fileList,qrcode,headUrl} = this.state;
const uploadButton2 = (
<div className={css.qrcodeSection}>
<div className={css.text}>
{this.state.loading2 ? <Icon type="loading" /> : <div style={{fontSize:".24rem"}}>+</div>}
</div>
</div>
);
const uploadButton = (
this.state.loading ? <Icon type="loading" /> : <img src={require("../../assets/image/defaultHead.png")} alt="avatar" />
);
const propsUpload1 = {
listType:"picture-card",
className:"avatar-uploader",
showUploadList:false,
beforeUpload:beforeUpload,
customRequest:(files)=>{
let file = files.file;
let fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
let userId = this.state.userId;
let formData = new FormData();
formData.append('file', file);
formData.append('fileType', "head");
formData.append('functionType', 'businessCard');
formData.append('userId', userId);
request(`/o2o/ai/fileUpload`, {
method: 'POST',
body: formData
}).then((res) => {
if (res.data.status) {
this.setState({
headUrl:res.data.data.fileAddress,
loading: false,
})
}
})
},
onChange:this.handleChange
};
const propsUpload2 = {
listType:"picture-card",
className:"avatar-uploader",
showUploadList:false,
beforeUpload:beforeUpload,
customRequest:(files)=>{
let file = files.file;
let fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
let userId = this.state.userId;
let formData = new FormData();
formData.append('file', file);
formData.append('fileType', "QRcode");
formData.append('functionType', 'businessCard');
formData.append('userId', userId);
request(`/o2o/ai/fileUpload`, {
method: 'POST',
body: formData
}).then((res) => {
if (res.data.status) {
this.setState({
qrcode:res.data.data.fileAddress,
loading2: false,
})
}
})
},
onChange:this.handleChange2
};
return (
<div className={css.businessCardEditWrap} style={{ background: '#fff' }}>
<div className={styles.ac_wrap}>
<div id="scrollSection">
<ul>
<li className={css.headsection}>
<label className={css.headText}>头像</label>
<div className={css.uploadHeadImg}>
<Upload {...propsUpload1}>
{headUrl ? (this.state.loading ? <Icon type="loading" /> : <img src={headUrl} alt="avatar" /> ) : uploadButton }
</Upload>
</div>
</li>
<li className={styles.require}>
<InputItem
type="text"
disabled={true}
value={this.state.name}
placeholder = {this.state.disabled?'':"请输入姓名"}
>姓名</InputItem>
</li>
<li className={styles.require}>
<InputItem
type="text"
disabled={true}
value={this.state.postName}
>职务</InputItem>
</li>
<li className={styles.require}>
<InputItem
type="text"
disabled={true}
value={this.state.Orgwork}
>机构</InputItem>
</li>
<li className={styles.require}>
<InputItem
type="text"
disabled={true}
value={this.state.phone}
>手机号</InputItem>
</li>
<div className={css.QRcode}>
<div className={css.codeText}>上传二维码</div>
<div className={css.code}>
<Upload {...propsUpload2}>
{qrcode ? (this.state.loading2 ? <Icon type="loading" /> : <img src={qrcode} alt="avatar" /> ) : uploadButton2 }
</Upload>
</div>
</div>
<div className={css.saveBtn} onClick={()=>{this.saveHandle()}}>
<img src={require("../../assets/image/baocun.png")} alt="" />
</div>
</ul>
</div>
</div>
</div>
)
}
}
export default connect(({BusinessCard})=>({BusinessCard}))(AddCardEditor);