index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-subsection mode="subsection" activeColor="#ffbc00" :list="tabList" :current="curNow"
  5. @change="sectionChange"></u-subsection>
  6. </view>
  7. <view class="bottom">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  9. <view class="list-scroll-view">
  10. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  11. <view class="rank" :class="[`rank${index+1}`]">TOP{{index+1}}</view>
  12. <view class="left">
  13. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''">
  14. </image>
  15. </view>
  16. <view class="right">
  17. <view class="name textOver">{{item.series||'暂无'}} {{item.year||'暂无'}}款
  18. {{item.style||'暂无'}}
  19. </view>
  20. <view class="other">
  21. <text v-if="item.year">{{item.year||'暂无'}}年 | </text>
  22. <text v-if="item.mileage">{{item.mileage||'暂无'}}万公里 | </text>
  23. <text v-if="item.place">{{item.place||'暂无'}}</text>
  24. </view>
  25. <view class="money">
  26. <text>{{item.total_money||'0'}}</text>
  27. <text>万</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="is_bottom" v-if="is_bottom">
  32. <text>{{config.bottom_title||'没有更多了!'}}</text>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup lang="ts">
  40. import { getCurrentInstance, ref } from 'vue';
  41. //该依赖已内置不需要单独安装
  42. import { onLoad } from "@dcloudio/uni-app";
  43. // 请求接口
  44. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  45. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  46. const tabList = ref(['销量榜', '保值榜', '店铺规模榜']);
  47. const curNow = ref(0);
  48. // 基本信息
  49. const config = ref({ logoUrl: [] });
  50. // 列表
  51. const list = ref([]);
  52. const total = ref(0);
  53. const skip = ref(0);
  54. const limit = ref(6);
  55. const page = ref(0);
  56. // 数据是否触底
  57. const is_bottom = ref(false);
  58. const scrollTop = ref(0);
  59. onLoad(async () => {
  60. await searchConfig();
  61. await search();
  62. })
  63. // config信息
  64. const searchConfig = async () => {
  65. config.value = uni.getStorageSync('config');
  66. };
  67. // 查询
  68. const search = async () => {
  69. const info = {
  70. skip: skip.value,
  71. limit: limit.value,
  72. status: '0'
  73. }
  74. const res = await $api('car', 'GET', info);
  75. if (res.errcode === 0) {
  76. list.value = list.value.concat(res.data)
  77. total.value = res.total
  78. } else {
  79. uni.showToast({
  80. title: res.errmsg || '',
  81. icon: 'error',
  82. });
  83. }
  84. };
  85. const toRoute = (item) => {
  86. uni.navigateTo({
  87. url: `/${item.route}`,
  88. })
  89. };
  90. // 跳转
  91. const sectionChange = (index) => {
  92. curNow.value = index;
  93. };
  94. // 查看详情
  95. const toView = (item) => {
  96. uni.navigateTo({
  97. url: `/pagesHome/car/index?id=${item.id || item._id}`
  98. })
  99. };
  100. // 联系卖家
  101. const toChat = (item) => {
  102. uni.makePhoneCall({
  103. phoneNumber: item.shop || '110',
  104. success: function () {
  105. console.log('拨打电话成功');
  106. },
  107. fail: function () {
  108. uni.showToast({
  109. title: '拨打电话失败',
  110. icon: 'error',
  111. });
  112. }
  113. });
  114. };
  115. // 清空失效数据
  116. const toDelete = () => {
  117. console.log('清空失效数据');
  118. };
  119. // 分页
  120. const toPage = () => {
  121. if (total.value > list.value.length) {
  122. uni.showLoading({
  123. title: '加载中',
  124. mask: true
  125. })
  126. page.value = page.value + 1;
  127. skip.value = page.value * limit.value;
  128. search();
  129. uni.hideLoading();
  130. } else is_bottom.value = true
  131. };
  132. // 清空列表
  133. const clearPage = () => {
  134. list.value = []
  135. skip.value = 0
  136. limit.value = 6
  137. page.value = 0
  138. };
  139. </script>
  140. <style lang="scss" scoped>
  141. .content {
  142. display: flex;
  143. flex-direction: column;
  144. width: 100vw;
  145. height: 100vh;
  146. .top {
  147. padding: 2vw;
  148. }
  149. .bottom {
  150. position: relative;
  151. flex-grow: 1;
  152. .list {
  153. position: relative;
  154. display: flex;
  155. margin: 2vw 0 0 0;
  156. padding: 2vw 2vw 0 2vw;
  157. .rank {
  158. position: absolute;
  159. top: -2px;
  160. left: 2px;
  161. padding: 2px 4px;
  162. font-size: var(--font14Size);
  163. color: var(--mainColor);
  164. font-weight: bold;
  165. background-color: var(--f99Color);
  166. border-top-left-radius: 8px;
  167. /* 左上角 */
  168. border-bottom-right-radius: 8px;
  169. /* 右下角 */
  170. }
  171. .rank1 {
  172. background-color: #817AE3;
  173. }
  174. .rank2 {
  175. background-color: #FF6A88;
  176. }
  177. .rank3 {
  178. background-color: #FBAB7E;
  179. }
  180. .left {
  181. .image {
  182. width: 100px;
  183. height: 70px;
  184. border-radius: 2px;
  185. }
  186. }
  187. .right {
  188. display: flex;
  189. flex-direction: column;
  190. justify-content: space-between;
  191. margin: 0 0 0 2vw;
  192. width: 100%;
  193. .name {
  194. font-size: var(--font14Size);
  195. }
  196. .other {
  197. color: var(--f85Color);
  198. font-size: var(--font12Size);
  199. }
  200. .money {
  201. color: var(--fF0Color);
  202. font-size: var(--font12Size);
  203. text:first-child {
  204. font-size: var(--font18Size);
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. .scroll-view {
  212. position: absolute;
  213. top: 0;
  214. left: 0;
  215. right: 0;
  216. bottom: 0;
  217. .list-scroll-view {
  218. display: flex;
  219. flex-direction: column;
  220. }
  221. }
  222. .is_bottom {
  223. width: 100%;
  224. text-align: center;
  225. text {
  226. padding: 2vw 0;
  227. display: inline-block;
  228. color: var(--f85Color);
  229. font-size: var(--font12Size);
  230. }
  231. }
  232. </style>