import { Component } from "react"; import { View, Text, Image, Button } from "@tarojs/components"; import { AtIcon } from "taro-ui"; import "./index.less"; import { getMyShopList, getMyShopDetail, getShareShopDetail, getShareShopProductList, getShareJump,bindShareJump } from "../../../service"; import storeManagement from "../../../images/storeManagement/storeManagement.png"; import storeManagementIcon from "../../../images/storeManagement/storeManagementIcon.png"; import ProductCard from "../../../components/ProductCard"; //卡片模块 import Taro from "@tarojs/taro"; export default class Index extends Component { state = { isManager: true, productList: [], //商品列表 shopDetail: {}, //店铺详情 page: 1, //页数 loading: false, //加载状态 totalPages: 1, // 添加总页数 isShare: false, // 是否是分享进入 shopId: '', // 店铺id }; // 获取店铺详情 getMyShopDetail = async () => { const res = this.state.isShare ? await getShareShopDetail({ store_id: this.state.shopId }) : await getMyShopDetail(); this.setState({ shopDetail: res, }); }; // 获取商品列表 getMyShopList = async (isBack) => { const { page } = this.state; this.setState({ loading: true }); const res = this.state.isShare ? await getShareShopProductList({ store_id: this.state.shopId, page, page_size: 10, }) : await getMyShopList({ page, page_size: 10, }); this.setState((prevState) => ({ productList: isBack ? res.goods_list : [...prevState.productList, ...res.goods_list], totalPages: res.total_pages, loading: false, })); }; componentDidShow() { const { router } = Taro.getCurrentInstance(); const params = router.params; console.log(params,1111); this.setState({ isManager: JSON.parse(params.isManager), //是否是店长 isShare: params.isShare||false, // 是否是分享进入 shopId: params.shopId||'', // 店铺id },()=>{ this.getMyShopDetail(); //获取店铺详情 this.getMyShopList(true); //获取店铺数据 }); } // 页面上拉触底 onReachBottom = () => { const { page, totalPages, loading } = this.state; if (page < totalPages && !loading) { this.setState( (prevState) => ({ page: prevState.page + 1 }), () => this.getMyShopList() ); } }; // 更换头像 handleChangeAvatar = () => { Taro.navigateTo({ url: "/pages/mineSub/infoEdit/index", }); }; // 配置分享内容 onShareAppMessage() { return { title: "店铺", path: `/pages/memberSub/storeManagement/index?shopId=${this.state.shopDetail.id}&isShare=true&isManager=false&&shareJump=${res.share_unique_value}`, imageUrl: '' } return getShareJump({ share_type:2, share_id: this.state.shopDetail.id }).then(res=>{ return { title: "店铺", path: `/pages/memberSub/storeManagement/index?shopId=${this.state.shopDetail.id}&isShare=true&isManager=false&&shareJump=${res.share_unique_value}`, imageUrl: '' } }) } render() { const { shopDetail, productList } = this.state; return ( {/* 头部卡片 */} {/* 分享店铺 */} {!this.state.isShare && ( )} {/* 个人信息 */} 更换头像 {shopDetail.store_name} {shopDetail.store_intro} {/* 商品列表 */} 店长推荐 {productList && ( {productList.map((product) => ( ))} )} {/* 底部购买模块 */} {this.state.isManager && ( {/* 浏览店铺 */} {/* 店铺模版 */} Taro.navigateTo({ url: "/pages/memberSub/productManagement/index", }) } className="bottom-buy-right-share" > 商品管理 )} ); } }