ShareDetailContainer.js
5.96 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
import React, { Component } from 'react';
import ReactNative,{ StyleSheet, View, NativeModules, Dimensions, Platform, NativeAppEventEmitter} from "react-native";
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Map } from 'immutable';
import queryString from 'query-string';
import * as shareDetailActions from '../reducers/shareDetail/shareDetailActions';
import ShareDetail from '../components/ShareDetail';
import { getSlicedUrl } from '../../classify/utils/Utils';
const actions = [
shareDetailActions,
];
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 ShareDetailContainer extends Component {
constructor(props) {
super(props);
this.showShareView = this.showShareView.bind(this);
this._goBack = this._goBack.bind(this);
this._addFavorite = this._addFavorite.bind(this);
this._jumpWithUrl = this._jumpWithUrl.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._onPressProduct = this._onPressProduct.bind(this);
this.subscription = NativeAppEventEmitter.addListener(
'ProductShareDetailEvent',
() => {
let { shareDetail } = this.props;
let shareDetailInfo = shareDetail ? shareDetail.toJS(): {};
let productInfo = shareDetailInfo.productInfo;
if (!productInfo || productInfo == {}) {
return
}
this.showShareView(productInfo);
}
);
}
render() {
let { shareDetail } = this.props;
return (
<View style={styles.container}>
<ShareDetail
shareDetail={shareDetail}
showShareView={this.showShareView}
goBack={this._goBack}
addFavorite={this._addFavorite}
jumpWithUrl={this._jumpWithUrl}
onEndReached={this._onEndReached}
onPressProduct={this._onPressProduct}
collage_activity_id={this.props.collage_activity_id}
collage_rebates_amount={this.props.collage_rebates_amount}
collage_price={this.props.collage_price}
/>
</View>
)
}
componentDidMount() {
this.props.actions.fetchShareCodeInfo(this.props.product_skn);
this.props.actions.fetchShareDetail({product_skn: this.props.product_skn});
this.props.actions.fetchFavoriteInfo({id: this.props.product_id, type: 'product'});
this.props.actions.getProductList(false,this.props.product_skn);
}
componentWillUnmount() {
this.subscription && this.subscription.remove();
}
_onPressProduct(product) {
let productSkn = product && product.get('product_skn', 0);
let product_id = product && product.get('product_id', 0);
//拼团需要传递的字段
let collage_activity_id = product && product.get('collage_activity_id', -1);
let collage_price = product && product.get('collage_price', 0);
if (!productSkn) {
return;
}
let pageName = 'iFP_Alliance';
if (Platform.OS === 'android') {
pageName = 'aFP_Alliance';
}
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.minealliance","params":{"type":"shareDetail","title":"有赚商品详情", "product_skn":"${productSkn}", "product_id": "${product_id}" ,"from_page_name":"${pageName}", "collage_activity_id":"${collage_activity_id}", "collage_price":"${collage_price}"}}`;
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
_onEndReached() {
this.props.actions.getProductList(false,this.props.product_skn);
}
_addFavorite = () => {
this.props.actions.addFavorite({id: this.props.product_id, type: 'product'});
}
showShareView = (productInfo) => {
let { host } = this.props.app;
let { shareDetail } = this.props;
let shareDetailJS = shareDetail ? shareDetail.toJS(): null;
let goodsList = productInfo.goodsList;
let productPriceBo = productInfo.productPriceBo;
let goodsInfo = goodsList ? goodsList[0] : {};
let productSkn = productPriceBo.productSkn;
let productUrl = productInfo.productUrl;
let shortUrl = shareDetailJS && shareDetailJS.shareCodeInfo ? shareDetailJS.shareCodeInfo.shortUrl : '';
let unionType = ReactNative.NativeModules.YH_CommonHelper.unionType();
let qrCode;
if (unionType) {
let params = {
productSkn,
union_type: unionType,
}
productUrl = shortUrl;
let paramsString = encodeURIComponent(JSON.stringify(params));
qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + paramsString + '&miniQrType=7';
}else {
qrCode = host + '/wechat/miniapp/img-check.jpg?param=' + productSkn + '&miniQrType=7';
}
let shareParam = {
title: productInfo.productName ? productInfo.productName : '',
content: productInfo.productName ? productInfo.productName : '',
image: goodsInfo.colorImage,
url: productUrl,
miniProgramPath: 'pages/goodsDetail/goodsDetail?productSkn=' + productSkn,
miniProgramQCodeUrl: qrCode,
product_name: productInfo.productName ? productInfo.productName : '',
sales_price: productPriceBo.originalSalesPrice + "",
productDefaultImage: goodsInfo.colorImage,
fromType: 'productDetail',
};
ReactNative.NativeModules.YH_CommonHelper.shareInfoWithParam(shareParam);
}
_goBack = () => {
NativeModules.YH_CommonHelper.goBack();
}
_jumpWithUrl = () => {
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${this.props.product_skn}"}}`;
NativeModules.YH_CommonHelper.jumpWithUrl(url);
}
}
const DEVICE_WIDTH_RATIO = Dimensions.get('window').width / 375;
const styles = StyleSheet.create({
container: {
flex: 1,
}
})
export default connect(mapStateToProps, mapDispatchToProps)(ShareDetailContainer)