index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="content">
  3. <view class="info">
  4. <scroll-view scroll-y="true" class="scroll-view">
  5. <view class="list-scroll-view">
  6. <view class="u-menu-wrap">
  7. <scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view"
  8. :scroll-top="scrollTop">
  9. <view v-for="(item,index) in tabbar" :key="index" :id="'item' + index" class="u-tab-item"
  10. :class="[current == index ? 'u-tab-item-active' : '']" @tap="swichMenu(index)">
  11. <text class="u-line-1">{{item.name}}</text>
  12. </view>
  13. </scroll-view>
  14. <scroll-view :scroll-top="scrollRightTop" scroll-y scroll-with-animation class="right-box"
  15. :scroll-into-view="itemId" @scroll="rightScroll">
  16. <view class="page-view">
  17. <view class="class-item" :id="'item' + index" v-for="(item,index) in tabbar"
  18. :key="index">
  19. <view class="item-title">
  20. <view v-if="item.type!='2'">{{item.name}}</view>
  21. <view v-else class="title">
  22. <view class="left">{{item.name}} <span class="span">({{item.unit}})</span>
  23. </view>
  24. <view class="right">{{item.content||'不限'}}</view>
  25. </view>
  26. </view>
  27. <view class="item-container">
  28. <view v-if="item.type=='1'" class="thumb-box1">
  29. <u-button :text="item.text" size="normal" type="info"
  30. @click="toCommon(item.value)"></u-button>
  31. </view>
  32. <view v-else-if="item.type=='2'" class="thumb-box2">
  33. <slider-range :value="item.value" :min="item.min" :max="item.max"
  34. :step="item.step" :scale="{ show: true}"
  35. @change="event=>changeSliderValue(event,item)">
  36. </slider-range>
  37. </view>
  38. <view v-else v-for="(item1, index1) in item.foods" :key="index1"
  39. @tap="toSelect(item,item1)" class="thumb-box3">
  40. <view :class="[item1?.is_open==false?'title_1':'title_2']">{{item1.label}}
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. <view class="foot">
  52. <view class="left" @tap="toReset">重置</view>
  53. <view class="right">
  54. <view class="button" @tap="toSearch">共{{total}}辆车符合条件</view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script setup lang="ts">
  60. import Vue from 'vue';
  61. import classifyData from '@/pagesHome/condition/common/classify.js';
  62. import SliderRange from '@/components/slider-range/index.vue'
  63. import { getCurrentInstance, computed, ref } from 'vue';
  64. //该依赖已内置不需要单独安装
  65. import { onLoad, onShow } from "@dcloudio/uni-app";
  66. // 请求接口
  67. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  68. // openid
  69. const openid = computed(() => {
  70. return uni.getStorageSync('openid');
  71. })
  72. // 基本信息
  73. const config = ref({});
  74. const id = ref('');
  75. const total = ref(0);
  76. // 滑动菜单的值
  77. const scrollTop = ref(0); //tab标题的滚动条位置
  78. const current = ref(0); // 预设当前项的值
  79. const itemId = ref(''); // 栏目右边scroll-view用于滚动的id
  80. const tabbar = ref([]);
  81. const scrollRightTop = ref(0); // 右边栏目scroll-view的滚动条高度
  82. const cityInfo = ref({}); // 城市信息
  83. const searchList = ref([]); // 选中的搜索信息
  84. // 查询
  85. const searchInfo = ref({});
  86. // 字典表
  87. const boxTypeList = ref([]);
  88. const structureList = ref([]);
  89. const emissionList = ref([]);
  90. const energyList = ref([]);
  91. const displacementList = ref([]);
  92. const setList = ref([]);
  93. onLoad(async (options) => {
  94. id.value = options && options.id
  95. await searchOther();
  96. await searchCar();
  97. await searchConfig();
  98. await search();
  99. })
  100. onShow(async () => {
  101. uni.$on('toRoute', function (data) {
  102. searchInfo.value.brand = data.name
  103. tabbar.value = tabbar.value.map((item, index) => {
  104. if (item.type == '1' && item.value == '0') item.text = data.name
  105. return item
  106. })
  107. })
  108. uni.$on('toCity', function (data) {
  109. searchInfo.value.place = data.name
  110. tabbar.value = tabbar.value.map((item, index) => {
  111. if (item.type == '1' && item.value == '1') item.text = data.name
  112. return item
  113. })
  114. })
  115. await searchCar();
  116. })
  117. // 查询其他信息
  118. const searchOther = async () => {
  119. let res;
  120. // 变速箱
  121. res = await $api(`dictData`, 'GET', { code: 'boxType', is_use: '0' });
  122. if (res.errcode === 0) boxTypeList.value = res.data;
  123. // 车身结构
  124. res = await $api(`dictData`, 'GET', { code: 'structure', is_use: '0' });
  125. if (res.errcode === 0) structureList.value = res.data;
  126. // 排放标准
  127. res = await $api(`dictData`, 'GET', { code: 'emission', is_use: '0' });
  128. if (res.errcode === 0) emissionList.value = res.data;
  129. // 能源类型
  130. res = await $api(`dictData`, 'GET', { code: 'energy', is_use: '0' });
  131. if (res.errcode === 0) energyList.value = res.data;
  132. // 排量
  133. res = await $api(`dictData`, 'GET', { code: 'displacement', is_use: '0' });
  134. if (res.errcode === 0) displacementList.value = res.data;
  135. // 座椅
  136. res = await $api(`dictData`, 'GET', { code: 'set', is_use: '0' });
  137. if (res.errcode === 0) setList.value = res.data;
  138. };
  139. // config信息
  140. const searchConfig = async () => {
  141. config.value = uni.getStorageSync('config');
  142. };
  143. // 车辆信息
  144. const searchCar = async () => {
  145. const info = {
  146. skip: 0,
  147. limit: 1,
  148. status: '0'
  149. }
  150. for (let val of searchList.value) {
  151. if (val.code == 'displacement') info[val.code] = val.label
  152. else info[val.code] = val.value
  153. }
  154. const res = await $api('car', 'GET', {
  155. ...info,
  156. ...searchInfo.value
  157. });
  158. if (res.errcode === 0) {
  159. total.value = res.total
  160. } else {
  161. uni.showToast({
  162. title: res.errmsg || '',
  163. icon: 'error',
  164. });
  165. }
  166. };
  167. // 查询
  168. const search = async () => {
  169. const data = classifyData.map((item, index) => {
  170. if (item.type == 'boxType') {
  171. // 变速箱
  172. boxTypeList.value.forEach(v => {
  173. v['is_open'] = false;
  174. });
  175. item.foods = boxTypeList.value;
  176. } else if (item.type == 'structure') {
  177. // 车身结构
  178. structureList.value.forEach(v => {
  179. v['is_open'] = false;
  180. });
  181. item.foods = structureList.value;
  182. } else if (item.type == 'emission') {
  183. // 排放标准
  184. emissionList.value.forEach(v => {
  185. v['is_open'] = false;
  186. });
  187. item.foods = emissionList.value;
  188. } else if (item.type == 'energy') {
  189. // 能源类型
  190. energyList.value.forEach(v => {
  191. v['is_open'] = false;
  192. });
  193. item.foods = energyList.value
  194. } else if (item.type == 'displacement') {
  195. // 排量
  196. displacementList.value.forEach(v => {
  197. v['is_open'] = false;
  198. });
  199. item.foods = displacementList.value;
  200. } else if (item.type == 'set') {
  201. // 座椅
  202. setList.value.forEach(v => {
  203. v['is_open'] = false;
  204. });
  205. item.foods = setList.value;
  206. }
  207. return item
  208. })
  209. tabbar.value = data
  210. };
  211. // 点击左边的栏目切换
  212. const swichMenu = (index) => {
  213. if (index == current.value) return;
  214. current.value = index;
  215. itemId.value = `item${index}`
  216. };
  217. // 右侧滚动
  218. const rightScroll = async (e) => {
  219. scrollTop.value = e.scrollTop
  220. };
  221. // 品牌/城市
  222. const toCommon = (type) => {
  223. if (type == '0') {
  224. uni.navigateTo({
  225. url: `/pagesHome/brand/index`
  226. })
  227. } else {
  228. uni.navigateTo({
  229. url: `/pagesHome/city/index`
  230. })
  231. }
  232. };
  233. // 刻度选择
  234. const changeSliderValue = async (e, data) => {
  235. tabbar.value = tabbar.value.map((item, index) => {
  236. if (item.name == data.name) {
  237. if (e.firstValue == 0) item.content = `${e.secondValue}${item.unit}以下`
  238. else item.content = `${e.firstValue}-${e.secondValue}${item.unit}`
  239. item.value = e.values
  240. }
  241. return item
  242. })
  243. if (data.name == '价格') searchInfo.value.money = data.content
  244. else if (data.name == '车龄') searchInfo.value.year = data.content
  245. else searchInfo.value.mileage = data.content
  246. await searchCar();
  247. };
  248. // 选择
  249. const toSelect = async (arr, data) => {
  250. searchList.value.push(data)
  251. tabbar.value = tabbar.value.map((item, index) => {
  252. if (item.type == arr.type) {
  253. item.foods = item.foods.map((item1, index1) => {
  254. if (item1.value == data.value) item1.is_open = !item1.is_open
  255. return item1
  256. })
  257. }
  258. return item
  259. })
  260. await searchCar();
  261. };
  262. // 查找
  263. const toSearch = () => {
  264. uni.navigateTo({
  265. url: `/pagesHome/search/index`
  266. })
  267. };
  268. // 重置
  269. const toReset = async () => {
  270. searchInfo.value = {}
  271. searchList.value = []
  272. await search()
  273. await searchCar()
  274. };
  275. </script>
  276. <style lang="scss" scoped>
  277. .content {
  278. display: flex;
  279. flex-direction: column;
  280. width: 100vw;
  281. height: 100vh;
  282. .info {
  283. position: relative;
  284. flex-grow: 1;
  285. .u-menu-wrap {
  286. flex: 1;
  287. display: flex;
  288. overflow: hidden;
  289. }
  290. .u-tab-view {
  291. width: 100px;
  292. background: var(--f6Color);
  293. }
  294. .u-tab-item {
  295. height: 55px;
  296. background: var(--f6Color);
  297. box-sizing: border-box;
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. font-size: var(--font14Size);
  302. color: #444;
  303. line-height: 1;
  304. }
  305. .u-tab-item-active {
  306. position: relative;
  307. color: var(--f00Color);
  308. font-size: var(--font15Size);
  309. font-weight: 600;
  310. background-color: var(--mainColor);
  311. border-left: 4px solid var(--fFFColor);
  312. }
  313. .right-box {
  314. height: 705px;
  315. background-color: rgb(250, 250, 250);
  316. }
  317. .page-view {
  318. padding: 8px;
  319. }
  320. .class-item {
  321. margin-bottom: 15px;
  322. background-color: var(--mainColor);
  323. padding: 8px;
  324. border-radius: 4px;
  325. }
  326. .item-title {
  327. font-size: var(--font14Size);
  328. margin: 0 0 2vw 0;
  329. .title {
  330. display: flex;
  331. align-items: center;
  332. justify-content: space-between;
  333. .left {
  334. font-weight: bold;
  335. .span {
  336. font-size: var(--font12Size);
  337. color: var(--f85Color);
  338. }
  339. }
  340. }
  341. }
  342. .item-menu-name {
  343. font-size: var(--font12Size);
  344. }
  345. .item-container {
  346. display: flex;
  347. flex-wrap: wrap;
  348. .thumb-box1 {
  349. width: 100%;
  350. }
  351. .thumb-box2 {
  352. width: 100%;
  353. }
  354. .thumb-box3 {
  355. font-size: var(--font12Size);
  356. width: 23vw;
  357. text-align: center;
  358. .title_1 {
  359. padding: 2vw;
  360. margin: 1vw;
  361. background-color: var(--f5Color);
  362. }
  363. .title_2 {
  364. padding: 2vw;
  365. margin: 1vw;
  366. background: rgba(255, 222, 173, 0.35);
  367. border: 1px solid var(--fFFColor);
  368. }
  369. }
  370. }
  371. }
  372. .foot {
  373. display: flex;
  374. justify-content: space-around;
  375. align-items: center;
  376. padding: 2vw;
  377. .right {
  378. .button {
  379. text-align: center;
  380. width: 65vw;
  381. padding: 4vw 6vw;
  382. font-size: var(--font16Size);
  383. background-color: var(--fFFColor);
  384. }
  385. }
  386. }
  387. }
  388. .scroll-view {
  389. position: absolute;
  390. top: 0;
  391. left: 0;
  392. right: 0;
  393. bottom: 0;
  394. .list-scroll-view {
  395. display: flex;
  396. flex-direction: column;
  397. }
  398. }
  399. </style>