index.vue 11 KB

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