index.vue 10.0 KB

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