Home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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>致电:<a href="tel:0755-96586323" class="content-line link-url">0755-96586323</a></div>
  10. <div>邮件:<a href="mailto:yrsc@usoftchina.com" class="content-line link-url">yrsc@usoftchina.com</a></div>
  11. </div>
  12. </div>
  13. </div>
  14. <div v-if="!showMainSearch">
  15. <div class="home-header" :style="'background:url(' + bgUrl + ')no-repeat center center/100% 6.14rem'">
  16. <div class="home-search">
  17. <!--<ul>-->
  18. <!--<li :class="activeType=='model'?'active':''" @click="activeType='model'"><span>型号</span></li>-->
  19. <!--<li :class="activeType=='brand'?'active':''" @click="activeType='brand'"><span>品牌</span></li>-->
  20. <!--<li :class="activeType=='shops'?'active':''" @click="activeType='shops'"><span>商家</span></li>-->
  21. <!--</ul>-->
  22. <div class="home-input">
  23. <input type="text" placeholder="请输入您要查找的型号、品牌或商家" v-model="keyword"
  24. @click="onHomeSearchClick()"/>
  25. <span @click="onSearch()"><i class="iconfont icon-sousuo"></i></span>
  26. </div>
  27. <!--<p style="color:#e45803;line-height:.4rem;margin-top:.1rem;width:4.2rem;margin-left:1rem;">搜品牌、搜现货 、搜好店 、搜规格书 就上优软商城</p>-->
  28. </div>
  29. </div>
  30. <div class="home-main">
  31. <nuxt-link to="/mobile/shop" class="home-main-content">
  32. <div>
  33. <img src="/images/mobile/@2x/home/shopbrand@2x.png">
  34. </div>
  35. <p>店铺列表</p>
  36. </nuxt-link>
  37. <nuxt-link to="/mobile/user" class="home-main-content">
  38. <div>
  39. <img src="/images/mobile/@2x/home/storebrand@2x.png">
  40. </div>
  41. <p>我的收藏</p>
  42. </nuxt-link>
  43. <a @click="showStoreInfo = true" class="home-main-content">
  44. <div>
  45. <img src="/images/mobile/@2x/home/phonebrand@2x.png">
  46. </div>
  47. <p>联系我们</p>
  48. </a>
  49. <a class="home-main-content">
  50. <div>
  51. <i class="icon-pinpai iconfont"></i>
  52. </div>
  53. <h2>
  54. {{numbrand[0]}}
  55. </h2>
  56. <p>品牌</p>
  57. </a>
  58. <a class="home-main-content">
  59. <div>
  60. <i class="icon-xinghao iconfont"></i>
  61. </div>
  62. <h2>
  63. {{numbrand[1]}}
  64. </h2>
  65. <p>型号</p>
  66. </a>
  67. <a class="home-main-content">
  68. <div>
  69. <i class="icon-biaoguigeshuomingshu iconfont"></i>
  70. </div>
  71. <h2>
  72. {{numbrand[2]}}
  73. </h2>
  74. <p>规格书</p>
  75. </a>
  76. </div>
  77. </div>
  78. <div class="main-search" v-else>
  79. <div class="main-search-header">
  80. <input type="text" v-model="keyword" placeholder="请输入您要查找的型号或品牌" @keyup.13="onSearch()" autofocus>
  81. <span @click="onSearch()">搜索</span>
  82. </div>
  83. <ul class="associate-list" v-show="associate.show">
  84. <li @click="onAssociateClick(similar.code)" v-for="similar in similarKeywords.all">
  85. <i class="icon-sousuo iconfont"></i>
  86. <span>{{similar.code}}</span>
  87. </li>
  88. <li>查找“{{keyword}}”</li>
  89. </ul>
  90. <div class="hot-history" v-show="!associate.show">
  91. <div class="search-history">
  92. <p>历史搜索</p>
  93. <ul>
  94. <li v-for="item in searchHistory" @click="onSearch(item.keyword)">
  95. <a>{{item.keyword}}</a>
  96. </li>
  97. </ul>
  98. </div>
  99. <div class="search-hot">
  100. <img src="/images/mobile/@2x/home/hot-search.png" alt="">
  101. <ul>
  102. <li v-for="hotword in hotwords">
  103. <nuxt-link :to="hotword.url" v-text="hotword.name"></nuxt-link>
  104. </li>
  105. </ul>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. <script>
  112. export default {
  113. name: 'home',
  114. data () {
  115. return {
  116. keyword: '',
  117. activeType: 'model',
  118. showMainSearch: false,
  119. showStoreInfo: false,
  120. isMore: false,
  121. isShow: false,
  122. len: 0,
  123. bgUrl: '/images/mobile/@2x/home/background@2x.png',
  124. associate: {
  125. show: false
  126. }
  127. }
  128. },
  129. props: {
  130. hotwords: {
  131. type: Array,
  132. default () {
  133. return [
  134. {name: 'DSP1-DC5V-F', url: '/mobile/brand/componentDetail/0900300200000669'},
  135. {name: 'Vishay', url: '/mobile/brand/30327265e42a871be050007f01003d96'},
  136. {name: 'Panasonic', url: '/mobile/brand/30327265e47d871be050007f01003d96'}
  137. ]
  138. }
  139. }
  140. },
  141. // filters: {
  142. // similarFilter: function (key) {
  143. // let keyword = this.keyword
  144. // let index = key.indexOf(keyword)
  145. // if (index !== -1) {
  146. // key = key.substring(0, index) + '<strong>' + key.sub(index, keyword.length) + '</strong>' + key.substring(index + keyword.length, key.length)
  147. // }
  148. // return key
  149. // }
  150. // },
  151. methods: {
  152. onHomeSearchClick () {
  153. this.showMainSearch = true
  154. this.$store.dispatch('searchData/getSearchHistory')
  155. },
  156. onBlur () {
  157. this.showMainSearch = false
  158. },
  159. onSearch (key) {
  160. if (key && key !== '') {
  161. this.keyword = key
  162. }
  163. if (this.keyword) {
  164. this.associate.show = false
  165. this.$router.push({path: '/mobile/search?w=' + encodeURIComponent(this.keyword)})
  166. }
  167. },
  168. matNumber (num) {
  169. if (num > 99999999) {
  170. this.isShow = true
  171. let str2 = num.toString()
  172. num = Math.floor(num / 100000000)
  173. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  174. num = num + 1
  175. }
  176. num += '亿'
  177. }
  178. if (num > 9999) {
  179. this.isMore = true
  180. let str = num.toString()
  181. num = Math.floor(num / 10000)
  182. if (parseInt(str.charAt(str.length - 4)) > 4) {
  183. num = num + 1
  184. }
  185. num += '万'
  186. } else {
  187. num += '个'
  188. }
  189. return num
  190. },
  191. forNum (numbers) {
  192. let num = []
  193. for (let i = 0; i < numbers.length; i++) {
  194. num.push(this.matNumber(numbers[i].count))
  195. }
  196. return num
  197. },
  198. loadCounts () {
  199. this.$store.dispatch('loadProductCounts', { _status: 'actived' })
  200. },
  201. onChange () {
  202. if (!this.keyword) {
  203. this.associate.show = false
  204. this.$store.dispatch('resetSearchKeywords')
  205. } else {
  206. this.searchKeywords()
  207. }
  208. if (this.click_flag) {
  209. this.associate.show = false
  210. }
  211. },
  212. searchKeywords () {
  213. this.associate.show = true
  214. this.$store.dispatch('searchKeywords', { keyword: this.keyword })
  215. },
  216. onAssociateClick (word) {
  217. this.keyword = word
  218. this.onSearch()
  219. }
  220. },
  221. created () {
  222. this.$store.dispatch('resetSearchKeywords')
  223. },
  224. watch: {
  225. 'keyword': {
  226. handler (val, oldVal) {
  227. let keywords = this.similarKeywords.data
  228. if (!keywords || !keywords.length) {
  229. this.onChange()
  230. }
  231. }
  232. }
  233. },
  234. computed: {
  235. numbrand () {
  236. return this.forNum(this.counts)
  237. },
  238. counts () {
  239. return this.$store.state.product.common.counts.data
  240. },
  241. similarKeywords () {
  242. return this.$store.state.search.keywords.data
  243. },
  244. searchHistory () {
  245. console.log(this.$store.state.searchData)
  246. return this.$store.state.searchData.searchHistory.searchHistory.data
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. @import '~assets/scss/mobileCommon';
  253. .home{
  254. font-size:.28rem;
  255. background: #f7fbff;
  256. margin-bottom:1rem;
  257. .home-header{
  258. width:100%;
  259. height:6.12rem;
  260. padding-bottom:1rem;
  261. .home-search{
  262. width:6rem;
  263. line-height: .3rem;
  264. margin:0 auto;
  265. text-align: center;
  266. padding-top: 1.74rem;
  267. ul{
  268. display:inline-flex;
  269. li{
  270. flex:1;
  271. text-align:center;
  272. >span{
  273. display:inline-block;
  274. width:.72rem;
  275. line-height:.33rem;
  276. height:.33rem;
  277. background: #fff;
  278. color:#000;
  279. border-radius: .05rem .05rem 0 0 ;
  280. }
  281. }
  282. li.active span{
  283. background: #3c7cf5;
  284. color:#fff;
  285. cursor:pointer;
  286. }
  287. }
  288. .home-input{
  289. width: 6rem;
  290. height: .61rem;
  291. line-height: .61rem;
  292. input{
  293. width:5.17rem;
  294. display: inline-block;
  295. padding: 0 1rem 0 .16rem;
  296. margin-right:-.83rem;
  297. font-size:.24rem;
  298. border:.02rem solid #3c7cf5;
  299. border-radius:.05rem;
  300. }
  301. span{
  302. display:inline-block;
  303. text-align: center;
  304. width:.83rem;
  305. font-size:.23rem;
  306. border-left:none;
  307. border-radius: 0 .05rem .05rem 0;
  308. background: #3c7cf5;
  309. color:#fff;
  310. vertical-align: middle;
  311. i{
  312. font-size: .33rem;
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. .home-main{
  320. width:100%;
  321. display:flex;
  322. justify-content:space-between;
  323. flex-wrap:wrap;
  324. text-align: center;
  325. padding-top: .46rem;
  326. height: 6.25rem;
  327. }
  328. .home-main a.home-main-content {
  329. width:33%;
  330. margin-bottom:.52rem;
  331. }
  332. .home-main .home-main-content div{
  333. border-radius: .2rem;
  334. width:1.14rem;
  335. height:1.14rem;
  336. margin:0 auto;
  337. }
  338. .home-main .home-main-content div>img{
  339. width: 100%;
  340. height:100%;
  341. }
  342. .home-main .home-main-content div>i {
  343. font-size: .8rem;
  344. }
  345. .home-main .home-main-content:nth-child(4) div>i {
  346. color: #ff3064;
  347. }
  348. .home-main .home-main-content:nth-child(5) div>i {
  349. color: #fa6743;
  350. }
  351. .home-main .home-main-content:nth-child(6) div>i {
  352. color: #fcb836;
  353. }
  354. .home-main .home-main-content p{
  355. font-size:.28rem;
  356. color:rgb(51,51,51);
  357. line-height: .52rem;
  358. }
  359. .home-main .home-main-content h2{
  360. font-size:.3rem;
  361. color:#ff7800;
  362. line-height: .32rem;
  363. margin:0;
  364. margin-top:.1rem;
  365. }
  366. .main-search {
  367. background: #fff;
  368. .main-search-header {
  369. height: .71rem;
  370. background: #4391f7;
  371. line-height: .66rem;
  372. padding-left: .84rem;
  373. input {
  374. width: 4.78rem;
  375. height: .54rem;
  376. line-height: .54rem;
  377. font-size: .23rem;
  378. color: #999;
  379. padding-left: .2rem;
  380. border-bottom-left-radius: .05rem;
  381. border-top-left-radius: .05rem;
  382. border: .01rem solid #fff;
  383. background: #fff;
  384. }
  385. span {
  386. display: inline-block;
  387. width: 1.02rem;
  388. text-align: center;
  389. height: .54rem;
  390. line-height: .54rem;
  391. color: #366df3;
  392. font-size: .23rem;
  393. margin-left: .02rem;
  394. border-top-right-radius: .05rem;
  395. border-bottom-right-radius: .05rem;
  396. background: #fff;
  397. }
  398. }
  399. .associate-list {
  400. padding-top: .25rem;
  401. background: #fff;
  402. li {
  403. height: 58px;
  404. line-height: 58px;
  405. padding: 0 45px;
  406. border-bottom: .01rem solid #f1f0f0;
  407. i {
  408. font-size: .4rem;
  409. margin-right: .24rem;
  410. color: #ddd;
  411. }
  412. span {
  413. color: #999;
  414. font-size: .28rem;
  415. line-height: 58px;
  416. height: .58rem;
  417. display: inline-block;
  418. }
  419. &:active, &:hover {
  420. background: #eee;
  421. }
  422. &:last-child {
  423. text-align: center;
  424. font-size: .3rem;
  425. color: #3976f4;
  426. border-bottom: none;
  427. &:active, &:hover {
  428. background: #fff;
  429. }
  430. }
  431. }
  432. }
  433. .hot-history {
  434. .search-history {
  435. padding-left: .51rem;
  436. padding-top: .38rem;
  437. >p {
  438. font-size: .3rem;
  439. color: #333;
  440. }
  441. ul {
  442. text-align: left;
  443. margin-top: .26rem;
  444. li {
  445. display: inline-block;
  446. max-width: 2.83rem;
  447. overflow: hidden;
  448. text-overflow: ellipsis;
  449. white-space: nowrap;
  450. margin-right: 10px;
  451. background: #f2f6ff;
  452. height: .56rem;
  453. line-height: .56rem;
  454. padding: 0 .12rem;
  455. a {
  456. font-size: .3rem;
  457. color: #666;
  458. }
  459. }
  460. }
  461. }
  462. .search-hot {
  463. text-align: center;
  464. margin-top: .3rem;
  465. >img {
  466. width: 2.56rem;
  467. height: .67rem;
  468. }
  469. ul {
  470. text-align: left;
  471. padding-left: .51rem;
  472. margin-top: .31rem;
  473. li {
  474. display: inline-block;
  475. max-width: 2.83rem;
  476. overflow: hidden;
  477. text-overflow: ellipsis;
  478. white-space: nowrap;
  479. margin-right: 10px;
  480. background: #fef1eb;
  481. height: .56rem;
  482. line-height: .56rem;
  483. padding: 0 .12rem;
  484. a {
  485. font-size: .3rem;
  486. color: #666;
  487. }
  488. &:nth-child(1) {
  489. a {
  490. color: #fc5708;
  491. }
  492. }
  493. }
  494. }
  495. }
  496. }
  497. }
  498. </style>