GroupPurchaseContainer.js
6.36 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {Dimensions, NativeAppEventEmitter, Platform, StyleSheet, View} from 'react-native'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as groupPurchaseActions from '../reducers/groupPurchase/groupPurchaseActions';
import GroupPurchase from '../components/GroupPurchase';
import ShareViewModal from '../components/ShareViewModal';
import ListSnapshootShare from '../components/ListSnapshootShare';
import {getSlicedUrl} from '../../classify/utils/Utils';
import Helper from '../utils/Helper';
const actions = [
groupPurchaseActions,
];
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 375;
function mapStateToProps(state) {
return {
...state
};
}
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
class GroupPurchaseContainer extends Component {
constructor(props) {
super(props);
this._onEndReached = this._onEndReached.bind(this);
this._didTouchBanner = this._didTouchBanner.bind(this);
this._didTouchProduct = this._didTouchProduct.bind(this);
this.showShareView = this.showShareView.bind(this);
this.shareMiniApp = this.shareMiniApp.bind(this);
this.showSnapshootShare = this.showSnapshootShare.bind(this);
this.shareSnapshootAction = this.shareSnapshootAction.bind(this);
this.jumpToMinePurchaseOrder = this.jumpToMinePurchaseOrder.bind(this);
this.subscription = NativeAppEventEmitter.addListener(
'ShareCollageListEvent',
() => {
this.props.actions.showShareView(true);
}
);
}
async componentDidMount() {
let { actions } = this.props;
actions.getProductList();
actions.fetchResourceInfo();
}
componentWillUnmount() {
this.subscription && this.subscription.remove();
}
_onEndReached() {
this.props.actions.getProductList();
}
_didTouchBanner(url) {
if (!url) {
return;
}
let params = {
URL: url,
};
ReactNative.NativeModules.YH_CommonHelper.logEvent('YB_GROUP_LIST_BANNER_C', params);
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
_didTouchProduct(productSkn,activityId,newSrc) {
if(newSrc){
let arr=newSrc.split("?");
newSrc = arr[0];
}
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${productSkn}","product_icon":"${newSrc}","activity_id":"${activityId}","activity_type":"groupPurchase"}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
shareSnapshootAction(shareType,url) {
let fromPage = 'GroupPurchaseDetail';
let param = {
shareType,
imageUrl: url,
fromPage,
}
ReactNative.NativeModules.YH_CommonHelper.shareImageToWXMini(param);
this.props.actions.showSnapshootShare(false);
}
showShareView(show){
this.props.actions.showShareView(show);
}
async shareMiniApp(){
let {
activityId,
resource,
shareCodeInfo,
groupListParams,
} = this.props.groupPurchase;
if (!resource) {
return;
}
let miniProgramPath = '/pages/group/list?activityId=' + activityId;
miniProgramPath = Helper.joinWxProgramPath(miniProgramPath, groupListParams)
let fromPage = 'GroupPurchase';
let bigImage = shareCodeInfo.get('bigImage');
let productIcon = bigImage ? getSlicedUrl(bigImage,150*DEVICE_WIDTH_RATIO, 120*DEVICE_WIDTH_RATIO, 2) : '';
this.props.actions.showShareView(false);
let businessId = 'collage';
let param = {
title: shareCodeInfo.get('title'),
image: productIcon,
shareUrl: '',
miniProgramPath,
fromPage,
businessId
}
ReactNative.NativeModules.YH_CommonHelper.shareWXMiniProgram(param);
}
showSnapshootShare(show){
this.props.actions.showShareView(false);
this.props.actions.showSnapshootShare(show);
}
jumpToMinePurchaseOrder() {
let url = 'http://m.yohobuy.com?openby:yohobuy={"action":"go.mineGroupPurchase"}';
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
render() {
let {
activityId,
showShareView,
showSnapshootShare,
productList,
resource,
shareCodeInfo,
groupListParams,
} = this.props.groupPurchase;
let {
host,
unionType,
} = this.props.app;
let groupParams = Helper.excludeParams(groupListParams, false)
let param = {
...groupParams,
activityId,
}
let qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + encodeURIComponent(JSON.stringify(param)) + '&miniQrType=25' + '&miniapp_type=60';
return (
<View style={styles.container}>
<ShareViewModal show={showShareView} unionType={unionType} showShareView={this.showShareView} shareMiniApp={this.shareMiniApp} showSnapshootShare={this.showSnapshootShare}/>
<ListSnapshootShare
show={showSnapshootShare}
unionType={unionType}
shareCodeInfo={shareCodeInfo}
showSnapshootShare={this.showSnapshootShare}
shareSnapshootAction={this.shareSnapshootAction}
qrCode={qrCode}
/>
<GroupPurchase
jumpToMinePurchaseOrder={this.jumpToMinePurchaseOrder}
productList={productList}
resource={resource}
onEndReached={this._onEndReached}
didTouchBanner={this._didTouchBanner}
didTouchProduct={this._didTouchProduct}
/>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(GroupPurchaseContainer);