index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <u-search shape="square" :show-action="false" placeholder="搜索" @focus="toChange"></u-search>
  5. </view>
  6. <view class="bottom">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index">
  10. <view class="name textOver">
  11. <text>{{item.name||'暂无'}}</text>
  12. </view>
  13. <view class="other textOver" v-if="item.start">
  14. <text>上牌日期:</text>
  15. <text>{{item.start||'暂无'}}</text>
  16. </view>
  17. <view class="other textOver" v-if="item.course">
  18. <text>行驶里程:</text>
  19. <text>{{item.course||'暂无'}}</text>
  20. </view>
  21. <view class="other textOver" v-if="item.city">
  22. <text>上牌城市:</text>
  23. <text>{{item.city||'暂无'}}</text>
  24. </view>
  25. <view class="other textOver" v-if="item.place">
  26. <text>估值地区:</text>
  27. <text>{{item.place||'暂无'}}</text>
  28. </view>
  29. <view class="other textOver" v-if="item.estimate">
  30. <text>预估价格:</text>
  31. <text style="color: red;">{{item.estimate||'暂无'}}万元</text>
  32. </view>
  33. <view class="other textOver" v-if="item.status">
  34. <text>状态:</text>
  35. <text style="color: red;">{{getDict(item.status,'status')}}</text>
  36. </view>
  37. </view>
  38. <view class="is_bottom" v-if="is_bottom">
  39. <text>{{config.bottom_title||'没有更多了!'}}</text>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup lang="ts">
  47. import { getCurrentInstance, computed, ref } from 'vue';
  48. //该依赖已内置不需要单独安装
  49. import { onLoad } from "@dcloudio/uni-app";
  50. // 请求接口
  51. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  52. const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
  53. // openid
  54. const openid = computed(() => {
  55. return uni.getStorageSync('openid');
  56. })
  57. // 查询
  58. const searchInfo = ref({});
  59. // 基本信息
  60. const config = ref({ logoUrl: [] });
  61. // 列表
  62. const list = ref([]);
  63. const total = ref(0);
  64. const skip = ref(0);
  65. const limit = ref(6);
  66. const page = ref(0);
  67. // 数据是否触底
  68. const is_bottom = ref(false);
  69. const scrollTop = ref(0);
  70. // 字典表
  71. const statusList = ref([]);
  72. onLoad(async () => {
  73. await searchOther();
  74. await searchConfig();
  75. await search();
  76. })
  77. // 查询其他信息
  78. const searchOther = async () => {
  79. let res;
  80. // 状态
  81. res = await $api(`dictData`, 'GET', { code: 'status', is_use: '0' });
  82. if (res.errcode === 0) statusList.value = res.data;
  83. };
  84. // config信息
  85. const searchConfig = async () => {
  86. config.value = uni.getStorageSync('config');
  87. };
  88. // 查询
  89. const search = async () => {
  90. const info = {
  91. skip: skip.value,
  92. limit: limit.value,
  93. // user: user.value._id
  94. }
  95. const res = await $api('apply', 'GET', {
  96. ...info,
  97. ...searchInfo.value
  98. });
  99. if (res.errcode === 0) {
  100. list.value = list.value.concat(res.data)
  101. total.value = res.total
  102. } else {
  103. uni.showToast({
  104. title: res.errmsg || '',
  105. icon: 'error',
  106. });
  107. }
  108. };
  109. // 数据处理
  110. const getDict = (data, model) => {
  111. let list;
  112. switch (model) {
  113. case 'status':
  114. list = statusList.value;
  115. break;
  116. default:
  117. break;
  118. }
  119. if (!list) return;
  120. const res = list.find((f) => f.value == data);
  121. return res?.label || '暂无';
  122. };
  123. // 搜索
  124. const toChange = () => {
  125. if (e) searchInfo.value.name = e
  126. else searchInfo.value = {}
  127. };
  128. // 分页
  129. const toPage = () => {
  130. if (total.value > list.value.length) {
  131. uni.showLoading({
  132. title: '加载中',
  133. mask: true
  134. })
  135. page.value = page.value + 1;
  136. skip.value = page.value * limit.value;
  137. search();
  138. uni.hideLoading();
  139. } else is_bottom.value = true
  140. };
  141. // 清空列表
  142. const clearPage = () => {
  143. list.value = []
  144. skip.value = 0
  145. limit.value = 6
  146. page.value = 0
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .content {
  151. display: flex;
  152. flex-direction: column;
  153. width: 100vw;
  154. height: 100vh;
  155. .top {
  156. margin: 2vw;
  157. }
  158. .bottom {
  159. position: relative;
  160. flex-grow: 1;
  161. background-color: var(--f9Color);
  162. .list {
  163. background-color: var(--mainColor);
  164. border: 1px solid var(--f5Color);
  165. padding: 2vw;
  166. margin: 2vw 2vw 0 2vw;
  167. border-radius: 5px;
  168. .name {
  169. font-size: var(--font16Size);
  170. margin: 0 0 1vw 0;
  171. }
  172. .other {
  173. font-size: var(--font14Size);
  174. text:first-child {
  175. color: var(--f85Color);
  176. }
  177. }
  178. }
  179. }
  180. }
  181. .scroll-view {
  182. position: absolute;
  183. top: 0;
  184. left: 0;
  185. right: 0;
  186. bottom: 0;
  187. .list-scroll-view {
  188. display: flex;
  189. flex-direction: column;
  190. }
  191. }
  192. .is_bottom {
  193. width: 100%;
  194. text-align: center;
  195. text {
  196. padding: 2vw 0;
  197. display: inline-block;
  198. color: var(--f85Color);
  199. font-size: var(--font12Size);
  200. }
  201. }
  202. </style>