index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <u-index-list :index-list="indexList" :sticky="false" activeColor="#ffbc00">
  3. <!-- <view :slot="header" class="list">
  4. <view class="text">热门品牌</view>
  5. <view class="one">
  6. <view class="list" v-for="(item, index) in list" :key="index" @tap="toCommon(item)">
  7. <view class="icon">
  8. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:'/static/logo.png'">
  9. </image>
  10. </view>
  11. <view class="title">{{item.name}}</view>
  12. </view>
  13. </view>
  14. </view> -->
  15. <template :key="index" v-for="(item, index) in itemArr">
  16. <!-- #ifdef APP-NVUE -->
  17. <u-index-anchor color="#333333" bg-color="#f9f9f9" :text="indexList[index]"></u-index-anchor>
  18. <!-- #endif -->
  19. <u-index-item>
  20. <!-- #ifndef APP-NVUE -->
  21. <u-index-anchor color="#333333" bg-color="#f9f9f9" :text="indexList[index]"></u-index-anchor>
  22. <!-- #endif -->
  23. <view class="list-cell" v-for="(cell, index) in item" @tap="toCommon(cell)">
  24. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:'/static/logo.png'">
  25. </image>
  26. <view class="title">{{cell.name}}</view>
  27. </view>
  28. </u-index-item>
  29. </template>
  30. </u-index-list>
  31. </template>
  32. <script setup lang="ts">
  33. import { getCurrentInstance, ref } from 'vue';
  34. //该依赖已内置不需要单独安装
  35. import { onLoad } from "@dcloudio/uni-app";
  36. // 请求接口
  37. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  38. // 基本信息
  39. const config = ref({ logoUrl: [] });
  40. const indexList = ref([]);
  41. const itemArr = ref([]);
  42. const type = ref('0');
  43. // const list = ref([{ name: '奥迪', url: [], type: '0' }, { name: '本田', url: [], type: '0' }, { name: '别克', url: [], type: '0' },
  44. // { name: '奥迪', url: [], type: '0' }, { name: '大众', url: [], type: '0' }, { name: '长城', url: [], type: '0' },
  45. // { name: '福特', url: [], type: '0' }, { name: '丰田', url: [], type: '0' }, { name: '长安', url: [], type: '0' },
  46. // { name: '日产', url: [], type: '0' }]);
  47. onLoad(async (options) => {
  48. type.value = options && options.type
  49. await searchConfig();
  50. await search();
  51. })
  52. // config信息
  53. const searchConfig = async () => {
  54. config.value = uni.getStorageSync('config');
  55. };
  56. // 查询
  57. const search = async () => {
  58. const res = await $api('brand/index', 'GET', {});
  59. if (res.errcode === 0) {
  60. itemArr.value = res.data.data1
  61. indexList.value = res.data.data2
  62. } else {
  63. uni.showToast({
  64. title: res.errmsg || '',
  65. icon: 'error',
  66. });
  67. }
  68. };
  69. const toCommon = (item) => {
  70. if (type.value == '4') {
  71. uni.navigateTo({
  72. url: `/pagesHome/search/index?brand=${item.name}`
  73. })
  74. } else {
  75. uni.$emit('toRoute', item)
  76. // 4. 返回上一页面
  77. uni.navigateBack({
  78. delta: 1 // 返回的页面数
  79. })
  80. }
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. .list {
  85. .text {
  86. margin: 2vw;
  87. font-weight: bold;
  88. font-size: var(--font16Size);
  89. }
  90. .one {
  91. display: flex;
  92. justify-content: space-between;
  93. flex-wrap: wrap;
  94. align-items: center;
  95. padding: 2vw 4vw;
  96. .list {
  97. display: flex;
  98. flex-direction: column;
  99. align-items: center;
  100. width: 18vw;
  101. margin: 0 0 1vw 0;
  102. .image {
  103. width: 40px;
  104. height: 40px;
  105. border-radius: 40px;
  106. }
  107. .title {
  108. margin: 0 0 1vw 0;
  109. font-size: var(--font14Size);
  110. }
  111. }
  112. }
  113. }
  114. .list-cell {
  115. display: flex;
  116. align-items: center;
  117. box-sizing: border-box;
  118. width: 100%;
  119. padding: 10px 24rpx;
  120. overflow: hidden;
  121. color: #323233;
  122. font-size: 14px;
  123. line-height: 24px;
  124. background-color: #fff;
  125. .image {
  126. width: 40px;
  127. height: 40px;
  128. border-radius: 40px;
  129. }
  130. .title {
  131. margin: 0 0 0 1vw;
  132. }
  133. }
  134. </style>