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

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