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

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