Home.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div class="home">
  3. <div class="mobile-modal" v-if="showStoreInfo">
  4. <div class="mobile-modal-box">
  5. <div class="mobile-modal-header">联系方式<i @click="showStoreInfo = false" class="icon-guanbi iconfont"></i></div>
  6. <div class="mobile-modal-content">
  7. <div>商家地址:深圳市南山区英唐大厦6楼</div>
  8. <div class="content-line link-url">在线咨询</div>
  9. <div>致电:<span class="content-line link-url">0755-96586323</span></div>
  10. </div>
  11. </div>
  12. </div>
  13. <div class="home-header">
  14. <div class="home-search">
  15. <ul>
  16. <li :class="activeType=='model'?'active':''" @click="activeType='model'"><span>型号</span></li>
  17. <li :class="activeType=='brand'?'active':''" @click="activeType='brand'"><span>品牌</span></li>
  18. <li :class="activeType=='shops'?'active':''" @click="activeType='shops'"><span>商家</span></li>
  19. </ul>
  20. <div class="home-input">
  21. <input type="text" placeholder="请输入您要查找的型号、品牌或商家" v-model="keyword"
  22. @focus.stop.prevent="onFocus()"/>
  23. <span @click="onSearch()"><i class="iconfont icon-sousuo"></i></span>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="home-main">
  28. <a class="home-main-content">
  29. <div>
  30. <img src="/images/mobile/@2x/home/brand@2x.png" alt="1">
  31. </div>
  32. <h2>
  33. {{numbrand[0]}}
  34. </h2>
  35. <p>品牌</p>
  36. </a>
  37. <a class="home-main-content">
  38. <div>
  39. <img src="/images/mobile/@2x/home/modelbrand@2x.png" alt="1">
  40. </div>
  41. <h2>
  42. {{numbrand[1]}}
  43. </h2>
  44. <p>型号</p>
  45. </a>
  46. <a class="home-main-content">
  47. <div>
  48. <img src="/images/mobile/@2x/home/bookbrand@2x.png">
  49. </div>
  50. <h2>
  51. {{numbrand[2]}}
  52. </h2>
  53. <p>规格书</p>
  54. </a>
  55. <nuxt-link to="/mobile/shop" class="home-main-content">
  56. <div>
  57. <img src="/images/mobile/@2x/home/shopbrand@2x.png">
  58. </div>
  59. <p>店铺列表</p>
  60. </nuxt-link>
  61. <nuxt-link to="/mobile/user" class="home-main-content">
  62. <div>
  63. <img src="/images/mobile/@2x/home/storebrand@2x.png">
  64. </div>
  65. <p>我的收藏</p>
  66. </nuxt-link>
  67. <a @click="showStoreInfo = true" class="home-main-content">
  68. <div>
  69. <img src="/images/mobile/@2x/home/phonebrand@2x.png">
  70. </div>
  71. <p>联系我们</p>
  72. </a>
  73. </div>
  74. <div class="home-search-list" v-if="associate && keyword">
  75. <div>
  76. <div class="search-list-top">
  77. <h5>历史搜索:<i class="iconfont icon-delete"></i></h5>
  78. <div class="search-list-item">
  79. <a href="#">smk212121288</a>
  80. <a href="#">CPU</a>
  81. <a href="#">CPU</a>
  82. <a href="#">CPU</a>
  83. <a href="#">CPU</a>
  84. <a href="#">CPU</a>
  85. </div>
  86. </div>
  87. <div class="search-list-bottom">
  88. <h5><i class="iconfont icon-remensousuo"></i>热搜器件</h5>
  89. <span v-for="item in hotwords">
  90. <nuxt-link :to="item.url" >{{item.name}}</nuxt-link>
  91. </span>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </template>
  97. <script>
  98. export default {
  99. name: 'home',
  100. data () {
  101. return {
  102. keyword: '',
  103. activeType: 'model',
  104. associate: '',
  105. showStoreInfo: false,
  106. isMore: false,
  107. isShow: false,
  108. len: 0
  109. }
  110. },
  111. props: {
  112. hotwords: {
  113. type: Array,
  114. default () {
  115. return [
  116. {name: 'SCT2080KEC', url: '/mobile/brand/componentDetail/1100400300009990'},
  117. {name: 'Vishay', url: '/mobile/brand/30327265e42a871be050007f01003d96'},
  118. {name: 'Panasonic', url: '/mobile/brand/30327265e47d871be050007f01003d96'}
  119. ]
  120. }
  121. }
  122. },
  123. methods: {
  124. onFocus () {
  125. this.associate = true
  126. },
  127. onSearch () {
  128. if (this.keyword) {
  129. this.$router.push({path: '/mobile/search?w=' + encodeURIComponent(this.keyword)})
  130. }
  131. },
  132. matNumber (num) {
  133. // let re = /(\d+)(\d{3})/
  134. if (num > 99999999) {
  135. this.isShow = true
  136. let str2 = num.toString()
  137. num = Math.floor(num / 100000000)
  138. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  139. num = num + 1
  140. }
  141. num += '亿'
  142. }
  143. if (num > 9999) {
  144. this.isMore = true
  145. let str = num.toString()
  146. num = Math.floor(num / 10000)
  147. if (parseInt(str.charAt(str.length - 4)) > 4) {
  148. num = num + 1
  149. }
  150. num += '万'
  151. } else {
  152. num += '个'
  153. }
  154. // let length = String(num).length
  155. // this.len = length > 3 ? length + 1 : length
  156. // num = (Array(7 - length).join(0) + num)
  157. // while (re.test(num)) {
  158. // num = num.replace(re, '$1,$2')
  159. // }
  160. // num = num.split('')
  161. return num
  162. },
  163. forNum (numbers) {
  164. let num = []
  165. for (let i = 0; i < numbers.length; i++) {
  166. num.push(this.matNumber(numbers[i].count))
  167. }
  168. return num
  169. },
  170. loadCounts () {
  171. this.$store.dispatch('loadProductCounts', { _status: 'actived' })
  172. }
  173. },
  174. created () {
  175. this.$store.dispatch('resetSearchKeywords')
  176. },
  177. mounted () {
  178. this.$nextTick(() => {
  179. setInterval(() => {
  180. this.loadCounts()
  181. }, 30000)
  182. })
  183. },
  184. computed: {
  185. numbrand () {
  186. return this.forNum(this.counts)
  187. },
  188. counts () {
  189. return this.$store.state.product.common.counts.data
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. @import '~assets/scss/mobileCommon';
  196. .home{
  197. margin-top: .88rem;
  198. font-size:.28rem;
  199. background: #f7fbff;
  200. margin-bottom:1rem;
  201. .home-header{
  202. width:100%;
  203. height:6.12rem;
  204. background:url('/images/mobile/@2x/home/background@2x.png')no-repeat;
  205. background-size: 100% 6.14rem;
  206. padding-bottom:1rem;
  207. .home-search{
  208. width:6rem;
  209. line-height: .3rem;
  210. margin:0 auto;
  211. padding-top:2rem;
  212. ul{
  213. display:inline-flex;
  214. li{
  215. flex:1;
  216. text-align:center;
  217. >span{
  218. display:inline-block;
  219. width:.72rem;
  220. line-height:.33rem;
  221. height:.33rem;
  222. background: #fff;
  223. color:#000;
  224. border-radius: .05rem .05rem 0 0 ;
  225. }
  226. }
  227. li.active span{
  228. background: #3c7cf5;
  229. color:#fff;
  230. cursor:pointer;
  231. }
  232. }
  233. .home-input{
  234. input{
  235. width:6rem;
  236. padding: 0 1.2rem 0 .16rem;
  237. margin-right:-1rem;
  238. font-size:.24rem;
  239. line-height: .64rem;
  240. border:.02rem solid #3c7cf5;
  241. border-radius:.05rem;
  242. }
  243. span{
  244. display:inline-block;
  245. text-align: center;
  246. width:1rem;
  247. height:.65rem;
  248. line-height: .64rem;
  249. font-size:.23rem;
  250. border-left:none;
  251. border-radius: 0 .05rem .05rem 0;
  252. background: #3c7cf5;
  253. color:#fff;
  254. i{
  255. font-size: .33rem;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. .home-main{
  263. width:100%;
  264. display:flex;
  265. justify-content:space-between;
  266. flex-wrap:wrap;
  267. text-align: center;
  268. padding-top:.22rem;
  269. }
  270. .home-main a.home-main-content {
  271. width:33%;
  272. margin-bottom:.52rem;
  273. }
  274. .home-main .home-main-content div{
  275. border-radius: .2rem;
  276. width:1.14rem;
  277. height:1.14rem;
  278. margin:0 auto;
  279. }
  280. .home-main .home-main-content div>img{
  281. width: 100%;
  282. height:100%;
  283. }
  284. .home-main .home-main-content p{
  285. font-size:.28rem;
  286. color:rgb(51,51,51);
  287. line-height: .52rem;
  288. }
  289. .home-main .home-main-content h2{
  290. font-size:.3rem;
  291. color:#ff7800;
  292. line-height: .32rem;
  293. margin:0;
  294. margin-top:.1rem;
  295. }
  296. /* 搜索记录 */
  297. .home-search-list {
  298. position:absolute;
  299. top:6.5rem;
  300. width:100%;
  301. min-height: 4rem;
  302. background: #fff;
  303. }
  304. .home-search-list div{
  305. width:6.55rem;
  306. margin:0 auto;
  307. margin-top:.1rem;
  308. padding-bottom:.2rem;
  309. .search-list-top{
  310. h5{
  311. font-size:.3rem;
  312. position:relative;
  313. line-height: .4rem;
  314. color:rgb(102,102,102);
  315. i{
  316. position:absolute;
  317. right:.2rem;
  318. top:.1rem;
  319. color:#4f8afb;
  320. font-size: .35rem;
  321. }
  322. }
  323. .search-list-item{
  324. a{
  325. display:inline-block;
  326. font-size:.28rem;
  327. line-height: .45rem;
  328. color:rgb(102,102,102);
  329. background: #fff;
  330. padding:0 .1rem;
  331. width:2.18rem;
  332. overflow:hidden;
  333. text-overflow : ellipsis;
  334. &:nth-child(2){
  335. border-left:1px solid #a5a6a6;
  336. border-right:1px solid #a5a6a6;
  337. text-align: center;
  338. }
  339. &:nth-child(5){
  340. border-left:1px solid #a5a6a6;
  341. border-right:1px solid #a5a6a6;
  342. text-align: center;
  343. }
  344. }
  345. }
  346. }
  347. .search-list-bottom{
  348. margin-top:-.07rem;
  349. h5{
  350. color:rgb(255,120,0);
  351. font-size:.3rem;
  352. text-align: center;
  353. i{
  354. margin-right:.15rem;
  355. }
  356. }
  357. a{
  358. display:inline-block;
  359. font-size:.24rem;
  360. color:rgb(255,120,0);
  361. background: #fff;
  362. max-width:1.62rem;
  363. line-height: .35rem;
  364. padding:0 .1rem;
  365. border:1px solid rgb(255,120,0);
  366. overflow:hidden;
  367. text-overflow : ellipsis;
  368. margin-left:.12rem;
  369. }
  370. }
  371. }
  372. </style>