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

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