index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. // 偏移
  47. const offset = ref(['-2px', '355px']);
  48. const tabList = ref(['销量榜', '保值榜', '店铺规模榜']);
  49. const curNow = ref(0);
  50. // 基本信息
  51. const config = ref({ logoUrl: [] });
  52. // 列表
  53. const list = ref([]);
  54. const total = ref(0);
  55. const skip = ref(0);
  56. const limit = ref(6);
  57. const page = ref(0);
  58. // 数据是否触底
  59. const is_bottom = ref(false);
  60. const scrollTop = ref(0);
  61. onLoad(async () => {
  62. await searchConfig();
  63. await search();
  64. })
  65. // config信息
  66. const searchConfig = async () => {
  67. config.value = uni.getStorageSync('config');
  68. };
  69. // 查询
  70. const search = async () => {
  71. const info = {
  72. skip: skip.value,
  73. limit: limit.value,
  74. status: '0'
  75. }
  76. const res = await $api('car', 'GET', info);
  77. if (res.errcode === 0) {
  78. list.value = list.value.concat(res.data)
  79. total.value = res.total
  80. } else {
  81. uni.showToast({
  82. title: res.errmsg || '',
  83. icon: 'error',
  84. });
  85. }
  86. };
  87. const toRoute = (item) => {
  88. uni.navigateTo({
  89. url: `/${item.route}`,
  90. })
  91. };
  92. // 跳转
  93. const sectionChange = (index) => {
  94. curNow.value = index;
  95. };
  96. // 查看详情
  97. const toView = (item) => {
  98. uni.navigateTo({
  99. url: `/pagesHome/car/index?id=${item.id || item._id}`
  100. })
  101. };
  102. // 联系卖家
  103. const toChat = (item) => {
  104. uni.makePhoneCall({
  105. phoneNumber: item.shop || '110',
  106. success: function () {
  107. console.log('拨打电话成功');
  108. },
  109. fail: function () {
  110. uni.showToast({
  111. title: '拨打电话失败',
  112. icon: 'error',
  113. });
  114. }
  115. });
  116. };
  117. // 清空失效数据
  118. const toDelete = () => {
  119. console.log('清空失效数据');
  120. };
  121. // 分页
  122. const toPage = () => {
  123. if (total.value > list.value.length) {
  124. uni.showLoading({
  125. title: '加载中',
  126. mask: true
  127. })
  128. page.value = page.value + 1;
  129. skip.value = page.value * limit.value;
  130. search();
  131. uni.hideLoading();
  132. } else is_bottom.value = true
  133. };
  134. // 清空列表
  135. const clearPage = () => {
  136. list.value = []
  137. skip.value = 0
  138. limit.value = 6
  139. page.value = 0
  140. };
  141. </script>
  142. <style lang="scss" scoped>
  143. .content {
  144. display: flex;
  145. flex-direction: column;
  146. width: 100vw;
  147. height: 100vh;
  148. .top {
  149. padding: 2vw;
  150. }
  151. .bottom {
  152. position: relative;
  153. flex-grow: 1;
  154. .list {
  155. position: relative;
  156. display: flex;
  157. margin: 2vw 0 0 0;
  158. padding: 2vw 2vw 0 2vw;
  159. .rank {
  160. position: absolute;
  161. top: -2px;
  162. left: 2px;
  163. padding: 2px 4px;
  164. font-size: var(--font14Size);
  165. color: var(--mainColor);
  166. font-weight: bold;
  167. background-color: var(--f99Color);
  168. border-top-left-radius: 8px;
  169. /* 左上角 */
  170. border-bottom-right-radius: 8px;
  171. /* 右下角 */
  172. }
  173. .rank1 {
  174. background-color: #817AE3;
  175. }
  176. .rank2 {
  177. background-color: #FF6A88;
  178. }
  179. .rank3 {
  180. background-color: #FBAB7E;
  181. }
  182. .left {
  183. .image {
  184. width: 100px;
  185. height: 70px;
  186. border-radius: 2px;
  187. }
  188. }
  189. .right {
  190. display: flex;
  191. flex-direction: column;
  192. justify-content: space-between;
  193. margin: 0 0 0 2vw;
  194. width: 100%;
  195. .name {
  196. font-size: var(--font14Size);
  197. }
  198. .other {
  199. color: var(--f85Color);
  200. font-size: var(--font12Size);
  201. }
  202. .money {
  203. color: var(--fF0Color);
  204. font-size: var(--font12Size);
  205. text:first-child {
  206. font-size: var(--font18Size);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. .scroll-view {
  214. position: absolute;
  215. top: 0;
  216. left: 0;
  217. right: 0;
  218. bottom: 0;
  219. .list-scroll-view {
  220. display: flex;
  221. flex-direction: column;
  222. }
  223. }
  224. .is_bottom {
  225. width: 100%;
  226. text-align: center;
  227. text {
  228. padding: 2vw 0;
  229. display: inline-block;
  230. color: var(--f85Color);
  231. font-size: var(--font12Size);
  232. }
  233. }
  234. </style>