Home.vue 10 KB

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