king
2018-09-29 31573a0912c1971a9043b3f9294f643c7d60a2aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
<template>
  <div class="goods">
    <header-line-component v-if="header === 'discover'"></header-line-component>
    <div class="weui-search-bar weui-search-bar_focusing" id="searchBar" v-if="header === 'search'">
      <a href="javascript:" class="back" @click="jumpBack()"><i class="fa fa-angle-left"></i></a>
      <form class="weui-search-bar__form">
        <div class="weui-search-bar__box">
          <i class="weui-icon-search"></i>
          <input type="search" class="weui-search-bar__input" id="searchInput" @focus="isseeking = true" @blur="isseeking = false">
          <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
        </div>
      </form>
      <a href="javascript:" class="weui-search-bar__confirm-btn">{{dict.search}}</a>
    </div>
    <div class="recommends" v-if="isseeking">
      <h4>{{dict.recommend}}</h4>
      <div class="recommend-box">
        <span class="recommend-item" v-for="item in recommends" :key="item.id">{{item.name}}</span>
      </div>
    </div>
    <tab-component class="border-bottom-5" v-if="!isseeking" :tabs="navList" @tabchange="tabChange"></tab-component>
    <goods-list-component v-if="!isseeking && goods" :goods="goods" @goodslistjump="jumpmenu"></goods-list-component>
    <bottom-line-component v-if="!isseeking && bottomtip" :message="bottomtip"></bottom-line-component>
  </div>
</template>
 
<script>
import {dict} from '../store/dictionary'
import {goodsData} from '../store/mockdata'
import goodsListComponent from '../components/goodsListComponent'
import headerLineComponent from '../components/headerLineComponent'
import bottomLineComponent from '../components/bottomLineComponent'
import tabComponent from '../components/tabComponent'
export default {
  name: 'goods',
  components: { goodsListComponent, tabComponent, headerLineComponent, bottomLineComponent },
  data () {
    return {
      dict: dict, // 字典表翻译
      isseeking: false, // 是否为搜索状态
      recommends: null, // 推荐信息
      header: 'search', // 顶部默认为搜索,可选为“发现”类
      // tab类型切换,默认为综合、销量、价格
      navList: [
        {
          name: dict.synthesis,
          active: true,
          type: 'synthesis'
        },
        {
          name: dict.sales_volume,
          active: false,
          type: 'sales'
        },
        {
          name: dict.price,
          active: false,
          type: 'price'
        }
      ],
      goods: null, // 商品列表
      type: null, // 从其他界面传递过来的搜索类型
      bottomtip: null // 底部提示信息
    }
  },
  methods: {
    /**
     * @description 搜索行返回按钮,返回上一个界面
    */
    jumpBack () {
      this.$router.back(-1)
    },
    /**
     * @description 类型切换,从组件中获取当前类型并更新数据
    */
    tabChange (message) {
      console.log(message.value)
      this.goods = null
      this.bottomtip = null
      setTimeout(() => {
        this.goods = JSON.parse(JSON.stringify(goodsData.goods))
        this.bottomtip = dict.bottomtip
      }, 1000)
    },
    /**
     * @description 点击商品时页面跳转
     */
    jumpmenu (message) {
      this.$router.push({name: message.view, params: {id: message.id}})
    }
  },
  mounted: function () {
    let currentType = this.navList.find((item) => {
      return item.active
    })
    console.log(currentType)
    setTimeout(() => {
      this.goods = JSON.parse(JSON.stringify(goodsData.goods))
      this.recommends = JSON.parse(JSON.stringify(goodsData.recommends))
      this.bottomtip = dict.bottomtip
    }, 1000)
    this.type = this.$route.params.type
    console.log(this.type)
    // 获取参数信息,控制头部为搜索框或提示
    if (this.$route.params.header) {
      this.header = this.$route.params.header
    }
    // 当页面从首页搜索跳转,搜索框获取焦点
    if (this.$route.params.header === 'search') {
      $('#searchInput').focus()
    }
  }
}
</script>
 
<style scoped>
.back {
  display: inline-block;
  font-size: 30px;
  padding: 0 10px;
  line-height: 28px;
  color: #bbbbbb;
}
.weui-search-bar {
  top: 0px;
  width: 100%;
  max-width: 41.2rem;
  padding: 8px 10px 8px 0px;
  background: #ffffff;
}
.weui-search-bar:before {
  border: none;
}
.weui-search-bar__form {
  background: transparent;
}
.weui-search-bar__form:after {
  border-radius: 10px;
}
.weui-search-bar__label {
  border-radius: 20px;
}
.weui-search-bar__box .weui-search-bar__input{
  height: 1.6em;
  line-height: 1.6em;
}
.weui-search-bar__confirm-btn {
  display: block;
  margin-left: 10px;
  line-height: 28px;
  color: #000000;
  white-space: nowrap;
}
.recommends h4 {
  padding: 20px 0px 10px 12px;
}
.recommends .recommend-box {
  padding: 0px 10px;
}
.recommends .recommend-box .recommend-item {
  display: inline-block;
  font-size: 14px;
  padding: 0px 10px;
  background: #eeeeee;
  border-radius: 5px;
  margin: 5px 2px;
}
</style>