index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <view class="cont_bg" id="tob">
  5. <Navbar fixed leftShow bgColor="transparent">
  6. <template #center>
  7. <view class="nav_title">
  8. <trans _t="店铺街" />
  9. </view>
  10. </template>
  11. </Navbar>
  12. <view class="bg_top">
  13. <view class="search">
  14. <Search
  15. v-model="defaultParams.keywords"
  16. border="none"
  17. @input="onSearchInput"
  18. @click="searchClick"
  19. :placeholder="t('请搜索关键字')"
  20. >
  21. <template #prefix>
  22. <i class="icon-font icon-search"></i>
  23. </template>
  24. <template #suffix>
  25. <i class="icon-font icon-camera"></i>
  26. </template>
  27. </Search>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 店铺列表 - 使用封装的List组件 -->
  32. <view class="content">
  33. <List
  34. ref="listRef"
  35. url="/seller/seller/lists"
  36. :defaultParams="defaultParams"
  37. @datas="getList"
  38. >
  39. <template #item="{ item }">
  40. <shopItem
  41. :item="item"
  42. @click="toShopDetail"
  43. @productClick="toProductDetail"
  44. />
  45. </template>
  46. </List>
  47. </view>
  48. </view>
  49. <Tabbar page="shop" />
  50. </Theme>
  51. </template>
  52. <script setup>
  53. import { ref, reactive, watch, onMounted } from "vue";
  54. import Tabbar from "@/components/tabbar";
  55. import Navbar from "@/components/navbar";
  56. import Search from "@/components/input";
  57. import List from "@/components/list";
  58. import shopItem from "./components/shop_item";
  59. import { t } from "@/locale";
  60. import { onShow } from "@dcloudio/uni-app";
  61. // 搜索值
  62. const searchValue = ref("");
  63. // List组件引用
  64. const listRef = ref(null);
  65. // 默认参数
  66. const defaultParams = reactive({
  67. keywords: "",
  68. longitude: "",
  69. latitude: "",
  70. });
  71. // 过滤后的店铺列表
  72. const filteredShops = ref([]);
  73. // 获取地理位置
  74. const getLocation = () => {
  75. uni.getLocation({
  76. type: "gcj02",
  77. success: (res) => {
  78. defaultParams.longitude = res.longitude.toString();
  79. defaultParams.latitude = res.latitude.toString();
  80. console.log("获取位置成功:", res);
  81. },
  82. fail: (err) => {
  83. console.log("获取位置失败:", err);
  84. // 设置默认位置(北京)
  85. defaultParams.longitude = "116.397128";
  86. defaultParams.latitude = "39.916527";
  87. },
  88. });
  89. listRef.value && listRef.value.handleRefresh();
  90. };
  91. // 搜索输入
  92. const onSearchInput = (value) => {
  93. searchValue.value = value;
  94. defaultParams.keywords = value;
  95. listRef.value && listRef.value.handleRefresh();
  96. };
  97. // 搜索点击
  98. const searchClick = () => {
  99. console.log("搜索:", searchValue.value);
  100. };
  101. // 相机点击
  102. const onCameraClick = () => {
  103. console.log("相机搜索");
  104. // 这里可以添加相机搜索功能
  105. };
  106. // 获取列表数据
  107. const getList = (data) => {
  108. console.log("商品列表数据:", data);
  109. };
  110. // 跳转到店铺详情
  111. const toShopDetail = (shop) => {
  112. uni.navigateTo({
  113. url: `/pagesBuyer/store/detail?id=${shop.id}`,
  114. });
  115. };
  116. // 跳转到商品详情
  117. const toProductDetail = (product) => {
  118. uni.navigateTo({
  119. url: `/pagesBuyer/product/detail?id=${product.id}`,
  120. });
  121. };
  122. onShow(() => {
  123. getLocation();
  124. });
  125. onMounted(() => {
  126. getLocation();
  127. });
  128. </script>
  129. <style lang="less" scoped>
  130. @import url("@/style.less");
  131. .wrap {
  132. min-height: 100vh;
  133. background: var(--inputBg);
  134. display: flex;
  135. flex-direction: column;
  136. .cont_bg {
  137. z-index: 88;
  138. background-color: var(--black);
  139. .nav_title {
  140. color: var(--bg);
  141. }
  142. .bg_top {
  143. padding: 0 30rpx;
  144. .search {
  145. padding: 26rpx 0 60rpx 0;
  146. :deep(.u-input) {
  147. padding: 0 20px 0 16px !important;
  148. .u-input__content__field-wrapper__field {
  149. height: 47px;
  150. }
  151. }
  152. .icon-search {
  153. color: var(--text);
  154. font-size: 40rpx;
  155. }
  156. .icon-camera {
  157. color: var(--text-01);
  158. font-size: 70rpx;
  159. }
  160. }
  161. .debug-info {
  162. padding: 10rpx 0;
  163. text-align: center;
  164. text {
  165. font-size: 24rpx;
  166. color: var(--primary);
  167. background: rgba(255, 107, 107, 0.1);
  168. padding: 8rpx 16rpx;
  169. border-radius: 20rpx;
  170. }
  171. }
  172. }
  173. }
  174. .content {
  175. width: 100%;
  176. flex: 1;
  177. padding: 20rpx 0;
  178. padding-bottom: calc(90rpx + constant(safe-area-inset-bottom));
  179. padding-bottom: calc(90rpx + env(safe-area-inset-bottom));
  180. }
  181. }
  182. </style>