index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 list = ref([{ name: '奥迪', url: [], type: '0' }, { name: '本田', url: [], type: '0' }, { name: '别克', url: [], type: '0' },
  43. // { 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' }]);
  46. onLoad(async () => {
  47. await searchConfig();
  48. await search();
  49. })
  50. // config信息
  51. const searchConfig = async () => {
  52. config.value = uni.getStorageSync('config');
  53. };
  54. // 查询
  55. const search = async () => {
  56. const res = await $api('brand/index', 'GET', {});
  57. if (res.errcode === 0) {
  58. itemArr.value = res.data.data1
  59. indexList.value = res.data.data2
  60. } else {
  61. uni.showToast({
  62. title: res.errmsg || '',
  63. icon: 'error',
  64. });
  65. }
  66. };
  67. const toCommon = (item) => {
  68. uni.$emit('toRoute', item)
  69. // 4. 返回上一页面
  70. uni.navigateBack({
  71. delta: 1 // 返回的页面数
  72. })
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .list {
  77. .text {
  78. margin: 2vw;
  79. font-weight: bold;
  80. font-size: var(--font16Size);
  81. }
  82. .one {
  83. display: flex;
  84. justify-content: space-between;
  85. flex-wrap: wrap;
  86. align-items: center;
  87. padding: 2vw 4vw;
  88. .list {
  89. display: flex;
  90. flex-direction: column;
  91. align-items: center;
  92. width: 18vw;
  93. margin: 0 0 1vw 0;
  94. .image {
  95. width: 40px;
  96. height: 40px;
  97. border-radius: 40px;
  98. }
  99. .title {
  100. margin: 0 0 1vw 0;
  101. font-size: var(--font14Size);
  102. }
  103. }
  104. }
  105. }
  106. .list-cell {
  107. display: flex;
  108. align-items: center;
  109. box-sizing: border-box;
  110. width: 100%;
  111. padding: 10px 24rpx;
  112. overflow: hidden;
  113. color: #323233;
  114. font-size: 14px;
  115. line-height: 24px;
  116. background-color: #fff;
  117. .image {
  118. width: 40px;
  119. height: 40px;
  120. border-radius: 40px;
  121. }
  122. .title {
  123. margin: 0 0 0 1vw;
  124. }
  125. }
  126. </style>