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

568 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-into-view="left_tabview" 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" :id="'tab_'+ left_selectIndex" :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. 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. left_tabview: 'tab_0', // 默认和left_selectIndex对应,scroll-view定位到的左侧tab元素
  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. this.left_tabview = '';
  271. setTimeout(() => {
  272. this.left_tabview = 'tab_'+ findInx; // TODO 待验证是否跟随滚动
  273. }, 0);
  274. },
  275. // 计算高度
  276. computerH: function() {
  277. this.ttscrollH = 0;
  278. for (let item of this.dataArr) {
  279. let title_lineH = 49; //rpx
  280. let subNum = item.sub_category.length;
  281. let subImgH = this.subItemW; //rpx
  282. let subTitleH = 40; //rpx
  283. let rowSpecH = 8; //rpx
  284. let rowN = subNum % 3;
  285. let rowSpecNum = parseInt(subNum / 3) + parseInt(rowN > 0 ? 1 : 0);
  286. let totalRpx = title_lineH + (subImgH + subTitleH) * rowSpecNum + rowSpecH * (rowSpecNum - 1);
  287. this.heighArr.push(totalRpx);
  288. this.ttscrollH = this.ttscrollH + totalRpx;
  289. }
  290. // this.placeholderH = this.scrollH - this.heighArr[this.heighArr.length - 1];
  291. //以下方法也可以
  292. // let self=this
  293. // var selectorQuery = uni.createSelectorQuery()
  294. // selectorQuery.selectAll('.right_item').boundingClientRect(data => {
  295. // self.heighArr = data.map(item => {
  296. // return {
  297. // top: Math.round(item.top),
  298. // height: Math.round(item.height)
  299. // }
  300. // })
  301. // }).exec()
  302. // console.log('ttscrollH',this.$refs.left_0)
  303. }
  304. }
  305. }
  306. </script>
  307. <style lang="scss" scoped>
  308. .page {
  309. display: grid;
  310. grid-template-columns: 1fr 2fr;
  311. grid-template-rows: auto;
  312. position: absolute;
  313. left: 0rpx;
  314. right: 0rpx;
  315. overflow: hidden;
  316. box-sizing: border-box;
  317. }
  318. .left_view {
  319. background-color: #f4f8f8;
  320. position: relative;
  321. box-sizing: border-box;
  322. // 蒙版
  323. .seletItem {
  324. height: 98px;
  325. position: absolute;
  326. top: 0rpx;
  327. left: 0rpx;
  328. z-index: 10;
  329. right: 0rpx;
  330. // background-color: rgba(255, 255, 255, 0.3);
  331. transition: top 0.2s linear;
  332. display: flex;
  333. align-items: center;
  334. box-sizing: border-box;
  335. &::before {
  336. content: '';
  337. width: 6rpx;
  338. height: 60%;
  339. background-color: #15716E;
  340. left: 0rpx;
  341. }
  342. }
  343. .left_item {
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. height: 60px;
  348. margin-bottom: 0rpx;
  349. position: relative;
  350. font-size: 28rpx;
  351. box-sizing: border-box;
  352. color: #555555;
  353. }
  354. .left_item_s {
  355. background-color: #ffffff;
  356. color: #15716E;
  357. font-weight: bold;
  358. position: relative;
  359. box-sizing: border-box;
  360. }
  361. }
  362. .right_view {
  363. background-color: #ffffff;
  364. padding: 0rpx 12px;
  365. box-sizing: border-box;
  366. .right_item {
  367. .right_item_title {
  368. display: block;
  369. box-sizing: border-box;
  370. line-height: 49px;
  371. font-size: 28rpx;
  372. font-weight: bold;
  373. color: #15716E;
  374. }
  375. .right_item_view {
  376. display: grid;
  377. grid-template-columns: repeat(3, 1fr);
  378. grid-template-rows: auto;
  379. grid-gap: 8px 15px;
  380. box-sizing: border-box;
  381. .item {
  382. display: flex;
  383. flex-flow: column nowrap;
  384. align-items: center;
  385. box-sizing: border-box;
  386. text {
  387. color: #333;
  388. line-height: 40px;
  389. }
  390. }
  391. }
  392. }
  393. }
  394. .tabs{
  395. width: 750rpx;
  396. height: 90rpx;
  397. display: flex;
  398. justify-content: space-between;
  399. border-bottom: 1rpx solid #e5e5e5;
  400. background-color: #FFFFFF;
  401. .lf-tab{
  402. // width: 50%;
  403. display: flex;
  404. align-items: center;
  405. justify-content: center;
  406. font-size: 28rpx;
  407. color: #777777;
  408. position: relative;
  409. &.tab-active{
  410. color: #15716E;
  411. }
  412. &.tab-active::after{
  413. content: '';
  414. position: absolute;
  415. bottom: 0;
  416. left: 50%;
  417. width: 80rpx;
  418. height: 10rpx;
  419. background-color: #15716E;
  420. border-radius: 10rpx 10rpx 0 0;
  421. margin-left: -40rpx;
  422. }
  423. }
  424. }
  425. .lf-filter-box{
  426. height: 105rpx;
  427. width: 750rpx;
  428. background-color: #F4F8F8;
  429. display: flex;
  430. justify-content: center;
  431. align-items: center;
  432. position: relative;
  433. .lf-filter{
  434. width: 300rpx;
  435. height: 65rpx;
  436. border-radius: 33rpx;
  437. border: 1rpx solid #15716E;
  438. color: #15716E;
  439. font-size: 24rpx;
  440. display: flex;
  441. align-items: center;
  442. justify-content: space-between;
  443. position: relative;
  444. overflow: hidden;
  445. &.lf-filter-after::after{
  446. content: '';
  447. position: absolute;
  448. top: 12rpx;
  449. left: calc(50% - 1rpx);
  450. width: 2rpx;
  451. height: 40rpx;
  452. background-color: #15716E;
  453. }
  454. &>view{
  455. height: 100%;
  456. width: 50%;
  457. display: flex;
  458. justify-content: space-around;
  459. align-items: center;
  460. }
  461. .filter-active{
  462. background-color: #15716E;
  463. color: #FFFFFF;
  464. }
  465. }
  466. .filter-modal-mask{
  467. position: absolute;
  468. top: 105rpx;
  469. left: 0;
  470. width: 100%;
  471. background-color: rgba(0,0,0,0.5);
  472. z-index: 99;
  473. .filter-modal{
  474. width: 750rpx;
  475. height: max-content;
  476. padding: 60rpx 32rpx;
  477. box-sizing: border-box;
  478. background-color: #FFFFFF;
  479. display: flex;
  480. flex-wrap: wrap;
  481. position: relative;
  482. z-index: 102;
  483. .filter-item{
  484. width: 215rpx;
  485. height: 65rpx;
  486. border-radius: 10rpx;
  487. border: 1rpx solid #555555;
  488. display: flex;
  489. justify-content: center;
  490. align-items: center;
  491. font-size: 28rpx;
  492. color: #555555;
  493. margin-right: 21rpx;
  494. &:nth-child(3n){
  495. margin-right: 0rpx;
  496. }
  497. &:nth-child(n+4){
  498. margin-top: 21rpx;
  499. }
  500. }
  501. .filter-item-active{
  502. background-color: #15716E;
  503. color: #FFFFFF;
  504. }
  505. }
  506. }
  507. }
  508. .brand-scroll{
  509. padding: 0rpx 32rpx;
  510. box-sizing: border-box;
  511. width: 750rpx;
  512. .brand-item{
  513. margin-bottom: 60rpx;
  514. &:nth-child(1n){
  515. margin-top: 30rpx;
  516. }
  517. }
  518. .img{
  519. width: 150rpx;
  520. height: 150rpx;
  521. border-radius: 4rpx;
  522. margin-right: 20rpx;
  523. }
  524. .info{
  525. width: 514rpx;
  526. height: 150rpx;
  527. display: flex;
  528. flex-direction: column;
  529. justify-content: space-between;
  530. }
  531. }
  532. .brand{
  533. position: relative;
  534. }
  535. .fixed-point{
  536. position: fixed;
  537. right: 0;
  538. top: 0;
  539. // top: 18vh;
  540. // height: 70vh;
  541. height: 100vh;
  542. width: 57rpx;
  543. z-index: 2;
  544. display: flex;
  545. align-items: center;
  546. .fixed-content{
  547. width: 100%;
  548. height: max-content;
  549. padding: 14rpx 0rpx;
  550. background-color: rgba(0,0,0,0.3);
  551. border-radius: 30rpx 0rpx 0rpx 30rpx;
  552. .point-item{
  553. font-size: 24rpx;
  554. color: #FFFFFF;
  555. text-align: center;
  556. }
  557. }
  558. }
  559. </style>