index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. if (searchInfo.value.brand) info.brand = searchInfo.value.brand
  151. if (searchInfo.value.place) info.place = searchInfo.value.place
  152. const res = await $api('car', 'GET', {
  153. ...info
  154. });
  155. if (res.errcode === 0) {
  156. total.value = res.total
  157. } else {
  158. uni.showToast({
  159. title: res.errmsg || '',
  160. icon: 'error',
  161. });
  162. }
  163. };
  164. // 查询
  165. const search = async () => {
  166. const data = classifyData.map((item, index) => {
  167. if (item.type == 'boxType') {
  168. // 变速箱
  169. boxTypeList.value.forEach(v => {
  170. v['is_open'] = false;
  171. });
  172. item.foods = boxTypeList.value;
  173. } else if (item.type == 'structure') {
  174. // 车身结构
  175. structureList.value.forEach(v => {
  176. v['is_open'] = false;
  177. });
  178. item.foods = structureList.value;
  179. } else if (item.type == 'emission') {
  180. // 排放标准
  181. emissionList.value.forEach(v => {
  182. v['is_open'] = false;
  183. });
  184. item.foods = emissionList.value;
  185. } else if (item.type == 'energy') {
  186. // 能源类型
  187. energyList.value.forEach(v => {
  188. v['is_open'] = false;
  189. });
  190. item.foods = energyList.value
  191. } else if (item.type == 'displacement') {
  192. // 排量
  193. displacementList.value.forEach(v => {
  194. v['is_open'] = false;
  195. });
  196. item.foods = displacementList.value;
  197. } else if (item.type == 'set') {
  198. // 座椅
  199. setList.value.forEach(v => {
  200. v['is_open'] = false;
  201. });
  202. item.foods = setList.value;
  203. }
  204. return item
  205. })
  206. tabbar.value = data
  207. };
  208. // 点击左边的栏目切换
  209. const swichMenu = (index) => {
  210. if (index == current.value) return;
  211. current.value = index;
  212. itemId.value = `item${index}`
  213. };
  214. // 右侧滚动
  215. const rightScroll = async (e) => {
  216. scrollTop.value = e.scrollTop
  217. };
  218. // 品牌/城市
  219. const toCommon = (type) => {
  220. if (type == '0') {
  221. uni.navigateTo({
  222. url: `/pagesHome/brand/index`
  223. })
  224. } else {
  225. uni.navigateTo({
  226. url: `/pagesHome/city/index`
  227. })
  228. }
  229. };
  230. // 刻度选择
  231. const changeSliderValue = (e, data) => {
  232. tabbar.value = tabbar.value.map((item, index) => {
  233. if (item.name == data.name) {
  234. if (e.firstValue == 0) item.content = `${e.secondValue}${item.unit}以下`
  235. else item.content = `${e.firstValue}-${e.secondValue}${item.unit}`
  236. item.value = e.values
  237. }
  238. return item
  239. })
  240. };
  241. // 选择
  242. const toSelect = async (arr, data) => {
  243. searchList.value.push(data)
  244. tabbar.value = tabbar.value.map((item, index) => {
  245. if (item.type == arr.type) {
  246. item.foods = item.foods.map((item1, index1) => {
  247. if (item1.value == data.value) item1.is_open = !item1.is_open
  248. return item1
  249. })
  250. }
  251. return item
  252. })
  253. };
  254. // 查找
  255. const toSearch = () => {
  256. uni.navigateTo({
  257. url: `/pagesHome/search/index`
  258. })
  259. };
  260. // 重置
  261. const toReset = () => {
  262. searchInfo.value = {}
  263. searchCar()
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. .content {
  268. display: flex;
  269. flex-direction: column;
  270. width: 100vw;
  271. height: 100vh;
  272. .info {
  273. position: relative;
  274. flex-grow: 1;
  275. .u-menu-wrap {
  276. flex: 1;
  277. display: flex;
  278. overflow: hidden;
  279. }
  280. .u-tab-view {
  281. width: 100px;
  282. background: var(--f6Color);
  283. }
  284. .u-tab-item {
  285. height: 55px;
  286. background: var(--f6Color);
  287. box-sizing: border-box;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. font-size: var(--font14Size);
  292. color: #444;
  293. line-height: 1;
  294. }
  295. .u-tab-item-active {
  296. position: relative;
  297. color: var(--f00Color);
  298. font-size: var(--font15Size);
  299. font-weight: 600;
  300. background-color: var(--mainColor);
  301. border-left: 4px solid var(--fFFColor);
  302. }
  303. .right-box {
  304. height: 705px;
  305. background-color: rgb(250, 250, 250);
  306. }
  307. .page-view {
  308. padding: 8px;
  309. }
  310. .class-item {
  311. margin-bottom: 15px;
  312. background-color: var(--mainColor);
  313. padding: 8px;
  314. border-radius: 4px;
  315. }
  316. .item-title {
  317. font-size: var(--font14Size);
  318. margin: 0 0 2vw 0;
  319. .title {
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. .left {
  324. font-weight: bold;
  325. .span {
  326. font-size: var(--font12Size);
  327. color: var(--f85Color);
  328. }
  329. }
  330. }
  331. }
  332. .item-menu-name {
  333. font-size: var(--font12Size);
  334. }
  335. .item-container {
  336. display: flex;
  337. flex-wrap: wrap;
  338. .thumb-box1 {
  339. width: 100%;
  340. }
  341. .thumb-box2 {
  342. width: 100%;
  343. }
  344. .thumb-box3 {
  345. font-size: var(--font12Size);
  346. width: 23vw;
  347. text-align: center;
  348. .title_1 {
  349. padding: 2vw;
  350. margin: 1vw;
  351. background-color: var(--f5Color);
  352. }
  353. .title_2 {
  354. padding: 2vw;
  355. margin: 1vw;
  356. background: rgba(255, 222, 173, 0.35);
  357. border: 1px solid var(--fFFColor);
  358. }
  359. }
  360. }
  361. }
  362. .foot {
  363. display: flex;
  364. justify-content: space-around;
  365. align-items: center;
  366. padding: 2vw;
  367. .right {
  368. .button {
  369. text-align: center;
  370. width: 65vw;
  371. padding: 4vw 6vw;
  372. font-size: var(--font16Size);
  373. background-color: var(--fFFColor);
  374. }
  375. }
  376. }
  377. }
  378. .scroll-view {
  379. position: absolute;
  380. top: 0;
  381. left: 0;
  382. right: 0;
  383. bottom: 0;
  384. .list-scroll-view {
  385. display: flex;
  386. flex-direction: column;
  387. }
  388. }
  389. </style>