金诚优选前端代码
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.

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