preview.js
8.08 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
import { Component, Fragment } from 'react';
import { connect } from 'dva';
import { Carousel, Toast, ActionSheet } from 'antd-mobile';
import moment from 'moment';
import share from '../../utils/share';
import shareHide from '../../utils/shareHide';
import {urlGetParams} from '../../utils/dataFilter'
import css from './css.less';
const isIPhone = new RegExp('\\biPhone\\b|\\biPod\\b', 'i').test(window.navigator.userAgent);
let wrapProps;
if (isIPhone) {
wrapProps = {
onTouchStart: e => e.preventDefault(),
};
}
class Preview extends Component{
constructor(props) {
super(props);
this.state = {
index: 0,
inviInfo: null,
isprev:'t'
}
}
showActionSheet = () => {
const { inviInfo } = this.state;
const BUTTONS = ['导航','取消'];
ActionSheet.showActionSheetWithOptions({
options: BUTTONS,
cancelButtonIndex: BUTTONS.length - 1,
maskClosable: true,
'data-seed': 'logId',
wrapProps,
},
(buttonIndex) => {
if (buttonIndex === 0) {
window.location.href = `https://api.map.baidu.com/marker?location=${JSON.parse(inviInfo.specificLocation).lat},${JSON.parse(inviInfo.specificLocation).lng}&title=目标位置&content=${inviInfo.activitySite}&output=html&src=webapp.baidu.openAPIdemo`;
}
});
}
componentDidMount() {
document.title = '邀请函';
const { search } = this.props.location;
const params = urlGetParams(window.location.href);
if (search) {
if(params.id){
this.setState({ isprev: ''+params.isprev });
this.getInfo(params);
}
}
}
getInfo = (params) => {
const _this = this;
this.props.dispatch({
type: 'Invitation/GetInvitListById',
payload: {
id:params.id
},
callback(res) {
const inviInfo = res[0];
let inviInfoCopy = { ...inviInfo, specificLocation: JSON.parse(inviInfo.specificLocation) };
let urlShare = "";
if(params.isShare){//处理多次转发参数问题
urlShare = window.location.href;
}else{
urlShare = `${window.location.href.split('?')[0]}?isprev=2&id=${params.id}&isShare=t&phoneNum=${localStorage.getItem('number')}`;
}
share({
decodeUrl: window.location.href.split('#')[0],
title: inviInfo.activityName,
desc: inviInfo.essay,
shareUrl: urlShare,
thumbnail: inviInfo.invitationPath,
record:{
"operCode": inviInfo.id,
"operTitle": inviInfo.activityName,
"operFunction": 100130,
"operType": 202,
"phoneNum": params.isShare ? params.phoneNum : ""
}
});
//点击记录
_this.props.dispatch({
type:"home/setClickRecord",
payload: {
"operCode": inviInfo.id,
"operFunction": 100130,
"operTitle": inviInfo.activityName,
"operType": 201,
"phoneNum":params.isShare ? params.phoneNum : ""
},
callback(data){
console.log('点击分享出去的链接进来记录一次')
}
});
shareHide(false);
sessionStorage.setItem('invitationInfo', JSON.stringify(inviInfoCopy))
_this.setState({ inviInfo }, () => {
const ppoint = inviInfoCopy.specificLocation;
var map = new window.BMap.Map("invitationMap"); // 创建地图实例
map.disableDragging();
map.disableDoubleClickZoom();
map.disablePinchToZoom();
var point = new window.BMap.Point(ppoint.lng, ppoint.lat); // 创建点坐标
var loadCount = 1;
map.centerAndZoom(point, 17);
let marker = new window.BMap.Marker(point); // 创建标注
map.addOverlay(marker);
// 解决地图初始化位置和标注偏移问题
map.addEventListener("tilesloaded", function () {
if (loadCount == 1) {
map.setCenter(point);
}
loadCount = loadCount + 1;
});
});
}, error(err) {
Toast.error(err.message, 2);
}
})
}
render() {
const { inviInfo, isprev } = this.state;
return (
<div className={css.prevWrap}>
{
inviInfo && <Fragment>
<div className={css.prev}>
<div className={css.bg + ' ' + (isprev === 't' ? css.isprev : '')}><img src={inviInfo.invitationPath} alt="" /></div>
<div className={css.carouselWrap} style={{ color: inviInfo.colour ? inviInfo.colour:'#fff'}}>
<Carousel
selectedIndex={this.state.index}
autoplay={false}
infinite
dots={false}
>
<div className={css.pagea}>
<div className={css.pageaWrap}>
<div className={css.activityName}>{inviInfo.activityName}</div>
<div className={css.subtit}>时间</div>
<div className={css.subcon}>{moment(inviInfo.activityTime).format('YYYY-MM-DD HH:mm')}</div>
<div className={css.subtit}>地点</div>
<div className={css.subcon}>{inviInfo.activitySite + inviInfo.activityAdress}</div>
</div>
</div>
<div className={css.pageb}>
<div className={css.pagebWrap}>
<div className={css.con}>尊敬的{inviInfo.named}: </div>
<div className={css.con} style={{ textIndent: '2em' }}>{inviInfo.essay}</div>
<div className={css.con} style={{ textAlign: 'right' }}>{moment(inviInfo.updateTime).format('YYYY-MM-DD')}</div>
<div className={css.con} style={{ textAlign: 'right' }}>{inviInfo.invitationMessage}</div>
</div>
</div>
<div className={css.pageb}>
<div className={css.pagebWrap}>
<div className={css.con}>联系电话:{inviInfo.number}</div>
<div className={css.con}>活动时间:{moment(inviInfo.activityTime).format('YYYY-MM-DD HH:mm')}</div>
<div className={css.con}>活动地点:{inviInfo.activitySite + inviInfo.activityAdress}</div>
<div className={css.mapWrap} onClick={this.showActionSheet}>
<div id="invitationMap" style={{ height: '100%' }}></div>
</div>
</div>
</div>
</Carousel>
</div>
<div className={css.btn_left} onClick={() => {
const { index } = this.state;
if (index !== 0) {
this.setState({ index: index - 1 })
} else {
this.setState({ index: 2 })
}
}}></div>
<div className={css.btn_right} onClick={() => {
const { index } = this.state;
if (index < 2) {
this.setState({ index: index + 1 })
} else {
this.setState({ index: 0 })
}
}}></div>
{isprev === 't' && <div className={css.btnCreatePriew} style={{ backgroundColor: inviInfo.colour ? inviInfo.colour : '#FF9D5C'}}
onClick={() => {
const _this = this;
this.props.dispatch({
type: 'Invitation/addEdit',
payload: {
...inviInfo,
judegeId: 1,
updateTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
},
callback(res) {
Toast.success(res.message, 2);
_this.props.history.push({ pathname: "/invitation" });
}, error(err) {
Toast.error(err.message, 2);
}
})
}}
><img src={require("../../assets/image/yaoqinghan.png")} /></div>}
</div>
</Fragment>}
</div>
)
}
}
export default connect()(Preview);