index.vue 6.5 KB
Newer Older
sin's avatar
sin committed
1 2 3
<template>
    <div>
        <van-search
4
        v-model="keyword"
sin's avatar
sin committed
5 6 7 8
        placeholder="请输入搜索关键词"
        show-action
        @search="onSearch"
        >
9
            <div slot="action" @click="onSearch">搜索</div>
sin's avatar
sin committed
10 11
        </van-search>
        <van-badge-group :active-key="activeKey" class="tab" :style="'height:'+fullHeight+'px'">
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
            <!--<van-badge title="热门推荐" @click="onClick" />-->
            <!--<van-badge title="手机数码" @click="onClick" />-->
            <!--<van-badge title="家用电器" @click="onClick" />-->
            <!--<van-badge title="电脑办公" @click="onClick" />-->
            <!--<van-badge title="美妆护肤" @click="onClick" />-->
            <!--<van-badge title="个护清洁" @click="onClick" />-->
            <!--<van-badge title="汽车用品" @click="onClick" />-->
            <!--<van-badge title="男装" @click="onClick" />-->
            <!--<van-badge title="男鞋" @click="onClick" />-->
            <!--<van-badge title="女装" @click="onClick" />-->
            <!--<van-badge title="女鞋" @click="onClick" />-->
            <!--<van-badge title="母婴童装" @click="onClick" />-->
            <!--<van-badge title="图书音像" @click="onClick" />-->
            <!--<van-badge title="运动户外" @click="onClick" />-->
            <van-badge v-for="category in rootCategories" :title="category.name" @click="onClick" />
sin's avatar
sin committed
27 28
        </van-badge-group>
        <div class="content" :style="'width:'+fullWidth+'px;height:'+(fullHeight-7)+'px'" >
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
            <!-- TODO 营销活动,暂时注释掉 -->
            <!--<img src="https://img11.360buyimg.com/mcoss/jfs/t1/1072/23/3672/95463/5b9a0813E175891fa/e38fc2f7c2ddfec2.jpg" />-->
            <!-- TODO 常用分类,暂时注释掉 -->
            <!--<div class="category-div">-->
                <!--<h4>常用分类</h4>-->
                <!--<ul >-->
                    <!--<li>-->
                      <!--<router-link to="/search?keyword=xxxx">-->
                        <!--<img src="//img12.360buyimg.com/focus/jfs/t11824/150/2263801190/3392/8e69e1b3/5a167b8cNdcf71ae5.jpg">-->
                        <!--<span>蓝牙耳机</span>-->
                      <!--</router-link>-->
                    <!--</li>-->
                    <!--<li>-->
                        <!--<a >-->
                            <!--<img src="//img20.360buyimg.com/focus/jfs/t13759/194/897734755/2493/1305d4c4/5a1692ebN8ae73077.jpg">-->
                            <!--<span>iPhone</span>-->
                        <!--</a>-->
                    <!--</li>-->
                    <!--<div style="clear:both"></div>-->
                <!--</ul>-->
            <!--</div>-->
sin's avatar
sin committed
50
            <div class="category-div">
51 52 53
                <!--<h4>热门分类</h4>-->
                <ul>
                    <li v-for="category in childCategories">
54
                        <router-link :to="'/products/list?title=' + activeCategory.name + '&cidFirst=' + activeCategory.id + '&cidSecond=' + category.id">
55 56
                            <img :src="category.picUrl" />
                            <span>{{ category.name }}</span>
57
                        </router-link>
sin's avatar
sin committed
58 59 60
                    </li>
                    <div style="clear:both">
                    </div>
61
                </ul>
sin's avatar
sin committed
62 63 64 65 66 67 68 69
            </div>
        </div>
        <navigate />
    </div>
</template>

<script>
import { Search } from "vant";
70 71
// import { GetAddressById } from '../../api/user';
import { getProductCategoryList } from '../../api/product';
sin's avatar
sin committed
72 73 74 75 76 77 78 79

export default {
  name: "userindex",
  components: {
    [Search.name]: Search
  },
  data() {
    return {
80
      keyword: "",
81 82
      rootCategories: [],
      childCategories: [],
sin's avatar
sin committed
83
      activeKey: 0,
84
      activeCategory: {}, // 选中的分类
sin's avatar
sin committed
85 86 87 88 89 90
      fullHeight: document.documentElement.clientHeight - 93,
      fullWidth: document.documentElement.clientWidth - 99
    };
  },
  methods: {
    onSearch() {
91 92
      // debugger;
      // GetAddressById(1);
93 94 95 96
      // console.log(this.value);
      this.$router.push(
        {name: '/product/search', params: {keyword: this.keyword}}
      )
sin's avatar
sin committed
97 98
    },
    onClick(key) {
99 100 101
      // debugger;
      // GetAddressById(1);
      // 设置 activeKey
sin's avatar
sin committed
102
      this.activeKey = key;
103 104
      // 读取子节点的分类
      if (this.rootCategories.length > key) {
105 106
        this.activeCategory = this.rootCategories[key];
        let response = getProductCategoryList(this.activeCategory.id);
107 108 109 110
        response.then(data => {
          this.childCategories = data;
        });
      }
sin's avatar
sin committed
111
    }
112 113 114 115 116 117 118 119 120 121
  },
  mounted() {
    let response = getProductCategoryList(0);
    response.then(data => {
      // console.log(data);
      // debugger;
      // 设置根节点的分类
      this.rootCategories = data;
      // 获得首个根节点的分类
      if (data && data.length > 0) {
122
        this.activeCategory = data[0];
123 124 125 126 127 128
        let response = getProductCategoryList(data[0].id);
        response.then(data => {
          this.childCategories = data;
        });
      }
    });
sin's avatar
sin committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  }
};
</script>

<style lang="less">
.tab {
  float: left;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
  .van-badge {
    padding: 15px 12px 15px 9px;
  }
  .van-badge:not(:last-child)::after {
    height: 199%;
  }
}
.content {
  float: left;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
  margin: 7px 7px 0;
  font-size: 12px;
  img {
    width: 100%;
  }
  .category-div {
    margin: 19px 0px 0;
    h4 {
      font-size: 14px;
      color: #333;
    }
    ul{
        margin-top: 10px;
    }
    li {
      width: 32.8%;
      float: left;
      text-align: center;
      img {
        width: 60px;
        height: 60px;
      }
      span{
          font-size: 12px;
    height: 36px;
    color: #686868;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: box;
    display: -webkit-box;
    display: -moz-box;
    display: -ms-box;
    display: -o-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -moz-line-clamp: 2;
    -ms-line-clamp: 2;
    -o-line-clamp: 2;
    box-orient: vertical;
    -webkit-box-orient: vertical;
    -ms-box-orient: vertical;
    -o-box-orient: vertical;
    word-break: break-all;
    box-align: center;
    -webkit-box-align: center;
    -moz-box-align: center;
    -ms-box-align: center;
    -o-box-align: center;
    box-pack: center;
    -webkit-box-pack: center;
    -moz-box-pack: center;
    -ms-box-pack: center;
    -o-box-pack: center;
    z-index: 2;
    position: relative;
      }
    }
  }
}
</style>