city.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="container">
  3. <uv-sticky>
  4. <uv-navbar
  5. title="本地生活"
  6. leftIconSize="0"
  7. :border="false"
  8. bgColor="#fbcd17"
  9. titleStyle="font-weight: 700;color: #1A1A1A;"
  10. placeholder
  11. ></uv-navbar>
  12. <view class="search-top">
  13. <view class="city-text" @click="regionSelectionRef.open()">
  14. <uv-icon name="map" color="#000000" size="28rpx"></uv-icon>
  15. <view>{{ cityName }}</view>
  16. <uv-icon name="arrow-right" color="#000000" size="30rpx"></uv-icon>
  17. </view>
  18. <view class="searchBox">
  19. <uv-search
  20. v-model="param.keyword"
  21. shape="round"
  22. :clearabled="false"
  23. :showAction="false"
  24. height="80rpx"
  25. bg-color="#f7f7f7"
  26. border-color="#D9D9D9"
  27. laceholder-color="#CCCCCC"
  28. search-icon="/static/image/order/icon_search.png"
  29. @search="$uv.throttle(search, 1000)"
  30. @custom="$uv.throttle(search, 1000)"
  31. >
  32. <template #suffix>
  33. <view class="search-action">搜索</view>
  34. </template>
  35. </uv-search>
  36. </view>
  37. </view>
  38. </uv-sticky>
  39. <!-- <view style="height: 86rpx"></view> -->
  40. <view class="u-skeleton">
  41. <view class="banner" v-if="bannerList.length > 0 || skeletonShow">
  42. <!-- <image src="/static/shop/banner.png" mode="aspectFill"></image> -->
  43. <uv-swiper
  44. class="u-skeleton-fillet"
  45. :list="bannerList"
  46. keyName="image"
  47. height="360rpx"
  48. :indicatorMode="bannerList.length > 1 ? 'round' : 'none'"
  49. bgColor="transparent"
  50. ></uv-swiper>
  51. </view>
  52. <view class="menu" v-if="iconList.length > 0 || skeletonShow">
  53. <swiper
  54. class="swiper u-skeleton-fillet"
  55. :indicator-dots="true"
  56. :autoplay="false"
  57. :current="current"
  58. :style="{ height: menuHeight }"
  59. @change="swiperChange"
  60. >
  61. <swiper-item class="swiper-item" v-for="(el, k) in iconList" :key="k">
  62. <view class="item" v-for="(v, i) in el" :key="i" @click="goShop(v)">
  63. <view class="img">
  64. <image
  65. class="u-skeleton-fillet"
  66. :src="v.icon"
  67. mode="widthFix"
  68. ></image>
  69. </view>
  70. <text class="u-skeleton-fillet">{{ v.name || "加载中" }}</text>
  71. </view>
  72. </swiper-item>
  73. </swiper>
  74. </view>
  75. <view class="con-box">
  76. <view class="store-bg">
  77. <image class="store-bg-image" src="/static/store.png" mode="">
  78. </image>
  79. <view class="store-bg-btn" @click="goShop()">
  80. <text class="text">查看更多</text>
  81. <uv-icon name="arrow-right" color="#fbbd1c" size="24rpx"></uv-icon>
  82. </view>
  83. </view>
  84. <view class="items">
  85. <ShopItem v-for="(v, index) in RowsList" :key="v.businessId" :v="v" />
  86. </view>
  87. </view>
  88. <view>
  89. <loadMore v-if="RowsList.length > 0" :status="LoadStatus"></loadMore>
  90. <noData v-if="RowsList.length <= 0" :config="{ top: 2 }"></noData>
  91. </view>
  92. <uv-skeleton
  93. :loading="skeletonShow"
  94. :animation="true"
  95. bgColor="#FFF"
  96. ></uv-skeleton>
  97. </view>
  98. <!-- 地区选择 -->
  99. <RegionSelection
  100. ref="regionSelectionRef"
  101. :hierarchy="2"
  102. @confirm="addressConfirm"
  103. />
  104. </view>
  105. </template>
  106. <script setup>
  107. import { computed, reactive, ref } from "vue";
  108. import { onLoad, onPullDownRefresh } from "@dcloudio/uni-app";
  109. import { getAdList_Api, getQuickLinkList_Api } from "@/api/index.js";
  110. import { getBusinessPage } from "@/api/shop.js";
  111. import { usePageData } from "@/hooks/usePageData.ts";
  112. import ShopItem from "../nearbyShop/components/ShopItem.vue";
  113. const { RowsList, LoadStatus, initData } = usePageData(getBusinessPage);
  114. const regionSelectionRef = ref(null);
  115. const cityName = ref("洪山区");
  116. const param = reactive({
  117. keyword: "",
  118. });
  119. const iconList = ref([]);
  120. const bannerList = ref([]);
  121. const current = ref(0);
  122. const skeletonShow = ref(true);
  123. const menuHeight = computed(() => {
  124. const items = iconList.value[current.value] || [];
  125. return items.length > 5 ? "350rpx" : "150rpx";
  126. });
  127. const goShop = (item = {}) => {
  128. uni.navigateTo({
  129. url:
  130. "/pages/nearbyShop/list?id=" +
  131. (item.id || "") +
  132. "&cityName=" +
  133. cityName.value +
  134. "&cityCode=" +
  135. (param.cityCode || ""),
  136. });
  137. };
  138. // 获取banner广告
  139. const getBanner = () => {
  140. getAdList_Api("local_life_banner").then((res) => {
  141. if (res && res.code == 200) {
  142. bannerList.value = res.data || [];
  143. } else {
  144. bannerList.value = [];
  145. }
  146. });
  147. };
  148. // 分组
  149. const chunk = (arr, size) => {
  150. const res = [];
  151. for (let i = 0; i < arr.length; i += size) res.push(arr.slice(i, i + size));
  152. return res;
  153. };
  154. // 获取分类列表
  155. const getTypeList = () => {
  156. getQuickLinkList_Api("local_life").then((res) => {
  157. if (res && res.code == 200) {
  158. const list = res.data || [];
  159. iconList.value = chunk(list, 10);
  160. current.value = 0;
  161. } else {
  162. iconList.value = [];
  163. }
  164. });
  165. };
  166. // 获取当前位置
  167. const getLocation = () =>
  168. new Promise((resolve, reject) => {
  169. uni.getLocation({
  170. type: "gcj02",
  171. geocode: true,
  172. success: resolve,
  173. fail: reject,
  174. });
  175. });
  176. const swiperChange = (e) => {
  177. if (!e) return;
  178. current.value = e.detail.current;
  179. };
  180. // 地区选择确认
  181. const addressConfirm = (e = {}) => {
  182. // console.log(e);
  183. const picked = e.areaName || e.cityName || e.provinceName;
  184. cityName.value = picked || cityName.value;
  185. Object.assign(param, { ...e });
  186. initData(param);
  187. };
  188. onLoad(() => {
  189. getBanner();
  190. getTypeList();
  191. getLocation().then((res) => {
  192. console.log("当前位置", res);
  193. param.longitude = res.longitude;
  194. param.latitude = res.latitude;
  195. initData({
  196. latitude: res.latitude,
  197. longitude: res.longitude,
  198. });
  199. });
  200. skeletonShow.value = false;
  201. // initData();
  202. });
  203. onPullDownRefresh(() => {
  204. getBanner();
  205. getTypeList();
  206. });
  207. </script>
  208. <style lang="scss" scoped>
  209. .container {
  210. .search-top {
  211. // position: fixed;
  212. width: 100%;
  213. // height: 110rpx;
  214. // display: flex;
  215. // justify-content: space-between;
  216. // align-items: center;
  217. padding: 10rpx 30rpx 26rpx 30rpx;
  218. background-color: #fbcd17;
  219. // z-index: 3;
  220. box-sizing: border-box;
  221. }
  222. .city-text {
  223. margin-right: 12rpx;
  224. font-size: 28rpx;
  225. font-family: PingFang SC, PingFang SC-Regular;
  226. font-weight: 400;
  227. text-align: center;
  228. color: #000000;
  229. display: flex;
  230. align-items: center;
  231. margin-bottom: 20rpx;
  232. view {
  233. max-width: 100rpx;
  234. white-space: nowrap;
  235. text-overflow: ellipsis;
  236. overflow: hidden;
  237. font-weight: 700;
  238. }
  239. image {
  240. width: 26rpx;
  241. height: 36rpx;
  242. margin-right: 10rpx;
  243. vertical-align: middle;
  244. }
  245. }
  246. .searchBox {
  247. position: relative;
  248. flex: 1;
  249. box-sizing: border-box;
  250. // width: 580rpx;
  251. // height: 80rpx;
  252. image {
  253. width: 35rpx;
  254. height: 35rpx;
  255. }
  256. .search-action {
  257. width: 124rpx;
  258. height: 70rpx;
  259. background: #fbd415;
  260. border-radius: 35rpx;
  261. font-size: 30rpx;
  262. font-family: PingFang SC, PingFang SC-Regular;
  263. font-weight: 400;
  264. color: #1a1a1a;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. margin-right: 0rpx;
  269. }
  270. }
  271. }
  272. .banner {
  273. width: 100%;
  274. height: 360rpx;
  275. // padding: 0rpx 30rpx 0;
  276. margin-bottom: 20rpx;
  277. box-sizing: border-box;
  278. image {
  279. width: 100%;
  280. height: 100%;
  281. }
  282. ::v-deep uni-swiper {
  283. height: 360rpx !important;
  284. box-sizing: border-box;
  285. }
  286. }
  287. .menu {
  288. display: flex;
  289. // justify-content: space-between;
  290. // align-items: center;
  291. flex-wrap: wrap;
  292. padding: 0 30rpx;
  293. margin: 22rpx 0;
  294. .swiper {
  295. width: 100%;
  296. height: auto;
  297. transition: all 0.3s;
  298. ::v-deep .uni-swiper-dots-horizontal {
  299. bottom: 0;
  300. .uni-swiper-dot-active {
  301. background-color: #fa6138;
  302. }
  303. }
  304. }
  305. .swiper-item {
  306. display: flex;
  307. flex-wrap: wrap;
  308. }
  309. .item {
  310. display: flex;
  311. flex-direction: column;
  312. align-items: center;
  313. width: 20%;
  314. margin-bottom: 20rpx;
  315. .img {
  316. width: 94rpx;
  317. height: 94rpx;
  318. margin-bottom: 13rpx;
  319. // border-radius: 50%;
  320. overflow: hidden;
  321. image {
  322. width: 100%;
  323. height: 100%;
  324. }
  325. }
  326. text {
  327. width: 100%;
  328. font-size: 26rpx;
  329. font-family: PingFang SC, PingFang SC-Regular;
  330. font-weight: 400;
  331. text-align: center;
  332. color: #1a1a1a;
  333. overflow: hidden;
  334. text-overflow: ellipsis;
  335. white-space: nowrap;
  336. }
  337. }
  338. // .item:nth-child(5n) {
  339. // margin-right: 0;
  340. // }
  341. }
  342. .con-box {
  343. // padding: 0 0;
  344. background: linear-gradient(180deg, #fff8e3, rgba(255, 249, 233, 0) 200rpx);
  345. .store-bg {
  346. width: 750rpx;
  347. height: 118rpx;
  348. display: flex;
  349. align-items: center;
  350. justify-content: space-between;
  351. padding: 30rpx;
  352. box-sizing: border-box;
  353. // background: url("/static/store_bg.png") no-repeat;
  354. background-size: 100% 117rpx;
  355. .store-bg-image {
  356. width: 141rpx;
  357. height: 33rpx;
  358. }
  359. .store-bg-btn {
  360. width: 165rpx;
  361. height: 58rpx;
  362. background: #ffffff;
  363. border-radius: 29rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. font-size: 24rpx;
  368. font-weight: 400;
  369. color: #fbbd1c;
  370. }
  371. }
  372. .u-section {
  373. margin-bottom: 27rpx;
  374. ::v-deep .uicon-arrow-right:before {
  375. color: #666;
  376. }
  377. }
  378. .items {
  379. padding: 0 30rpx;
  380. }
  381. }
  382. </style>