123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- import { Component } from "react";
- import { View, Text, Swiper, SwiperItem, Image } from "@tarojs/components";
- import { AtIcon } from "taro-ui";
- import {
- getProductDetail,
- getProductLikeList,
- getProductPromotion,
- getShareJump,
- bindShareJump,
- addLog,
- } from "../../../service";
- import { formatDate } from "../../../common/time";
- import { isDebounce } from "../../../common/debounce";
- import "./index.less";
- import Taro from "@tarojs/taro";
- import productDetailIcon from "../../../images/productDetail/productDetailIcon.png";
- import like from "../../../images/productDetail/like.png";
- import home from "../../../images/nav/home.png";
- import selfBuy from "../../../images/productDetail/selfBuy.png";
- import share from "../../../images/productDetail/share.png";
- import ProductCard from "../../../components/ProductCard";
- import Modal from "../../../components/Modal";
- import ShareModal from "../../../components/shareModal";
- import SignModal from "../../../components/signModal";
- export default class Index extends Component {
- state = {
- id: "",
- isShare: false,
- isOpened: "",
- productDetail: [],
- productLikeList: [],
- productPromotion: [],
- isHighCommission: false,
- isSeckill: false,
- shareJump: "",
- shareTitle: "",
- shareUserId: "",
- };
-
- fetchProductDetails = async (id) => {
- const res = await getProductDetail({
- goods_id: id,
- });
- this.setState({
- productDetail: res,
- });
- };
-
- getProductLikeList = async () => {
- const res = await getProductLikeList();
- this.setState({
- productLikeList: res,
- });
- };
-
- getProductPromotion = async () => {
- const res = await getProductPromotion({
- goods_id: [this.state.id],
- item_id: [this.state.productDetail.item_id],
- });
- this.setState({
- productPromotion:
- res.alibaba_idle_affiliate_general_link_convert_response.result.result,
- });
- };
- componentDidMount() {
-
- Taro.hideShareMenu({
- menus: ["shareAppMessage", "shareTimeline"],
- });
- const { id, isShare, isHighCommission, isSeckill, shareJump, shareUserId } =
- Taro.getCurrentInstance().router.params;
- let session_key = Taro.getStorageSync("session_key");
- let userInfo = Taro.getStorageSync("userInfo");
- let isShowSign = Taro.getStorageSync("isShowSign");
- this.setState(
- {
- id,
- isShare,
- isHighCommission: isHighCommission === "true",
- isSeckill: isSeckill === "true",
- shareUserId: shareUserId,
- },
- () => {
-
- shareJump &&
- Taro.setStorage({
- key: "shareJump",
- data: shareJump,
- });
- this.fetchProductDetails(id);
- this.getProductLikeList();
- if (session_key && shareJump) {
- this.bindShareJump();
- }
- if (this.state.isHighCommission || this.state.isSeckill) {
- this.handleLog("direct_to_product");
- }
- }
- );
-
- if (session_key && isShowSign!==false && userInfo && userInfo.user_identity == 0) {
- this.setState({
- isOpened: "sign",
- });
- }
- }
-
- handleCopy = (text) => {
- Taro.setClipboardData({
- data: text,
- success: () => {
- Taro.showToast({
- title: "复制成功",
- icon: "success",
- });
- },
- });
- };
-
- handleToHome = () => {
- Taro.switchTab({
- url: "/pages/index/index",
- });
- };
-
- handleBuy = async () => {
- if (!this.state.productPromotion.short_tpwd) {
- await this.getProductPromotion();
- }
- this.setState({
- isOpened: "self",
- });
- };
-
- handleLog = (event_type) => {
- if (!isDebounce(500)) return;
- if (this.state.isHighCommission || this.state.isSeckill) {
- const dayid = formatDate(new Date(), "YYYY-MM-DD");
- const event_type_title =
- event_type == "share_product_link"
- ? "点击分享赚"
- : event_type == "direct_to_product"
- ? "进入商品详情页"
- : "进入商品详情页";
- let userId = "";
- if (Taro.getStorageSync("loginInfo")) {
- userId = Taro.getStorageSync("loginInfo").id;
- }
-
- let ext = "";
- if (this.state.shareUserId) {
- ext = JSON.stringify({
- share_users_id: this.state.shareUserId,
- });
- }
- addLog({
- users_id: userId || 0,
- goods_id: Number(this.state.id),
- event_type_title,
- event_type,
- dayid,
- ext,
- });
- }
- };
-
- openSharePopup = async () => {
- const res = await getShareJump({
- share_type: 1,
- share_id: this.state.id,
- });
- this.setState({
- shareJump: res.share_unique_value,
- isOpened: "share",
- });
- this.handleLog("share_product_link");
- };
-
- bindShareJump = async () => {
- let shareJump = Taro.getStorageSync("shareJump");
- await bindShareJump({
- share_type: 1,
- share_unique_value: shareJump,
- });
- Taro.removeStorageSync("shareJump");
- };
-
- handleShareTitleChange = (newTitle) => {
- this.setState({
- shareTitle: newTitle,
- });
- };
-
- onShareAppMessage() {
- return {
- title: this.state.shareTitle || this.state.productDetail.item_title,
- path: `/pages/indexSub/productDetail/index?id=${this.state.id}&&isShare=true&&isHighCommission=${this.state.isHighCommission}&&isSeckill=${this.state.isSeckill}&&shareJump=${this.state.shareJump}`,
- imageUrl: this.state.productDetail.images[0].img,
- };
- }
-
- handleBack = () => {
- const pages = Taro.getCurrentPages();
- if (pages.length > 1) {
- Taro.navigateBack();
- } else {
- Taro.switchTab({
- url: "/pages/index/index",
- });
- }
- };
- render() {
- const { productDetail } = this.state;
- return (
- <View
- className="index"
- style={{ paddingTop: Taro.navigationBarHeight + "px" }}
- >
- {!this.state.isShare && (
- <View className="back-btn" onClick={this.handleBack}>
- <AtIcon value="chevron-left" size="24" color="#999999"></AtIcon>
- </View>
- )}
- {}
- <Swiper className="swiper" autoplay circular>
- {productDetail.images &&
- productDetail.images.map((imageObj, index) => (
- <SwiperItem key={index}>
- <Image
- className="swiper-img"
- src={imageObj.img}
- mode="aspectFill"
- />
- </SwiperItem>
- ))}
- </Swiper>
- {}
- <View className="product-info">
- {}
- <Text className="product-name">
- <Text className="self-tag">
- {this.state.isHighCommission
- ? "高佣专项"
- : this.state.isSeckill
- ? "鱼市秒杀"
- : "自营"}
- </Text>
- {productDetail.item_title}
- </Text>
- {}
- <View className="price-tag-row">
- {}
- <View className="price-box">
- <Text className="current-price">
- <Text className="currency">¥</Text>
- {productDetail.reserve_price}
- </Text>
- {productDetail.original_price != "0.00" && (
- <Text className="original-price">
- ¥{productDetail.original_price}
- </Text>
- )}
- </View>
- {}
- <View className="tag-box">
- <Text className="tag">
- 分享赚¥{productDetail.estimated_commission}
- </Text>
- </View>
- </View>
- {}
- <View className="divider" />
- {}
- <View className="product-number-row">
- <Text className="number-label">
- 商品编号:{productDetail.goods_number}
- </Text>
- <Text
- className="copy-btn"
- onClick={() => this.handleCopy("123456")}
- >
- 复制
- </Text>
- </View>
- </View>
- {}
- <View className="product-tag-row">
- <View className="tag-item">
- <Image src={productDetailIcon} mode="aspectFit" />
- <Text className="tag-text">渔市商品</Text>
- </View>
- <View className="tag-item">
- <Image src={productDetailIcon} mode="aspectFit" />
- <Text className="tag-text">品质保证</Text>
- </View>
- <View className="tag-item">
- <Image src={productDetailIcon} mode="aspectFit" />
- <Text className="tag-text">无忧售后</Text>
- </View>
- </View>
- {}
- <View className="guess-you-like">
- <Image src={like} mode="aspectFit" />
- <Text className="title">猜你喜欢</Text>
- </View>
- {}
- <View className="product-card-list">
- {this.state.productLikeList.map((product) => (
- <ProductCard key={product.id} product={product} />
- ))}
- </View>
- {}
- <View className="bottom-buy">
- <View onClick={this.handleToHome} className="bottom-buy-left">
- <Image src={home} mode="aspectFit" />
- <Text className="bottom-buy-text">首页</Text>
- </View>
- <View className="bottom-buy-right">
- {!this.state.isShare ? (
- <>
- <View
- onClick={this.openSharePopup}
- className="bottom-buy-right-self"
- >
- <Image src={share} mode="aspectFit" />
- <Text className="bottom-buy-text">分享赚</Text>
- </View>
- <View
- onClick={this.handleBuy}
- className="bottom-buy-right-share"
- >
- <Image src={selfBuy} mode="aspectFit" />
- <Text className="bottom-buy-text">自购省</Text>
- </View>
- </>
- ) : (
- <View onClick={this.handleBuy} className="bottom-buy-right-btn">
- <Text className="bottom-buy-text">立即购买</Text>
- </View>
- )}
- </View>
- </View>
- {}
- <Modal
- title="咸鱼口令已复制"
- isOpened={this.state.isOpened == "self"}
- productPromotion={this.state.productPromotion}
- linkText={this.state.productPromotion.short_tpwd}
- id={this.state.id}
- shareUserId={this.state.shareUserId}
- isHighCommission={this.state.isHighCommission}
- isSeckill={this.state.isSeckill}
- />
- {}
- {this.state.isOpened == "share" && (
- <ShareModal
- onClose={() => {
- this.setState({
- isOpened: "",
- shareTitle: productDetail.item_title,
- });
- }}
- isOpened={this.state.isOpened == "share"}
- product={this.state.productDetail}
- onShareTitleChange={this.handleShareTitleChange}
- />
- )}
- {}
- <SignModal isOpened={this.state.isOpened == "sign"} onClose={() => {
- this.setState({
- isOpened: "",
- });
- }}/>
- </View>
- );
- }
- }
|