| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550 |
- <template>
-
- <view class="menuBox">
- <view class="menuContent">
- <scroll-view scroll-y="true" class="menuLeft">
- <view class="menuType" @click="changeCurrent(index)" v-for="(item,index) in prdList"
- :class="{currentMenu:currentIndex==index}">
- <text class="text2row">{{item.name}}</text>
- </view>
- <view class="line" :style="{top:currentIndex*100 +'rpx'}"></view>
- </scroll-view>
-
- <scroll-view :scroll-top="scrollTop" @scroll="scrollRight" class="menuRight" scroll-y="true">
- <div class="menuDetailBox" v-for="(item,index) in prdList" :key="index">
- <div class="title">{{item.name}}</div>
- <div class="menu" v-for="(menu,index) in item.children" :key="index">
- <div class="d2">
- <netImage style="margin-top: 10rpx;" width="180" height="180" :mysrc="menu.image" mymode="scaleToFill"></netImage>
- </div>
- <div class="menuName">
- <view class="contentColumnS" style="height: 200rpx;">
- <view class="contentColumn" style="width: 100%;">
- <text class="pdName text2row">{{menu.name}}</text>
- <text class="pdDetail text1row">{{menu.name}}</text>
- </view>
- <view class="contentColumn" style="width: 100%;">
- <view class="contentInRowL">
- <text class="redktext">特价</text>
- <text class="greedKtext" style="margin-left: 10rpx;">24H发货</text>
- </view>
- <view class="contentInRowS">
- <view class="">
- <text class="pricetext">123.32</text>
- <text class="pricedw">{{$t("locale.huobidw")}}</text>
- <text class="yuanjia">155.32{{$t("locale.huobidw")}}</text>
- </view>
- <image style="width: 50rpx;height: 50rpx;margin-bottom: 6rpx;" src="/static/meishi/BuyS.png" mode=""></image>
- </view>
- </view>
- </view>
-
- </div>
- </div>
- </div>
- </scroll-view>
- </view>
- </view>
- </template>
-
- <script>
- import api from "@/pages/api/api.js";
- export default {
- data() {
- return {
- newData:[], // 拿到右侧所有的商品列表元素
- scrollTop: 0,
- currentIndex: 0,
- lang:'3',
- id:'',
- shangpinfenlei:[],
- prdList:[],
- menuList: [{
- "id": 1,
- "name": "手机数码",
- "children": [{
- "id": 101,
- "name": "手机"
- },
- {
- "id": 105,
- "name": "数码相机"
- }
- ]
- },
- {
- "id": 2,
- "name": "家用电器",
- "children": [{
- "id": 201,
- "name": "电视机"
- },
- {
- "id": 204,
- "name": "冰箱"
- },
- {
- "id": 205,
- "name": "吸尘器"
- }
- ]
- },
- {
- "id": 3,
- "name": "服饰鞋包",
- "children": [{
- "id": 301,
- "name": "男装"
- },
- {
- "id": 302,
- "name": "女装"
- },
- {
- "id": 303,
- "name": "运动鞋"
- },
- {
- "id": 304,
- "name": "箱包"
- },
- {
- "id": 305,
- "name": "配饰"
- }
- ]
- },
- {
- "id": 4,
- "name": "美妆个护",
- "children": [{
- "id": 401,
- "name": "面部护肤"
- },
- {
- "id": 402,
- "name": "彩妆"
- },
- {
- "id": 403,
- "name": "洗发护发"
- },
- {
- "id": 404,
- "name": "身体护理"
- },
- {
- "id": 405,
- "name": "香水"
- }
- ]
- },
- {
- "id": 5,
- "name": "母婴玩具",
- "children": [{
- "id": 501,
- "name": "奶粉"
- },
- {
- "id": 502,
- "name": "尿不湿"
- },
- {
- "id": 503,
- "name": "婴儿用品"
- },
- {
- "id": 504,
- "name": "儿童玩具"
- },
- {
- "id": 505,
- "name": "孕妇用品"
- }
- ]
- },
- {
- "id": 6,
- "name": "食品饮料",
- "children": [{
- "id": 601,
- "name": "休闲零食"
- },
- {
- "id": 602,
- "name": "粮油调味"
- },
- {
- "id": 603,
- "name": "饮料酒水"
- },
- {
- "id": 604,
- "name": "冲调速食"
- },
- {
- "id": 605,
- "name": "生鲜水果"
- }
- ]
- },
- {
- "id": 7,
- "name": "家居家装",
- "children": [{
- "id": 701,
- "name": "家具"
- },
- {
- "id": 702,
- "name": "灯具"
- },
- {
- "id": 703,
- "name": "床上用品"
- },
- {
- "id": 704,
- "name": "厨房用品"
- },
- {
- "id": 705,
- "name": "装饰摆件"
- }
- ]
- },
- {
- "id": 8,
- "name": "运动户外",
- "children": [{
- "id": 801,
- "name": "跑步装备"
- },
- {
- "id": 802,
- "name": "健身器材"
- },
- {
- "id": 803,
- "name": "户外鞋服"
- },
- {
- "id": 804,
- "name": "骑行装备"
- },
- {
- "id": 805,
- "name": "垂钓用品"
- }
- ]
- },
- {
- "id": 9,
- "name": "汽车用品",
- "children": [{
- "id": 901,
- "name": "机油"
- },
- {
- "id": 902,
- "name": "轮胎"
- },
- {
- "id": 903,
- "name": "车载电器"
- },
- {
- "id": 904,
- "name": "清洁用品"
- },
- {
- "id": 905,
- "name": "维修配件"
- }
- ]
- },
- {
- "id": 10,
- "name": "图书文娱",
- "children": [{
- "id": 1001,
- "name": "文学小说"
- },
- {
- "id": 1002,
- "name": "少儿读物"
- },
- {
- "id": 1003,
- "name": "教育考试"
- },
- {
- "id": 1004,
- "name": "艺术设计"
- },
- {
- "id": 1005,
- "name": "音像制品"
- }
- ]
- }
- ]
-
- }
- },
- onLoad(option) {
- this.id=option.id;
- var language = uni.getStorageSync('language');
- if(language=='yuenan'){
- this.lang='0';
- }
- if(language=='zh-Hans'){
- this.lang='2';
- }
- if(language=='zh-Hant'){
- this.lang='3';
- }
- this.getmendianshangpinFL(this.id);
- },
- onReady() {
- uni.setNavigationBarTitle({
- title: '你好'
- })
-
- },
- methods: {
- changeCurrent(index) {
- this.currentIndex = index
- this.scrollTop = this.newData[index-1]?.offsetHeight || 0
- },
- scrollRight(e) {
- // console.log(e.detail.scrollTop,'scrollRight');
- const query = uni.createSelectorQuery().in(this);
- for (let i = 0; i < this.newData.length; i++) {
- let el = this.newData[i]
- if (e.detail.scrollTop < el.offsetHeight) {
- this.currentIndex = i
- return true
- }
- }
- },
- getmendianshangpinFL(id){
- uni.showLoading({
- mask:true
- })
- api('getmendianshangpinFL',{
- id:id,
- language:this.lang
- },res=>{
- uni.hideLoading();
- this.shangpinfenlei=res.data.data;
- console.log(this.shangpinfenlei)
- this.initFenlei();
- },failc=>{
- uni.hideLoading();
- //console.log('getadvertis----',failc)
- })
- },
- initFenlei(){
- this.prdList=[];
- if(this.shangpinfenlei&&this.shangpinfenlei.length>0){
- for (var i = 0; i < this.shangpinfenlei.length; i++) {
- var el = this.shangpinfenlei[i];
- var temp = {
- "id": el.id,
- "index": i+1,
- "name": el.name,
- "children": [
- ]
- }
- this.prdList.push(temp);
- }
- }
- this.initproduct();
- },
- initproduct(){
- if(this.prdList.length==0){
- return;
- }
- this.getmendianshangpinList(0);
-
- },
- getmendianshangpinList(index){
-
- var obj = this.prdList[index];
-
- api('getmendianshangpinList',{
- id:obj.id,
- language:this.lang
- },r=>{
- console.log(r);
- this.prdList[index].children=r.data.data;
- if(index+1<this.prdList.length){
- this.getmendianshangpinList(index+1);
- }
- else{
- console.log(this.prdList);
- this.initNewData();
- }
- },failc=>{
-
- //console.log('getadvertis----',failc)
- })
- },
- initNewData(){
- const query = uni.createSelectorQuery().in(this);
- query.selectAll('.menuDetailBox').boundingClientRect(data => {
- console.log('所有分类项:', data);
- this.newData = data.map((item, index) => {
- function fgfg(total) {
- let sum = 0
- for (var i = 0; i <= total; i++) {
- sum += data[i].height
- }
- return sum
- }
- item.offsetHeight = fgfg(index)
- return item
- })
-
- }).exec();
- },
- },
-
- }
- </script>
-
- <style lang="scss" scoped>
- .menuBox {
- height: calc(100vh);
- display: flex;
- flex-direction: column;
- // border: 1px solid #ccc;
- margin: 0 10rpx;
- .menuContent {
- // height: calc(100vh);
- overflow: auto;
- position: relative;
- display: flex;
- position: sticky;
- top: 0rpx;
- .menuLeft {
- float: left;
- position: relative;
- width: 200rpx;
- background-color: #f5f5f5;
-
- .menuType {
- transition: all 0.4s;
- position: relative;
- z-index: 999999999;
- height: 100rpx;
- display: flex;
- align-items: center;
- padding-left: 20rpx;
-
- &.currentMenu {
- font-weight: 700;
- }
- }
-
- }
-
- .menuRight {
- flex: 1;
- background-color:lavender;
-
- .menuDetailBox {
- .title {
- height: 60rpx;
- display: flex;
- align-items: center;
- }
-
- .menu {
- background-color: #fff;
- height: 200rpx;
- display: flex;
- justify-content: center;
-
- &:not(:nth-last-of-type(1)) {
- margin-bottom: 20rpx;
- }
-
- .d2 {
- width: 180rpx;
- height: 180rpx;
- }
-
- .menuName {
- flex: 1;
- margin-left: 20rpx;
- }
-
- }
- }
- }
- }
- }
-
- .line {
- position: absolute;
- left: 0;
- top: 0;
- height: 100rpx;
- width: 100%;
- background-color: #fff;
- z-index: 999;
- transition: all 0.4s;
-
- &::before {
- content: '';
- position: absolute;
- left: 0;
- top: 0;
- height: 100rpx;
- width: 4rpx;
- background-color: red;
- z-index: 999;
- transition: all 0.4s
- }
- }
-
- .pdName{
- font-size: 30rpx;
- font-weight: bold;
- color: black;
- }
- .pdDetail{
- font-size: 26rpx;
- color: darkgray;
- }
- .redktext{
- color: brown;
- border-radius: 4rpx;
- border: 1px solid brown;
- font-size: 26rpx;
- }
- .greedKtext{
- color: darkgreen;
- border-radius: 4rpx;
- border: 1px solid darkgreen;
- font-size: 26rpx;
- }
- .pricetext{
- color: firebrick;
- font-size: 28rpx;
- font-weight: bold;
- }
- .pricedw{
- font-size: 24rpx;
- color: darkgray;
- }
- .yuanjia{
- font-size: 24rpx;
- color: darkgray;
- text-decoration: line-through;
- }
-
- </style>
|