金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

544 lines
14 KiB

  1. <template>
  2. <view class="centent">
  3. <lf-nav :title="['分类','品牌'][current]" bgColor="#fff" :search="current == 0" @changeHeight="e => nav_height = e"></lf-nav>
  4. <view class="tabs">
  5. <view class="lf-tab"
  6. :style="{width: 100 / tabs.length +'%'}"
  7. :class="{'tab-active': current == index}"
  8. v-for="(item, index) in tabs" :key="index"
  9. @click="current = index">{{ item.name }}
  10. </view>
  11. </view>
  12. <!-- 分类 -->
  13. <view class="page" v-if="current == 0 && dataArr.length">
  14. <scroll-view class="left_view p_r" scroll-y :style="{ height: autoHeight }">
  15. <block v-for="(item, index) in dataArr" :key="index">
  16. <view :class="[left_selectIndex == index ? 'left_item_s' : '', 'left_item']" :id="'left_' + index" @click="leftTap({ item, index })">{{ item.name }}</view>
  17. </block>
  18. <view class="seletItem" :style="{ top: left_selectIndex * 60 - 19 + 'px' }"></view>
  19. </scroll-view>
  20. <scroll-view @scroll="rightScroll" class="right_view" scroll-y :style="{ height: autoHeight }" :scroll-into-view="'left_' + right_selectIndex" scroll-with-animation>
  21. <block v-for="(item, index) in dataArr" :key="index">
  22. <view :ref="'left_' + index" class="right_item " :id="'left_' + index">
  23. <text class="right_item_title ">{{ item.name }}</text>
  24. <view class="right_item_view">
  25. <view class="item" v-for="(c_item, c_index) in item.sub_category" :key="c_index" @click="rightTap(c_item)">
  26. <image :src="c_item.image" :style="{ width: '100%', height: subItemW + 'px', background: '#999999' }"></image>
  27. <text class="lf-font-24">{{ c_item.name }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </block>
  32. <view class="" :style="{ height: autoScrollHeight }"><!-- 站位 --></view>
  33. </scroll-view>
  34. </view>
  35. <!-- 品牌 -->
  36. <view class="brand" v-else-if="current == 1" :style="{height: autoHeight}">
  37. <!-- 筛选 -->
  38. <view class="lf-filter-box" :style="{'z-index': filter_active == '' ? 1 : 99}">
  39. <view class="lf-filter" :class="{'lf-filter-after': filter_active == ''}">
  40. <view v-for="(value, key) in filter_list" :key="key"
  41. :class="{'filter-active': filter_active == key}"
  42. @click="filter_active = key">{{ value.name }}
  43. </view>
  44. </view>
  45. <view class="filter-modal-mask" :style="{height: otherHeight}" v-if="filter_active != ''" @click="filter_active = ''">
  46. <view class="filter-modal" @click.stop>
  47. <view class="filter-item"
  48. :class="{'filter-item-active': filter_list[filter_active].current == index}"
  49. @click="selectFilter(item, index)"
  50. v-for="(item, index) in filter_list[filter_active].list"
  51. :key="index">{{ item.name || item }}
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 内容 -->
  57. <scroll-view class="brand-scroll" :scroll-into-view="scrollAnchorId" :scroll-y="true" :style="{height: otherHeight}">
  58. <view class="lf-flex brand-item"
  59. :id="'anchor-'+ item.initial"
  60. @click="$url('/pages/shop/shopdetail?id='+ item.id)"
  61. v-for="(item, index) in brand_list" :key="index">
  62. <image class="img" :src="item.logo"></image>
  63. <view class="info">
  64. <view class="lf-font-36 lf-font-bold lf-color-black">{{ item.name }}</view>
  65. <view class="lf-font-24 lf-color-gray">{{ item.category }}{{ item.goods_count || 0 }}件在售</view>
  66. <view class="lf-font-24">
  67. <text class="lf-iconfont icon-dizhi lf-font-24 lf-color-primary"></text>
  68. <text class="lf-color-gray lf-m-l-10">{{ item.floor }}</text>
  69. </view>
  70. </view>
  71. </view>
  72. </scroll-view>
  73. <!-- 锚点定位 -->
  74. <view class="fixed-point" v-if="point_list.length">
  75. <view class="fixed-content" @touchmove="pointTouchmove">
  76. <view class="point-item"
  77. @click="pointClick"
  78. :id="'point-'+ item"
  79. :style="{height: 100 / 26 +'%'}"
  80. v-for="(item, index) in point_list"
  81. :key="index">{{ item }}
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <lf-tabbar></lf-tabbar>
  87. </view>
  88. </template>
  89. <script>
  90. import lfNav from '@/components/lf-nav/lf-nav.vue';
  91. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  92. import testdata from './testdata.js';
  93. let app = getApp();
  94. export default {
  95. data() {
  96. return {
  97. scrollH: 0,
  98. subItemW: 0,
  99. left_selectIndex: 0,
  100. right_selectIndex: 0,
  101. ttscrollH: 0, //总高度
  102. placeholderH: 0, //占位高度
  103. heighArr: [],
  104. dataArr: [],
  105. current: 1,
  106. nav_height: 0,
  107. tabs: [{
  108. name: '分类'
  109. },{
  110. name: '品牌'
  111. }],
  112. filter_list: {
  113. 'floor': {
  114. name: '楼层',
  115. list: [],
  116. current: null
  117. },
  118. 'class': {
  119. name: '分类',
  120. list: [],
  121. current: null
  122. }
  123. },
  124. filter_active: '',
  125. brand_list: [],
  126. point_list: [],
  127. scrollAnchorId: ''
  128. };
  129. },
  130. computed: {
  131. autoHeight(){
  132. return `calc(${this.scrollH}px - ${this.nav_height}px - 90rpx - 120rpx)`;
  133. },
  134. otherHeight(){
  135. // 屏幕可用总高度 - 导航条高度 - tabs高度 - tabbar高度 - 筛选高度
  136. return `calc(${this.scrollH}px - ${this.nav_height}px - 90rpx - 120rpx - 105rpx)`;
  137. },
  138. autoScrollHeight(){
  139. return `calc(${this.scrollH}px - ${this.nav_height}px - 90rpx - 120rpx - 300rpx)`;
  140. }
  141. },
  142. components: {
  143. lfNav,
  144. lfTabbar
  145. },
  146. onLoad(options) {
  147. // https://ext.dcloud.net.cn/plugin?id=5031
  148. this.getBrandList();
  149. if(this.$isRight(options)){
  150. this.current = options.current || 1;
  151. this.left_selectIndex = options.type || 0;
  152. this.right_selectIndex = options.type || 0;
  153. }
  154. let info = uni.getSystemInfoSync();
  155. let self = this;
  156. self.scrollH = info.screenHeight;
  157. self.subItemW = parseInt((info.screenWidth * (2 / 3) - 15 * 2 - 24) / 3);
  158. this.getCategoryList().then(() => {
  159. self.computerH();
  160. });
  161. // setTimeout(function() {
  162. // self.computerH();
  163. // }, 100);
  164. // this.createAtoZ();
  165. },
  166. methods: {
  167. getBrandList(){
  168. this.$http.get({
  169. api: '/api/brand'
  170. }).then(res => {
  171. console.log("getBrandList", res);
  172. let category = res.data.data.category;
  173. let floor = res.data.data.floor;
  174. this.filter_list['floor'].list = floor;
  175. this.filter_list['class'].list = category;
  176. this.brand_list = res.data.data.list;
  177. this.autoCreateAtoZ(res.data.data.list);
  178. });
  179. },
  180. getCategoryList(){
  181. return new Promise((resolve, reject) => {
  182. this.$http.get({
  183. api: '/api/category/list'
  184. }).then(res => {
  185. console.log("getCategoryList", res);
  186. this.dataArr = res.data.data;
  187. resolve(res);
  188. }).catch(err => reject(err));
  189. }) },
  190. // 选择筛选项
  191. selectFilter(item, index){
  192. console.log(item, index);
  193. this.filter_list[this.filter_active].current = index;
  194. this.filter_active = '';
  195. },
  196. // 生成A-Z的大写字母 自己生成的
  197. createAtoZ(){
  198. let point_list = [];
  199. for(var i=0; i<26; i++){
  200. point_list.push(String.fromCharCode(65+i));
  201. }
  202. this.point_list = point_list;
  203. },
  204. // 生成A-Z的大写字母 根据店铺类别动态生成
  205. autoCreateAtoZ(list){
  206. let letters = Array.from(new Set(list.map(item => item.initial)));
  207. letters.sort(function(a1, b1){
  208. let a = a1.toLowerCase();
  209. let b = b1.toLowerCase();
  210. if (a < b) return -1;
  211. if (a > b) return 1;
  212. return 0;
  213. })
  214. this.point_list = letters;
  215. },
  216. pointTouchmove(event){
  217. console.log(event);
  218. },
  219. pointClick(event){
  220. // let index = (event.target.id).replace('point-', '');
  221. // let letter = this.point_list[index];
  222. let letter = (event.target.id).replace('point-', '');
  223. this.scrollAnchorId = '';
  224. this.$msg(letter);
  225. this.$nextTick(() => {
  226. this.scrollAnchorId = 'anchor-'+ letter;
  227. })
  228. },
  229. leftTap: function(e) {
  230. this.left_selectIndex = e.index;
  231. this.right_selectIndex = e.index;
  232. },
  233. // 右边点击
  234. rightTap: function(item) {
  235. console.log(item);
  236. this.$url('/pages/index/onlineMall/onlineMall?id='+ item.id);
  237. },
  238. rightScroll: function(e) {
  239. let scrollH = e.detail.scrollTop + 30;
  240. let cc = this.ttscrollH - this.scrollH;
  241. let a = 0;
  242. let findInx = this.heighArr.findIndex(function(itemH, i) {
  243. a = a + itemH;
  244. return a > scrollH;
  245. });
  246. // if (scrollH >= cc) {
  247. // return;
  248. // }
  249. this.left_selectIndex = findInx;
  250. },
  251. // 计算高度
  252. computerH: function() {
  253. this.ttscrollH = 0;
  254. for (let item of this.dataArr) {
  255. let title_lineH = 49; //rpx
  256. let subNum = item.sub_category.length;
  257. let subImgH = this.subItemW; //rpx
  258. let subTitleH = 40; //rpx
  259. let rowSpecH = 8; //rpx
  260. let rowN = subNum % 3;
  261. let rowSpecNum = parseInt(subNum / 3) + parseInt(rowN > 0 ? 1 : 0);
  262. let totalRpx = title_lineH + (subImgH + subTitleH) * rowSpecNum + rowSpecH * (rowSpecNum - 1);
  263. this.heighArr.push(totalRpx);
  264. this.ttscrollH = this.ttscrollH + totalRpx;
  265. }
  266. // this.placeholderH = this.scrollH - this.heighArr[this.heighArr.length - 1];
  267. //以下方法也可以
  268. // let self=this
  269. // var selectorQuery = uni.createSelectorQuery()
  270. // selectorQuery.selectAll('.right_item').boundingClientRect(data => {
  271. // self.heighArr = data.map(item => {
  272. // return {
  273. // top: Math.round(item.top),
  274. // height: Math.round(item.height)
  275. // }
  276. // })
  277. // }).exec()
  278. // console.log('ttscrollH',this.$refs.left_0)
  279. }
  280. }
  281. }
  282. </script>
  283. <style lang="scss" scoped>
  284. .page {
  285. display: grid;
  286. grid-template-columns: 1fr 2fr;
  287. grid-template-rows: auto;
  288. position: absolute;
  289. left: 0rpx;
  290. right: 0rpx;
  291. overflow: hidden;
  292. box-sizing: border-box;
  293. }
  294. .left_view {
  295. background-color: #f4f8f8;
  296. position: relative;
  297. box-sizing: border-box;
  298. // 蒙版
  299. .seletItem {
  300. height: 98px;
  301. position: absolute;
  302. top: 0rpx;
  303. left: 0rpx;
  304. z-index: 10;
  305. right: 0rpx;
  306. // background-color: rgba(255, 255, 255, 0.3);
  307. transition: top 0.2s linear;
  308. display: flex;
  309. align-items: center;
  310. box-sizing: border-box;
  311. &::before {
  312. content: '';
  313. width: 6rpx;
  314. height: 60%;
  315. background-color: #15716E;
  316. left: 0rpx;
  317. }
  318. }
  319. .left_item {
  320. display: flex;
  321. justify-content: center;
  322. align-items: center;
  323. height: 60px;
  324. margin-bottom: 0rpx;
  325. position: relative;
  326. font-size: 28rpx;
  327. box-sizing: border-box;
  328. color: #555555;
  329. }
  330. .left_item_s {
  331. background-color: #ffffff;
  332. color: #15716E;
  333. font-weight: bold;
  334. position: relative;
  335. box-sizing: border-box;
  336. }
  337. }
  338. .right_view {
  339. background-color: #ffffff;
  340. padding: 0rpx 12px;
  341. box-sizing: border-box;
  342. .right_item {
  343. .right_item_title {
  344. display: block;
  345. box-sizing: border-box;
  346. line-height: 49px;
  347. font-size: 28rpx;
  348. font-weight: bold;
  349. color: #15716E;
  350. }
  351. .right_item_view {
  352. display: grid;
  353. grid-template-columns: repeat(3, 1fr);
  354. grid-template-rows: auto;
  355. grid-gap: 8px 15px;
  356. box-sizing: border-box;
  357. .item {
  358. display: flex;
  359. flex-flow: column nowrap;
  360. align-items: center;
  361. box-sizing: border-box;
  362. text {
  363. color: #333;
  364. line-height: 40px;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. .tabs{
  371. width: 750rpx;
  372. height: 90rpx;
  373. display: flex;
  374. justify-content: space-between;
  375. border-bottom: 1rpx solid #e5e5e5;
  376. background-color: #FFFFFF;
  377. .lf-tab{
  378. // width: 50%;
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. font-size: 28rpx;
  383. color: #777777;
  384. position: relative;
  385. &.tab-active{
  386. color: #15716E;
  387. }
  388. &.tab-active::after{
  389. content: '';
  390. position: absolute;
  391. bottom: 0;
  392. left: 50%;
  393. width: 80rpx;
  394. height: 10rpx;
  395. background-color: #15716E;
  396. border-radius: 10rpx 10rpx 0 0;
  397. margin-left: -40rpx;
  398. }
  399. }
  400. }
  401. .lf-filter-box{
  402. height: 105rpx;
  403. width: 750rpx;
  404. background-color: #F4F8F8;
  405. display: flex;
  406. justify-content: center;
  407. align-items: center;
  408. position: relative;
  409. .lf-filter{
  410. width: 300rpx;
  411. height: 65rpx;
  412. border-radius: 33rpx;
  413. border: 1rpx solid #15716E;
  414. color: #15716E;
  415. font-size: 24rpx;
  416. display: flex;
  417. align-items: center;
  418. justify-content: space-between;
  419. position: relative;
  420. overflow: hidden;
  421. &.lf-filter-after::after{
  422. content: '';
  423. position: absolute;
  424. top: 12rpx;
  425. left: calc(50% - 1rpx);
  426. width: 2rpx;
  427. height: 40rpx;
  428. background-color: #15716E;
  429. }
  430. &>view{
  431. height: 100%;
  432. width: 50%;
  433. display: flex;
  434. justify-content: space-around;
  435. align-items: center;
  436. }
  437. .filter-active{
  438. background-color: #15716E;
  439. color: #FFFFFF;
  440. }
  441. }
  442. .filter-modal-mask{
  443. position: absolute;
  444. top: 105rpx;
  445. left: 0;
  446. width: 100%;
  447. background-color: rgba(0,0,0,0.5);
  448. z-index: 99;
  449. .filter-modal{
  450. width: 750rpx;
  451. height: max-content;
  452. padding: 60rpx 32rpx;
  453. box-sizing: border-box;
  454. background-color: #FFFFFF;
  455. display: flex;
  456. flex-wrap: wrap;
  457. position: relative;
  458. z-index: 102;
  459. .filter-item{
  460. width: 215rpx;
  461. height: 65rpx;
  462. border-radius: 10rpx;
  463. border: 1rpx solid #555555;
  464. display: flex;
  465. justify-content: center;
  466. align-items: center;
  467. font-size: 28rpx;
  468. color: #555555;
  469. margin-right: 21rpx;
  470. &:nth-child(3n){
  471. margin-right: 0rpx;
  472. }
  473. &:nth-child(n+4){
  474. margin-top: 21rpx;
  475. }
  476. }
  477. .filter-item-active{
  478. background-color: #15716E;
  479. color: #FFFFFF;
  480. }
  481. }
  482. }
  483. }
  484. .brand-scroll{
  485. padding: 0rpx 32rpx;
  486. box-sizing: border-box;
  487. width: 750rpx;
  488. .brand-item{
  489. margin-bottom: 60rpx;
  490. &:nth-child(1n){
  491. margin-top: 30rpx;
  492. }
  493. }
  494. .img{
  495. width: 150rpx;
  496. height: 150rpx;
  497. border-radius: 4rpx;
  498. margin-right: 20rpx;
  499. }
  500. .info{
  501. width: 514rpx;
  502. height: 150rpx;
  503. display: flex;
  504. flex-direction: column;
  505. justify-content: space-between;
  506. }
  507. }
  508. .brand{
  509. position: relative;
  510. }
  511. .fixed-point{
  512. position: fixed;
  513. right: 0;
  514. top: 0;
  515. // top: 18vh;
  516. // height: 70vh;
  517. height: 100vh;
  518. width: 57rpx;
  519. z-index: 2;
  520. display: flex;
  521. align-items: center;
  522. .fixed-content{
  523. width: 100%;
  524. height: max-content;
  525. padding: 14rpx 0rpx;
  526. background-color: rgba(0,0,0,0.3);
  527. border-radius: 30rpx 0rpx 0rpx 30rpx;
  528. .point-item{
  529. font-size: 24rpx;
  530. color: #FFFFFF;
  531. text-align: center;
  532. }
  533. }
  534. }
  535. </style>