detail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <!-- 黑色导航栏 -->
  5. <Navbar fixed leftIconColor="var(--light)" :bgColor="'var(--black)'">
  6. <template #center>
  7. <view class="nav_search">
  8. <Search
  9. v-model="searchValue"
  10. border="none"
  11. @input="onSearchInput"
  12. @click="onSearchClick"
  13. :placeholder="t('请输入商品链接或关键字')"
  14. >
  15. <template #prefix>
  16. <i class="icon-font icon-search"></i>
  17. </template>
  18. </Search>
  19. </view>
  20. </template>
  21. </Navbar>
  22. <!-- 店铺信息区域 -->
  23. <view class="shop-info-section">
  24. <view class="shop-header">
  25. <view class="shop-avatar">
  26. <image :src="shopInfo.avatar" mode="aspectFill" />
  27. </view>
  28. <view class="shop-details">
  29. <view class="shop-name">{{ shopInfo.name }}</view>
  30. <view class="shop-stats">
  31. <text class="followers">{{ shopInfo.followers }}粉丝</text>
  32. <text class="divider">|</text>
  33. <text class="rating">{{ shopInfo.rating }}%好评率</text>
  34. </view>
  35. </view>
  36. <view class="follow-btn" @click="toggleFollow">
  37. <i class="icon-font icon-plus"></i>
  38. <text>{{ isFollowed ? "已关注" : "关注" }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 商品列表 -->
  43. <view class="content">
  44. <List
  45. ref="listRef"
  46. :defaultParams="defaultParams"
  47. @datas="getList"
  48. :isLoading="false"
  49. >
  50. <template #item="{ item }">
  51. <productItem
  52. :item="item"
  53. @click="toProductDetail"
  54. @favorite="toggleProductFavorite"
  55. />
  56. </template>
  57. </List>
  58. </view>
  59. </view>
  60. <Tabbar page="shop" />
  61. </Theme>
  62. </template>
  63. <script setup>
  64. import { ref, reactive, onMounted } from "vue";
  65. import Tabbar from "@/components/tabbar";
  66. import Navbar from "@/components/navbar";
  67. import Search from "@/components/input";
  68. import List from "@/components/list";
  69. import productItem from "./components/product_item";
  70. import { t } from "@/locale";
  71. import { onLoad } from "@dcloudio/uni-app";
  72. import { SELLER_SELLER_INFO } from "@/api";
  73. // 搜索值
  74. const searchValue = ref("");
  75. // List组件引用
  76. const listRef = ref(null);
  77. // 默认参数
  78. const defaultParams = reactive({
  79. keyWord: "",
  80. id: "",
  81. });
  82. // 店铺信息
  83. const shopInfo = ref({
  84. id: 1,
  85. name: "香皂旗舰店",
  86. avatar: "/static/shop/shop1.png",
  87. followers: 100,
  88. rating: 90,
  89. });
  90. // 是否已关注
  91. const isFollowed = ref(false);
  92. // 商品数据
  93. const products = ref([
  94. {
  95. id: 1,
  96. image: "/static/products/product1.jpg",
  97. title: "种草这24cm不粘锅....",
  98. sales: "已售3000+",
  99. currentPrice: "80.20",
  100. originalPrice: "1380.00",
  101. isVideo: true,
  102. isFavorite: false,
  103. },
  104. {
  105. id: 2,
  106. image: "/static/products/product2.jpg",
  107. title: "#时尚锋芒计划",
  108. sales: "已售30万+",
  109. currentPrice: "210.99",
  110. originalPrice: "1380.00",
  111. isVideo: true,
  112. isFavorite: false,
  113. },
  114. {
  115. id: 3,
  116. image: "/static/products/product3.jpg",
  117. title: "种草这24cm不粘锅...",
  118. sales: "已售200+",
  119. currentPrice: "2100.00",
  120. originalPrice: "2380.00",
  121. isVideo: false,
  122. isFavorite: false,
  123. },
  124. {
  125. id: 4,
  126. image: "/static/products/product4.jpg",
  127. title: "种草这24cm不粘锅...",
  128. sales: "已售300+",
  129. currentPrice: "10.60",
  130. originalPrice: "13.00",
  131. isVideo: false,
  132. isFavorite: false,
  133. },
  134. {
  135. id: 5,
  136. image: "/static/products/product5.jpg",
  137. title: "种草这24cm不粘锅...",
  138. sales: "已售30",
  139. currentPrice: "2100.00",
  140. originalPrice: "2380.00",
  141. isVideo: false,
  142. isFavorite: false,
  143. },
  144. {
  145. id: 6,
  146. image: "/static/products/product6.jpg",
  147. title: "种草这24cm不粘锅...",
  148. sales: "已售100+",
  149. currentPrice: "10.60",
  150. originalPrice: "13.00",
  151. isVideo: false,
  152. isFavorite: false,
  153. },
  154. ]);
  155. // 过滤后的商品列表
  156. const filteredProducts = ref([]);
  157. // 搜索输入
  158. const onSearchInput = (value) => {
  159. searchValue.value = value;
  160. defaultParams.keyWord = value;
  161. // 触发列表刷新
  162. if (listRef.value) {
  163. listRef.value.handleRefresh();
  164. }
  165. };
  166. // 搜索点击
  167. const onSearchClick = () => {
  168. console.log("搜索:", searchValue.value);
  169. };
  170. // Tab切换
  171. const onTabChange = (index) => {
  172. currentTab.value = index;
  173. // 根据Tab切换商品分类
  174. const category = tabList.value[index].name;
  175. defaultParams.category = category;
  176. // 刷新列表
  177. if (listRef.value) {
  178. listRef.value.handleRefresh();
  179. }
  180. };
  181. // 切换关注状态
  182. const toggleFollow = () => {
  183. isFollowed.value = !isFollowed.value;
  184. console.log("关注状态:", isFollowed.value);
  185. };
  186. // 获取列表数据
  187. const getList = (data) => {
  188. // 模拟搜索过滤
  189. if (searchValue.value.trim()) {
  190. const keyword = searchValue.value.toLowerCase();
  191. filteredProducts.value = products.value.filter((product) =>
  192. product.title.toLowerCase().includes(keyword)
  193. );
  194. } else {
  195. filteredProducts.value = products.value;
  196. }
  197. // 设置到List组件
  198. if (listRef.value) {
  199. listRef.value.setList(filteredProducts.value);
  200. }
  201. };
  202. // 跳转到商品详情
  203. const toProductDetail = (product) => {
  204. uni.navigateTo({
  205. url: `/pagesBuyer/product/detail?id=${product.id}`,
  206. });
  207. };
  208. // 切换商品收藏状态
  209. const toggleProductFavorite = (product) => {
  210. product.isFavorite = !product.isFavorite;
  211. console.log("商品收藏状态:", product.isFavorite);
  212. };
  213. const getDetail = async () => {
  214. try {
  215. const res = await SELLER_SELLER_INFO(defaultParams);
  216. shopInfo.value = res.data;
  217. isCollect.value = res.data.isCollect ? true : false;
  218. } catch (error) {
  219. Toast(error.msg);
  220. }
  221. };
  222. onLoad((options) => {
  223. if (options.id) {
  224. defaultParams.id = options.id;
  225. getDetail();
  226. }
  227. // 初始化数据
  228. getList();
  229. });
  230. </script>
  231. <style lang="less" scoped>
  232. @import url("@/style.less");
  233. .wrap {
  234. min-height: 100vh;
  235. background: var(--bg);
  236. display: flex;
  237. flex-direction: column;
  238. .nav_search {
  239. flex: 1;
  240. padding: 0 40rpx 0 80rpx;
  241. :deep(.u-input) {
  242. padding: 0 26rpx !important;
  243. background: var(--light);
  244. backdrop-filter: blur(20rpx);
  245. color: var(--text-01);
  246. .u-input__content__field-wrapper__field {
  247. color: var(--text-01);
  248. }
  249. .u-input__content__field-wrapper__field::placeholder {
  250. color: rgba(255, 255, 255, 0.7);
  251. }
  252. }
  253. .icon-search {
  254. color: var(--text-01);
  255. font-size: 38rpx;
  256. }
  257. }
  258. .shop-info-section {
  259. padding: 30rpx;
  260. background: var(--black);
  261. border-bottom: 1rpx solid var(--border);
  262. .shop-header {
  263. display: flex;
  264. align-items: center;
  265. .shop-avatar {
  266. width: 100rpx;
  267. height: 100rpx;
  268. border-radius: 50%;
  269. overflow: hidden;
  270. margin-right: 20rpx;
  271. background: var(--primary);
  272. image {
  273. width: 100%;
  274. height: 100%;
  275. }
  276. }
  277. .shop-details {
  278. flex: 1;
  279. .shop-name {
  280. font-size: 32rpx;
  281. font-weight: bold;
  282. color: var(--black);
  283. margin-bottom: 8rpx;
  284. }
  285. .shop-stats {
  286. display: flex;
  287. align-items: center;
  288. font-size: 24rpx;
  289. color: var(--text-01);
  290. .divider {
  291. margin: 0 8rpx;
  292. color: var(--text-02);
  293. }
  294. }
  295. }
  296. .follow-btn {
  297. display: flex;
  298. align-items: center;
  299. gap: 8rpx;
  300. padding: 12rpx 24rpx;
  301. background: var(--light);
  302. border: 1rpx solid var(--border);
  303. border-radius: 40rpx;
  304. color: var(--black);
  305. font-size: 24rpx;
  306. font-weight: bold;
  307. .icon-plus {
  308. font-size: 20rpx;
  309. }
  310. }
  311. }
  312. }
  313. .content {
  314. flex: 1;
  315. padding: 20rpx 30rpx;
  316. padding-bottom: calc(90rpx + constant(safe-area-inset-bottom));
  317. padding-bottom: calc(90rpx + env(safe-area-inset-bottom));
  318. // 网格布局样式
  319. :deep(.list-container) {
  320. display: grid;
  321. grid-template-columns: 1fr 1fr;
  322. gap: 20rpx;
  323. }
  324. }
  325. }
  326. </style>