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

454 lines
12 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">
  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="(item, index) in item.subArr" :key="index" @click="rightTap(item)">
  26. <image :src="item.img" :style="{ width: '100%', height: subItemW + 'px', background: '#999999' }"></image>
  27. <text class="lf-font-24">{{ item.name }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </block>
  32. <view class="" :style="{ height: 'calc('+ scrollH / 2 +'px)' }"><!-- 站位 --></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">
  39. <view class="lf-filter" :class="{'lf-filter-after': filter_active == ''}">
  40. <view :class="{'filter-active': filter_active == 'floor'}" @click="filter_active = 'floor'">楼层</view>
  41. <view :class="{'filter-active': filter_active == 'class'}" @click="filter_active = 'class'">分类</view>
  42. </view>
  43. <view class="filter-modal-mask" :style="{height: otherHeight}" v-if="filter_active != ''" @click="filter_active = ''">
  44. <view class="filter-modal">
  45. <view class="filter-item" v-for="(item, index) in 6" :key="index">{{ '哈哈'+ item }}</view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 内容 -->
  50. <scroll-view class="brand-scroll" :scroll-into-view="scrollAnchorId" :scroll-y="true" :style="{height: otherHeight}">
  51. <view class="lf-flex brand-item"
  52. :id="'anchor-'+ index"
  53. @click="$url('/pages/shop/shopdetail')"
  54. v-for="(item, index) in point_list" :key="index">
  55. <image class="img" src="https://picsum.photos/200"></image>
  56. <view class="info">
  57. <view class="lf-font-36 lf-font-bold lf-color-black">luckin coffee 瑞幸咖啡 {{ item }}</view>
  58. <view class="lf-font-24 lf-color-gray">餐饮·美食18件在售</view>
  59. <view class="lf-font-24">
  60. <text class="lf-iconfont icon--1 lf-font-24"></text>
  61. <text class="lf-color-gray lf-m-l-10">L2</text>
  62. </view>
  63. </view>
  64. </view>
  65. </scroll-view>
  66. <!-- 锚点定位 -->
  67. <view class="fixed-point" @touchmove="pointTouchmove">
  68. <view class="point-item" @click="pointClick" :id="'point-'+index" :style="{height: 100 / 26 +'%'}" v-for="(item, index) in point_list" :key="index">{{ item }}</view>
  69. </view>
  70. </view>
  71. <lf-tabbar></lf-tabbar>
  72. </view>
  73. </template>
  74. <script>
  75. import lfNav from '@/components/lf-nav/lf-nav.vue';
  76. import lfTabbar from '@/components/lf-tabbar/lf-tabbar.vue';
  77. import testdata from './testdata.js';
  78. let app = getApp();
  79. export default {
  80. data() {
  81. return {
  82. scrollH: 0,
  83. subItemW: 0,
  84. left_selectIndex: 0,
  85. right_selectIndex: 0,
  86. ttscrollH: 0, //总高度
  87. placeholderH: 0, //占位高度
  88. heighArr: [],
  89. dataArr: testdata,
  90. current: 1,
  91. nav_height: 0,
  92. tabs: [{
  93. name: '分类'
  94. },{
  95. name: '品牌'
  96. }],
  97. filter_active: '',
  98. point_list: [],
  99. scrollAnchorId: ''
  100. };
  101. },
  102. computed: {
  103. autoHeight(){
  104. return `calc(${this.scrollH}px - ${this.nav_height}px - 90rpx - 120rpx)`;
  105. },
  106. otherHeight(){
  107. // 屏幕可用总高度 - 导航条高度 - tabs高度 - tabbar高度 - 筛选高度
  108. return `calc(${this.scrollH}px - ${this.nav_height}px - 90rpx - 120rpx - 105rpx)`;
  109. }
  110. },
  111. components: {
  112. lfNav,
  113. lfTabbar
  114. },
  115. onLoad(options) {
  116. // https://ext.dcloud.net.cn/plugin?id=5031
  117. if(this.$isRight(options)){
  118. this.current = options.current || 1;
  119. this.left_selectIndex = options.type || 0;
  120. this.right_selectIndex = options.type || 0;
  121. }
  122. let info = uni.getSystemInfoSync();
  123. let self = this;
  124. self.scrollH = info.screenHeight;
  125. self.subItemW = parseInt((info.screenWidth * (2 / 3) - 15 * 2 - 24) / 3);
  126. setTimeout(function() {
  127. self.computerH();
  128. }, 100);
  129. this.createAtoZ();
  130. },
  131. methods: {
  132. // 生成A-Z的大写字母
  133. createAtoZ(){
  134. let point_list = [];
  135. for(var i=0; i<26; i++){
  136. point_list.push(String.fromCharCode(65+i));
  137. }
  138. this.point_list = point_list;
  139. },
  140. pointTouchmove(event){
  141. console.log(event);
  142. },
  143. pointClick(event){
  144. let index = (event.target.id).replace('point-', '');
  145. let letter = this.point_list[index];
  146. this.scrollAnchorId = '';
  147. this.$msg(letter);
  148. this.$nextTick(() => {
  149. this.scrollAnchorId = 'anchor-'+ index;
  150. })
  151. },
  152. leftTap: function(e) {
  153. this.left_selectIndex = e.index;
  154. this.right_selectIndex = e.index;
  155. },
  156. // 右边点击
  157. rightTap: function() {
  158. this.$msg('敬请期待')
  159. },
  160. rightScroll: function(e) {
  161. let scrollH = e.detail.scrollTop + 30;
  162. let cc = this.ttscrollH - this.scrollH;
  163. let a = 0;
  164. let findInx = this.heighArr.findIndex(function(itemH, i) {
  165. a = a + itemH;
  166. return a > scrollH;
  167. });
  168. // if (scrollH >= cc) {
  169. // return;
  170. // }
  171. this.left_selectIndex = findInx;
  172. },
  173. // 计算高度
  174. computerH: function() {
  175. this.ttscrollH = 0;
  176. for (let item of this.dataArr) {
  177. let title_lineH = 49; //rpx
  178. let subNum = item.subArr.length;
  179. let subImgH = this.subItemW; //rpx
  180. let subTitleH = 40; //rpx
  181. let rowSpecH = 8; //rpx
  182. let rowN = subNum % 3;
  183. let rowSpecNum = parseInt(subNum / 3) + parseInt(rowN > 0 ? 1 : 0);
  184. let totalRpx = title_lineH + (subImgH + subTitleH) * rowSpecNum + rowSpecH * (rowSpecNum - 1);
  185. this.heighArr.push(totalRpx);
  186. this.ttscrollH = this.ttscrollH + totalRpx;
  187. }
  188. // this.placeholderH = this.scrollH - this.heighArr[this.heighArr.length - 1];
  189. //以下方法也可以
  190. // let self=this
  191. // var selectorQuery = uni.createSelectorQuery()
  192. // selectorQuery.selectAll('.right_item').boundingClientRect(data => {
  193. // self.heighArr = data.map(item => {
  194. // return {
  195. // top: Math.round(item.top),
  196. // height: Math.round(item.height)
  197. // }
  198. // })
  199. // }).exec()
  200. // console.log('ttscrollH',this.$refs.left_0)
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .page {
  207. display: grid;
  208. grid-template-columns: 1fr 2fr;
  209. grid-template-rows: auto;
  210. position: absolute;
  211. left: 0rpx;
  212. right: 0rpx;
  213. overflow: hidden;
  214. box-sizing: border-box;
  215. }
  216. .left_view {
  217. background-color: #f4f8f8;
  218. position: relative;
  219. box-sizing: border-box;
  220. // 蒙版
  221. .seletItem {
  222. height: 98px;
  223. position: absolute;
  224. top: 0rpx;
  225. left: 0rpx;
  226. z-index: 10;
  227. right: 0rpx;
  228. // background-color: rgba(255, 255, 255, 0.3);
  229. transition: top 0.2s linear;
  230. display: flex;
  231. align-items: center;
  232. box-sizing: border-box;
  233. &::before {
  234. content: '';
  235. width: 6rpx;
  236. height: 60%;
  237. background-color: #15716E;
  238. left: 0rpx;
  239. }
  240. }
  241. .left_item {
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. height: 60px;
  246. margin-bottom: 0rpx;
  247. position: relative;
  248. font-size: 28rpx;
  249. box-sizing: border-box;
  250. color: #555555;
  251. }
  252. .left_item_s {
  253. background-color: #ffffff;
  254. color: #15716E;
  255. font-weight: bold;
  256. position: relative;
  257. box-sizing: border-box;
  258. }
  259. }
  260. .right_view {
  261. background-color: #ffffff;
  262. padding: 0rpx 12px;
  263. box-sizing: border-box;
  264. .right_item {
  265. .right_item_title {
  266. display: block;
  267. box-sizing: border-box;
  268. line-height: 49px;
  269. font-size: 28rpx;
  270. font-weight: bold;
  271. color: #15716E;
  272. }
  273. .right_item_view {
  274. display: grid;
  275. grid-template-columns: repeat(3, 1fr);
  276. grid-template-rows: auto;
  277. grid-gap: 8px 15px;
  278. box-sizing: border-box;
  279. .item {
  280. display: flex;
  281. flex-flow: column nowrap;
  282. align-items: center;
  283. box-sizing: border-box;
  284. text {
  285. color: #333;
  286. line-height: 40px;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. .tabs{
  293. width: 750rpx;
  294. height: 90rpx;
  295. display: flex;
  296. justify-content: space-between;
  297. border-bottom: 1rpx solid #e5e5e5;
  298. background-color: #FFFFFF;
  299. .lf-tab{
  300. // width: 50%;
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. font-size: 28rpx;
  305. color: #777777;
  306. position: relative;
  307. &.tab-active{
  308. color: #15716E;
  309. }
  310. &.tab-active::after{
  311. content: '';
  312. position: absolute;
  313. bottom: 0;
  314. left: 50%;
  315. width: 80rpx;
  316. height: 10rpx;
  317. background-color: #15716E;
  318. border-radius: 10rpx 10rpx 0 0;
  319. margin-left: -40rpx;
  320. }
  321. }
  322. }
  323. .lf-filter-box{
  324. height: 105rpx;
  325. width: 750rpx;
  326. background-color: #F4F8F8;
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. position: relative;
  331. .lf-filter{
  332. width: 300rpx;
  333. height: 65rpx;
  334. border-radius: 33rpx;
  335. border: 1rpx solid #15716E;
  336. color: #15716E;
  337. font-size: 24rpx;
  338. display: flex;
  339. align-items: center;
  340. justify-content: space-between;
  341. position: relative;
  342. overflow: hidden;
  343. &.lf-filter-after::after{
  344. content: '';
  345. position: absolute;
  346. top: 12rpx;
  347. left: calc(50% - 1rpx);
  348. width: 2rpx;
  349. height: 40rpx;
  350. background-color: #15716E;
  351. }
  352. &>view{
  353. height: 100%;
  354. width: 50%;
  355. display: flex;
  356. justify-content: space-around;
  357. align-items: center;
  358. }
  359. .filter-active{
  360. background-color: #15716E;
  361. color: #FFFFFF;
  362. }
  363. }
  364. .filter-modal-mask{
  365. position: absolute;
  366. top: 105rpx;
  367. left: 0;
  368. width: 100%;
  369. background-color: rgba(0,0,0,0.5);
  370. .filter-modal{
  371. width: 750rpx;
  372. height: max-content;
  373. padding: 60rpx 32rpx;
  374. box-sizing: border-box;
  375. background-color: #FFFFFF;
  376. display: flex;
  377. flex-wrap: wrap;
  378. position: relative;
  379. z-index: 1;
  380. .filter-item{
  381. width: 215rpx;
  382. height: 65rpx;
  383. border-radius: 10rpx;
  384. border: 1rpx solid #555555;
  385. display: flex;
  386. justify-content: center;
  387. align-items: center;
  388. font-size: 28rpx;
  389. color: #555555;
  390. margin-right: 21rpx;
  391. &:nth-child(3n){
  392. margin-right: 0rpx;
  393. }
  394. &:nth-child(n+4){
  395. margin-top: 21rpx;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. .brand-scroll{
  402. padding: 0rpx 32rpx;
  403. box-sizing: border-box;
  404. width: 750rpx;
  405. .brand-item{
  406. margin-bottom: 60rpx;
  407. &:nth-child(1n){
  408. margin-top: 30rpx;
  409. }
  410. }
  411. .img{
  412. width: 150rpx;
  413. height: 150rpx;
  414. border-radius: 4rpx;
  415. margin-right: 20rpx;
  416. }
  417. .info{
  418. width: 514rpx;
  419. height: 150rpx;
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: space-between;
  423. }
  424. }
  425. .brand{
  426. position: relative;
  427. }
  428. .fixed-point{
  429. position: fixed;
  430. right: 0;
  431. top: 18vh;
  432. height: 70vh;
  433. width: 57rpx;
  434. background-color: rgba(0,0,0,0.3);
  435. border-radius: 30rpx 0rpx 0rpx 30rpx;
  436. padding: 14rpx 0rpx;
  437. z-index: 2;
  438. .point-item{
  439. font-size: 24rpx;
  440. color: #FFFFFF;
  441. text-align: center;
  442. }
  443. }
  444. </style>