|
@@ -1,6 +1,10 @@
|
1
|
1
|
import { Component } from "react";
|
2
|
2
|
import { View, Image, Button, Input } from "@tarojs/components";
|
3
|
|
-import { getShareJump, getProductDetail } from "../../../service/index";
|
|
3
|
+import {
|
|
4
|
+ getShareJump,
|
|
5
|
+ getProductDetail,
|
|
6
|
+ refreshToken,
|
|
7
|
+} from "../../../service/index";
|
4
|
8
|
import Taro from "@tarojs/taro";
|
5
|
9
|
import "./index.less";
|
6
|
10
|
|
|
@@ -25,51 +29,61 @@ export default class Index extends Component {
|
25
|
29
|
{
|
26
|
30
|
isSeckill: isSeckill === "true",
|
27
|
31
|
tagTitle,
|
28
|
|
- productDetail: productDetail ? JSON.parse(decodeURIComponent(productDetail)) : {},
|
29
|
|
- shareTitle: productDetail ? JSON.parse(decodeURIComponent(productDetail)).item_title : "",
|
|
32
|
+ productDetail: productDetail
|
|
33
|
+ ? JSON.parse(decodeURIComponent(productDetail))
|
|
34
|
+ : {},
|
|
35
|
+ shareTitle: productDetail
|
|
36
|
+ ? JSON.parse(decodeURIComponent(productDetail)).item_title
|
|
37
|
+ : "",
|
30
|
38
|
shareUserId,
|
31
|
39
|
id: id,
|
32
|
40
|
},
|
33
|
|
- async () => {
|
34
|
|
- Taro.showLoading({
|
35
|
|
- title: "加载中...",
|
36
|
|
- });
|
37
|
|
- try {
|
38
|
|
- await Promise.all([
|
39
|
|
- this.getProductDetail(id),
|
40
|
|
- this.getShareJump(id)
|
41
|
|
- ]);
|
42
|
|
- } finally {
|
43
|
|
- Taro.hideLoading();
|
44
|
|
- }
|
|
41
|
+ () => {
|
|
42
|
+ this.getProductDetail(id);
|
|
43
|
+ this.getShareJump(id);
|
45
|
44
|
}
|
46
|
45
|
);
|
47
|
46
|
}
|
48
|
47
|
// 获取商品详情
|
49
|
|
- getProductDetail = async (id='') => {
|
|
48
|
+ getProductDetail = async (id = "") => {
|
50
|
49
|
const res = await getProductDetail({
|
51
|
|
- goods_id: id||this.state.productDetail.id,
|
|
50
|
+ goods_id: id || this.state.productDetail.id,
|
52
|
51
|
});
|
53
|
52
|
this.setState({
|
54
|
53
|
productDetail: res,
|
55
|
54
|
shareTitle: res.item_title,
|
56
|
55
|
});
|
57
|
|
- }
|
|
56
|
+ };
|
|
57
|
+ // 重新获取分享跳转标识
|
|
58
|
+ regain = async () => {
|
|
59
|
+ const res = await refreshToken();
|
|
60
|
+ this.getShareJump();
|
|
61
|
+ };
|
58
|
62
|
// 获取分享跳转标识
|
59
|
|
- getShareJump = async (id='') => {
|
|
63
|
+ getShareJump = async (id = "") => {
|
|
64
|
+ Taro.showLoading({
|
|
65
|
+ title: "加载中...",
|
|
66
|
+ });
|
60
|
67
|
// 设置分享路径
|
61
|
68
|
const share_extend = JSON.stringify({
|
62
|
|
- path: `pages/indexSub/productDetail/index?id=${ id||this.state.productDetail.id}&isShare=true&isSeckill=${this.state.isSeckill}&shareType=11&&shareUserId=${this.state.shareUserId}`,
|
|
69
|
+ path: `pages/indexSub/productDetail/index?id=${
|
|
70
|
+ id || this.state.productDetail.id
|
|
71
|
+ }&isShare=true&isSeckill=${
|
|
72
|
+ this.state.isSeckill
|
|
73
|
+ }&shareType=11&&shareUserId=${this.state.shareUserId}`,
|
63
|
74
|
});
|
64
|
75
|
const res = await getShareJump({
|
65
|
76
|
share_type: 11,
|
66
|
|
- share_id: id||this.state.productDetail.id,
|
|
77
|
+ share_id: id || this.state.productDetail.id,
|
67
|
78
|
share_extend,
|
68
|
79
|
});
|
69
|
|
- this.setState({
|
70
|
|
- shareJump: res.share_unique_value,
|
71
|
|
- share_scheme_link: res.share_scheme_link,
|
72
|
|
- });
|
|
80
|
+ if (res.code == 200) {
|
|
81
|
+ this.setState({
|
|
82
|
+ shareJump: res.data.share_unique_value,
|
|
83
|
+ share_scheme_link: res.data.share_scheme_link,
|
|
84
|
+ });
|
|
85
|
+ }
|
|
86
|
+ Taro.hideLoading();
|
73
|
87
|
};
|
74
|
88
|
// 设置分享标题
|
75
|
89
|
handleShareTitleChange = (newTitle) => {
|
|
@@ -248,16 +262,25 @@ export default class Index extends Component {
|
248
|
262
|
<Input
|
249
|
263
|
onInput={this.handleShareTitleChange}
|
250
|
264
|
className="linkInput"
|
251
|
|
- value={this.state.share_scheme_link}
|
|
265
|
+ value={
|
|
266
|
+ this.state.share_scheme_link ||
|
|
267
|
+ "商品链接获取失败,请重新获取"
|
|
268
|
+ }
|
252
|
269
|
disabled
|
253
|
270
|
/>
|
254
|
271
|
<View className="copy-box">
|
255
|
272
|
<View className="copy-box-line"></View>
|
256
|
|
- <Image
|
257
|
|
- onClick={this.handleCopyLink}
|
258
|
|
- className="copy-box-icon"
|
259
|
|
- src="https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png"
|
260
|
|
- />
|
|
273
|
+ {this.state.share_scheme_link ? (
|
|
274
|
+ <Image
|
|
275
|
+ onClick={this.handleCopyLink}
|
|
276
|
+ className="copy-box-icon"
|
|
277
|
+ src="https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png"
|
|
278
|
+ />
|
|
279
|
+ ) : (
|
|
280
|
+ <View className="getLink" onClick={this.regain}>
|
|
281
|
+ 重新获取
|
|
282
|
+ </View>
|
|
283
|
+ )}
|
261
|
284
|
</View>
|
262
|
285
|
</View>
|
263
|
286
|
</View>
|