list.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view>
  3. <view class="top-box">
  4. <view class="top-nav">
  5. <view class="city-text" @click="regionSelectionRef.open()">
  6. <uv-icon name="map" color="#999999" size="34rpx"></uv-icon>
  7. <view>{{ cityName }}</view>
  8. </view>
  9. <view class="searchBox">
  10. <image
  11. src="/static/image/order/icon_search.png"
  12. mode="widthFix"
  13. ></image>
  14. <input
  15. v-model="param.keyword"
  16. type="text"
  17. @confirm="search"
  18. placeholder-style="color:#B3B3B3"
  19. placeholder="请输入关键字"
  20. @input="search"
  21. />
  22. </view>
  23. </view>
  24. <view class="tabsBox">
  25. <view class="type-box">
  26. <view class="item" @click="show = true">
  27. <view>{{
  28. selectIndex === null ? "全部分类" : selector[selectIndex].name
  29. }}</view>
  30. <uv-icon name="arrow-down" color="#4d4d4d" size="26rpx"></uv-icon>
  31. </view>
  32. <view
  33. class="item"
  34. v-for="(v, i) in typeList"
  35. :key="i"
  36. :class="{ activeCls: tabCurrent == i }"
  37. @click="tabsChange2(i)"
  38. >
  39. <view>{{ v.name }}</view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view :style="{ height: placeholderH + 'px' }"></view>
  45. <view class="shopListBox" v-if="RowsList.length > 0">
  46. <!-- 附近门店 -->
  47. <ShopItem
  48. v-for="(v, index) in RowsList"
  49. :key="v.businessId"
  50. :v="v"
  51. />
  52. </view>
  53. <view>
  54. <loadMore v-if="RowsList.length > 0" :status="LoadStatus"></loadMore>
  55. <noData v-if="RowsList.length <= 0" :config="{ top: 2 }"></noData>
  56. </view>
  57. <!-- 地区选择 -->
  58. <RegionSelection
  59. ref="regionSelectionRef"
  60. :hierarchy="2"
  61. @confirm="addressConfirm"
  62. />
  63. <uv-picker
  64. mode="selector"
  65. v-model="show"
  66. :range="selector"
  67. range-key="name"
  68. :default-selector="[sIndex]"
  69. @confirm="confirmSelect"
  70. ></uv-picker>
  71. </view>
  72. </template>
  73. <script setup>
  74. import { computed, getCurrentInstance, nextTick, reactive, ref } from "vue";
  75. import { onLoad, onPullDownRefresh, onShow } from "@dcloudio/uni-app";
  76. import { getBusinessPage, getBusinessCategoryList } from "@/api/shop.js";
  77. import { usePageData } from "@/hooks/usePageData.ts";
  78. import ShopItem from "./components/ShopItem.vue";
  79. const regionSelectionRef = ref(null);
  80. const { RowsList, LoadStatus, initData } = usePageData(getBusinessPage);
  81. const instance = getCurrentInstance();
  82. const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight || 0);
  83. const sticky = computed(() => statusBarHeight.value + 44);
  84. const placeholderH = ref(0);
  85. const cityName = ref("武汉市");
  86. const sIndex = ref(0);
  87. const param = reactive({});
  88. const tabCurrent = ref(0);
  89. const typeList = ref([
  90. { name: "距离优先", order: "distance" },
  91. { name: "评分优先", order: "average" },
  92. ]);
  93. const show = ref(false);
  94. const selector = ref([]);
  95. const selectIndex = ref(null);
  96. const getRect = (selectorStr) =>
  97. new Promise((resolve) => {
  98. const query = uni.createSelectorQuery();
  99. const ctx = instance?.proxy || undefined;
  100. if (ctx) query.in(ctx);
  101. query
  102. .select(selectorStr)
  103. .boundingClientRect((res) => resolve(res || {}))
  104. .exec();
  105. });
  106. const tabsChange2 = (index) => {
  107. tabCurrent.value = index;
  108. param.order = typeList.value[index]?.order || "distance";
  109. console.log(param);
  110. // initData(param);
  111. };
  112. const confirmSelect = (e) => {
  113. const idx = e?.[0] ?? 0;
  114. selectIndex.value = idx;
  115. sIndex.value = idx;
  116. initData(param);
  117. };
  118. // 地区选择确认
  119. const addressConfirm = (e) => {
  120. const picked = e.areaName || e.cityName || e.provinceName;
  121. cityName.value = picked || cityName.value;
  122. Object.assign(param, { ...e });
  123. initData(param);
  124. };
  125. const getTppe = async (id) => {
  126. await getBusinessCategoryList().then((res) => {
  127. if (res && res.code == 200) {
  128. selector.value = [{ name: "全部分类", id: "" }, ...(res.data || [])];
  129. if (id) {
  130. selector.value.forEach((v, i) => {
  131. if (String(v.id) === String(id)) selectIndex.value = i;
  132. });
  133. }
  134. }
  135. });
  136. };
  137. // 获取当前位置
  138. const getLoca = async () => {
  139. await uni.getLocation({
  140. type: "gcj02",
  141. geocode: true,
  142. success: (res) => {
  143. param.longitude = res.longitude;
  144. param.latitude = res.latitude;
  145. },
  146. fail: () => {},
  147. });
  148. };
  149. const searchTimer = ref(null);
  150. const search = () => {
  151. if (searchTimer.value) clearTimeout(searchTimer.value);
  152. searchTimer.value = setTimeout(() => {
  153. initData(param);
  154. }, 1000);
  155. };
  156. const initPage = async (options = {}) => {
  157. if (options?.id) {
  158. param.businessCategoryId = options.id;
  159. }
  160. if (options?.cityName) {
  161. cityName.value = options.cityName;
  162. }
  163. if (options?.cityCode) {
  164. param.cityCode = options.cityCode;
  165. }
  166. try {
  167. await getTppe(param.businessCategoryId);
  168. await getLoca();
  169. } catch (error) {
  170. console.log(error);
  171. }
  172. initData(param);
  173. };
  174. onLoad((options) => {
  175. initPage(options || {});
  176. });
  177. onShow(async () => {
  178. await nextTick();
  179. const rect = await getRect(".top-box");
  180. placeholderH.value = rect?.height || 0;
  181. });
  182. onPullDownRefresh(() => {
  183. // Promise.allSettled([getLoca(), initData(param)]).finally(() => {
  184. // uni.stopPullDownRefresh();
  185. // });
  186. });
  187. </script>
  188. <style lang="scss" scoped>
  189. .top-box {
  190. width: 750rpx;
  191. position: fixed;
  192. background-color: #fff;
  193. z-index: 3;
  194. }
  195. .top-nav {
  196. height: 120rpx;
  197. display: flex;
  198. justify-content: space-between;
  199. align-items: center;
  200. padding: 0 30rpx;
  201. background-color: #fff;
  202. }
  203. .city-text {
  204. margin-right: 20rpx;
  205. font-size: 30rpx;
  206. font-family: PingFang SC, PingFang SC-Regular;
  207. font-weight: 400;
  208. text-align: center;
  209. color: #666666;
  210. display: flex;
  211. align-items: center;
  212. view {
  213. max-width: 100rpx;
  214. white-space: nowrap;
  215. text-overflow: ellipsis;
  216. overflow: hidden;
  217. }
  218. image {
  219. width: 26rpx;
  220. height: 36rpx;
  221. margin-right: 10rpx;
  222. vertical-align: middle;
  223. }
  224. }
  225. .searchBox {
  226. // width: 560rpx;
  227. flex: 1;
  228. display: flex;
  229. padding: 10rpx 27rpx;
  230. border: 1rpx solid #cccccc;
  231. border-radius: 10rpx;
  232. display: flex;
  233. align-items: center;
  234. image {
  235. width: 35rpx;
  236. height: 35rpx;
  237. margin-right: 15rpx;
  238. flex-shrink: 0;
  239. }
  240. input {
  241. text-align: left;
  242. }
  243. }
  244. .tabsBox {
  245. width: 100%;
  246. background-color: #fff;
  247. .tabsBox_tabs {
  248. padding: 0 10rpx;
  249. ::v-deep .u-tab-item {
  250. font-weight: 700;
  251. }
  252. }
  253. }
  254. .type-box {
  255. display: flex;
  256. align-items: center;
  257. padding: 0 40rpx 20rpx;
  258. justify-content: space-between;
  259. .item {
  260. display: flex;
  261. font-size: 28rpx;
  262. font-family: PingFang SC, PingFang SC-Regular;
  263. font-weight: 400;
  264. color: #4d4d4d;
  265. align-items: center;
  266. color: #4d4d4d;
  267. &:first-child {
  268. min-width: 142rpx;
  269. }
  270. image {
  271. width: 14rpx;
  272. height: 10rpx;
  273. margin-left: 10rpx;
  274. vertical-align: middle;
  275. }
  276. }
  277. .activeCls {
  278. color: #fa6138;
  279. }
  280. .item2 {
  281. margin-left: 100rpx;
  282. padding-top: 20rpx;
  283. }
  284. }
  285. .content-box {
  286. padding: 0 30rpx;
  287. }
  288. .shopListBox {
  289. padding: 0 30rpx;
  290. .shopListBox_item {
  291. margin-top: 30rpx;
  292. }
  293. }
  294. </style>