BrandDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <div class="brand-detail" @click="checkShowFilter()">
  3. <div class="brand-logo">
  4. <div class="brand-logo-box">
  5. <img :src="brandDetail.logoUrl || '/images/component/default.png'" :alt="brandDetail.nameEn"/>
  6. </div>
  7. </div>
  8. <div class="brand-switch-item">
  9. <span :class="activeType=='detail'?'mobile-switch-btn active':'mobile-switch-btn'" @click="setActiveType('detail')">品牌</span>
  10. <span :class="activeType=='product'?'mobile-switch-btn active':'mobile-switch-btn'" @click="setActiveType('product')">产品</span>
  11. </div>
  12. <div class="brand-param-list" v-if="activeType=='detail'">
  13. <div class="brand-param-item" v-if="brandDetail.series">
  14. <p class="remind-title">主营产品</p>
  15. <img class="remind-tag" src="/images/mobile/@2x/title-line.png" alt="">
  16. <div class="main-sell">{{brandDetail.series}}</div>
  17. </div>
  18. <div class="brand-param-item" v-if="applications.length>0">
  19. <p class="remind-title">应用领域</p>
  20. <img class="remind-tag" src="/images/mobile/@2x/title-line.png" alt="">
  21. <div class="main-sell">
  22. <span v-for="(item, index) in applications"><span>{{item}}</span><span v-show="index+1 < applications.length">|</span></span>
  23. </div>
  24. </div>
  25. <div class="brand-param-item" v-if="brandDetail.brief">
  26. <p class="remind-title">品牌介绍</p>
  27. <img class="remind-tag" src="/images/mobile/@2x/title-line.png" alt="">
  28. <div class="main-sell">{{brandDetail.brief | wordFilter}}</div>
  29. </div>
  30. <div class="brand-param-item" v-if="brandDetail.url">
  31. <p class="remind-title">官网地址</p>
  32. <img class="remind-tag" src="/images/mobile/@2x/title-line.png" alt="">
  33. <a class="brand-url" :href="brandDetail.url" v-text="brandDetail.url"></a>
  34. </div>
  35. </div>
  36. <div class="brand-product-list" v-if="activeType=='product'">
  37. <div class="search-box" v-if="searchLists && searchLists.length > 0 || isSearch">
  38. <div class="kind-selecter">
  39. <div @mouseenter="isInList = true" @mouseleave="isInList = false">
  40. <span @click="showKindList = !showKindList" v-text="selectedKind.substring(0, 4)"></span>
  41. <ul v-show="showKindList">
  42. <li @click="selectKind({nameCn: '全部分类', id: ''})" v-show="selectedKind !== '全部分类'">全部分类</li>
  43. <li v-for="kind in kindList" v-text="kind.nameCn" @click="selectKind(kind)" v-show="selectedKind !== kind.nameCn"></li>
  44. </ul>
  45. </div>
  46. </div>
  47. <div class="kind-search">
  48. <input type="text" v-model="keyword" placeholder="请输入型号">
  49. <i @click="goodsSearch()" class="icon-sousuo iconfont"></i>
  50. </div>
  51. </div>
  52. <ul class="product-list">
  53. <li v-for="product in searchLists">
  54. <nuxt-link class="text-left" :to="'/mobile/brand/componentDetail/' + product.uuid">{{product.code}}</nuxt-link>
  55. <a class="text-right" @click="toShowPdf(product.attach)">规格书 <i class="icon-chakan iconfont"></i></a>
  56. </li>
  57. </ul>
  58. <div class="no-product" v-if="!productList.totalPages || productList.totalPages == 0">
  59. <img :src="!isSearch?'/images/mobile/@2x/car@2x.png':'/images/mobile/@2x/search-empty.png'" alt="">
  60. <div>抱歉,暂无产品信息</div>
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. export default {
  67. name: 'MobileBrandsDetail',
  68. data () {
  69. return {
  70. applications: [],
  71. activeType: 'detail',
  72. keyword: '',
  73. showKindList: false,
  74. parentid: 0,
  75. ids: null,
  76. pageParams: {
  77. page: 1,
  78. count: 10,
  79. filter: {}
  80. },
  81. selectedKind: '全部分类',
  82. isInList: false,
  83. isSearch: false,
  84. isSearchingMore: false,
  85. searchLists: []
  86. }
  87. },
  88. filters: {
  89. wordFilter: function (str) {
  90. return str.length > 65 ? str.substring(0, 65) + '...' : str
  91. }
  92. },
  93. mounted: function () {
  94. let _this = this
  95. _this.$nextTick(function () {
  96. window.addEventListener('scroll', function () {
  97. _this.scroll()
  98. }, false)
  99. document.addEventListener('click', _this.checkShowFilter)
  100. })
  101. },
  102. watch: {
  103. keyword: function (val, oldVal) {
  104. this.isSearch = true
  105. }
  106. },
  107. computed: {
  108. brandDetail () {
  109. let list = this.$store.state.brandDetail.detail.data
  110. if (list.application && list.application !== '') {
  111. this.applications = list.application.split(',')
  112. }
  113. this.pageParams.filter.brandid = list.id
  114. return list
  115. },
  116. productList () {
  117. console.log(this.pageParams)
  118. let list = this.$store.state.brandComponent.component.data
  119. this.searchLists = this.searchLists.concat(list.content)
  120. this.isSearchingMore = false
  121. return list
  122. },
  123. allPage () {
  124. return this.productList.totalPages || 0
  125. },
  126. kindList () {
  127. let brands = this.$store.state.brandCategories.categories.data
  128. if (!brands || brands.length === 0) {
  129. return []
  130. }
  131. // 初始化去除重复数据
  132. for (let i = 0; i < brands.length; i++) {
  133. for (let j = 0; j < brands[i].length; j++) {
  134. brands[i][j].children = []
  135. }
  136. }
  137. // 处理第1层
  138. if ((brands[0] && brands[0].length > 0) && (brands[1] && brands[1].length > 0)) {
  139. for (let i = 0; i < brands[1].length; i++) {
  140. for (let j = 0; j < brands[0].length; j++) {
  141. if (brands[0][j].id === brands[1][i].parentid) {
  142. if (!brands[0][j].children) {
  143. brands[0][j].children = []
  144. }
  145. brands[0][j].children.push(brands[1][i])
  146. break
  147. }
  148. }
  149. }
  150. }
  151. // 处理第2层
  152. if ((brands[1] && brands[1].length > 0) && (brands[2] && brands[2].length > 0)) {
  153. for (let i = 0; i < brands[2].length; i++) {
  154. for (let j = 0; j < brands[1].length; j++) {
  155. if (brands[1][j].id === brands[2][i].parentid) {
  156. if (!brands[1][j].children) {
  157. brands[1][j].children = []
  158. }
  159. brands[1][j].children.push(brands[2][i])
  160. break
  161. }
  162. }
  163. }
  164. }
  165. // 处理第3层
  166. if ((brands[2] && brands[2].length > 0) && (brands[3] && brands[3].length > 0)) {
  167. for (let i = 0; i < brands[3].length; i++) {
  168. for (let j = 0; j < brands[2].length; j++) {
  169. if (brands[2][j].id === brands[3][i].parentid) {
  170. if (!brands[2][j].children) {
  171. brands[2][j].children = []
  172. }
  173. brands[2][j].children.push(brands[3][i])
  174. break
  175. }
  176. }
  177. }
  178. }
  179. let kindList = []
  180. if (brands[0]) {
  181. for (let i = 0; i < brands[0].length; i++) {
  182. this.getKinds(brands[0][i], kindList)
  183. }
  184. }
  185. return kindList
  186. }
  187. },
  188. methods: {
  189. scroll: function () {
  190. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  191. if (Math.ceil(scrolled + window.screen.availHeight) >= document.body.scrollHeight && !this.isSearchingMore && this.pageParams.page < this.allPage && this.activeType === 'product') {
  192. this.getMoreProduct()
  193. }
  194. },
  195. getMoreProduct: function () {
  196. if (!this.isSearchingMore) {
  197. this.pageParams.page++
  198. this.isSearchingMore = true
  199. this.pageCommodity(this.pageParams, this.ids)
  200. }
  201. },
  202. getKinds: function (list, kindList) {
  203. if (list.children && list.children.length > 0) {
  204. for (let i = 0; i < list.children.length; i++) {
  205. this.getKinds(list.children[i], kindList)
  206. }
  207. } else {
  208. kindList.push(list)
  209. }
  210. },
  211. selectKind: function (data) {
  212. this.showKindList = false
  213. this.selectedKind = data.nameCn
  214. if (this.parentid === data.id) {
  215. this.parentid = 0
  216. this.ids = null
  217. } else {
  218. if (data.level === 1) {
  219. this.parentid = data.id
  220. }
  221. }
  222. this.pageParams.page = 1
  223. this.pageParams.filter.brandid = this.brandDetail.id
  224. if (data.id !== '') {
  225. this.pageParams.filter.kindid = data.id
  226. } else {
  227. delete this.pageParams.filter.kindid
  228. }
  229. this.pageCommodity(this.pageParams, this.ids)
  230. },
  231. goodsSearch () {
  232. this.pageParams.page = 1
  233. this.pageParams.filter.brandid = this.brandDetail.id
  234. this.pageParams.filter.code = this.keyword
  235. this.pageCommodity(this.pageParams)
  236. },
  237. pageCommodity (params) {
  238. // try {
  239. // let { data } = await this.$http.get('/api/product/component/list', { params })
  240. // this.$store.commit('brandComponent/GET_COMPONENT_SUCCESS', data)
  241. // } catch (err) {
  242. // this.$store.commit('brandComponent/GET_COMPONENT_FAILURE', err)
  243. // }
  244. this.$store.dispatch('loadBrandComponent', this.pageParams)
  245. },
  246. checkShowFilter: function () {
  247. if (!this.isInList) {
  248. this.showKindList = false
  249. }
  250. },
  251. toShowPdf: function (url) {
  252. if (url && url !== '1') {
  253. window.location.href = url
  254. }
  255. },
  256. setActiveType: function (type) {
  257. if (type === 'product' && (this.pageParams.page !== 1 || this.keyword !== '')) {
  258. this.pageParams.page = 1
  259. // this.keyword = ''
  260. this.searchLists = []
  261. console.log(this.pageParams)
  262. this.$store.dispatch('loadBrandComponent', this.pageParams)
  263. // this.pageCommodity(this.pageParams)
  264. }
  265. this.activeType = type
  266. }
  267. }
  268. }
  269. </script>
  270. <style lang="scss" scoped>
  271. .brand-detail {
  272. margin: 0 auto;
  273. margin-bottom: 1.2rem;
  274. text-align: center;
  275. background: #f7f7f7;
  276. .brand-logo {
  277. height: 3.17rem;
  278. width: 6.96rem;
  279. display: inline-block;
  280. margin: .38rem auto .18rem;
  281. line-height: 2.13rem;
  282. background: #fff;
  283. text-align: center;
  284. border-radius: .1rem;
  285. background: url('/images/mobile/@2x/brand-bg.png')no-repeat;
  286. background-size: 7.16rem 3.17rem;
  287. background-position: -.1rem 0;
  288. box-shadow: 0 0 .01rem .03rem #eee;
  289. .brand-logo-box {
  290. border: .01rem solid #c7e5fd;
  291. border-radius: .1rem;
  292. height: 2.21rem;
  293. width: 3.73rem;
  294. margin: .5rem auto 0;
  295. background: #fff;
  296. position: relative;
  297. img {
  298. max-height: 2.13rem;
  299. max-width: 3.7rem;
  300. }
  301. }
  302. }
  303. .brand-switch-item {
  304. text-align: center;
  305. background: #fff;
  306. margin-bottom: .28rem;
  307. .mobile-switch-btn {
  308. background: #fff;
  309. color: #666;
  310. display: inline-block;
  311. height: .64rem;
  312. font-size: .34rem;
  313. line-height: .64rem;
  314. width: 1.4rem;
  315. &:first-child {
  316. margin-right: 1.78rem;
  317. }
  318. &.active {
  319. color: #fc5708;
  320. border-bottom: .01rem solid #fc5708;
  321. }
  322. }
  323. }
  324. .brand-param-list {
  325. text-align: left;
  326. padding: .3rem .44rem .11rem;
  327. margin-top: .28rem;
  328. background: #fff;
  329. .brand-param-item {
  330. font-size: .28rem;
  331. margin-bottom: .48rem;
  332. .remind-tag {
  333. width: 1.18rem;
  334. float: left;
  335. margin-top: .05rem;
  336. }
  337. .remind-title {
  338. font-size: .3rem;
  339. color: #418bf6;
  340. margin: 0;
  341. }
  342. .main-sell {
  343. color: #666;
  344. line-height: .4rem;
  345. max-height: 1.2rem;
  346. overflow: hidden;
  347. text-overflow: ellipsis;
  348. display: -webkit-box;
  349. -webkit-box-orient: vertical;
  350. -webkit-line-clamp: 3;
  351. margin-top: .15rem;
  352. }
  353. .brand-url {
  354. overflow: hidden;
  355. text-overflow: ellipsis;
  356. white-space: nowrap;
  357. color: #01a44e;
  358. margin-left: .28rem;
  359. position: relative;
  360. bottom: .32rem;
  361. &:hover, &:active, &:focus, &:visited {
  362. text-decoration: underline!important;
  363. }
  364. }
  365. }
  366. }
  367. .brand-product-list {
  368. font-size: .28rem;
  369. background: #fff;
  370. ul.product-list {
  371. text-align: center;
  372. li {
  373. margin-left: .42rem;
  374. width: 6.66rem;
  375. height: .66rem;
  376. line-height: .66rem;
  377. border: {
  378. top: .01rem solid rgb(230,228,228);
  379. bottom: .01rem solid rgb(230,228,228);
  380. }
  381. &:nth-child(even) {
  382. background: #f9f9f9;
  383. }
  384. &:active, &:hover {
  385. background: #eee;
  386. }
  387. .text-left {
  388. float: left;
  389. color: #333;
  390. width: 4.45rem;
  391. overflow: hidden;
  392. text-overflow: ellipsis;
  393. white-space: nowrap;
  394. }
  395. .text-right {
  396. float: right;
  397. color: #333;
  398. i {
  399. font-size: .55rem;
  400. float: right;
  401. margin-right: .27rem;
  402. margin-left: .54rem;
  403. color: #6fcafe;
  404. }
  405. }
  406. }
  407. }
  408. .search-box {
  409. margin-bottom: .28rem;
  410. padding-top: .28rem;
  411. .kind-selecter {
  412. display: inline-block;
  413. position: relative;
  414. float: left;
  415. margin-left: .72rem;
  416. div {
  417. display: inline-block;
  418. span {
  419. width: 1.64rem;
  420. height: .6rem;
  421. line-height: .6rem;
  422. border: .01rem solid rgb(195,195,195);
  423. border-radius: .05rem;
  424. font-size: .28rem;
  425. display: inline-block;
  426. background: url('/images/mobile/@2x/productDetail/kind-narrow-down@2x.png')no-repeat;
  427. padding-right: .15rem;
  428. background-position: 1.35rem .25rem;
  429. background-size: .14rem .1rem;
  430. overflow: hidden;
  431. }
  432. }
  433. }
  434. .kind-search {
  435. display: inline-block;
  436. margin-right: .19rem;
  437. width: 4.36rem;
  438. height: .6rem;
  439. line-height: .6rem;
  440. vertical-align: middle;
  441. input[type = "text"] {
  442. display: inline-block;
  443. width: 3.61rem;
  444. height: .6rem;
  445. border: .01rem solid rgb(195,195,195);
  446. padding-left: .21rem;
  447. font-size: .24rem;
  448. float: left;
  449. }
  450. i {
  451. background: rgb(65,142,247);
  452. width: .73rem;
  453. height: .6rem;
  454. line-height: .6rem;
  455. font-size: .32rem;
  456. color: #fff;
  457. display: inline-block;
  458. margin-left: -.02rem;
  459. }
  460. }
  461. ul {
  462. position: absolute;
  463. top: 0.65rem;
  464. max-height: 3.15rem;
  465. overflow-y: auto;
  466. &::-webkit-scrollbar
  467. {
  468. display: none;
  469. }
  470. li {
  471. width: 1.64rem;
  472. height: .83rem;
  473. line-height: .83rem;
  474. padding: 0 .08rem;
  475. overflow: hidden;
  476. text-overflow: ellipsis;
  477. white-space: nowrap;
  478. background: rgba(0, 0, 0, 0.6);
  479. color: #fff;
  480. }
  481. }
  482. }
  483. .no-product {
  484. background: #fff;
  485. padding-top: 1rem;
  486. img {
  487. display: block;
  488. text-align: center;
  489. margin: 0 auto;
  490. margin-bottom: .45rem;
  491. width: 4.11rem;
  492. height: 2.5rem;
  493. }
  494. div {
  495. width: 5.27rem;
  496. margin: 0 auto;
  497. text-align: center;
  498. line-height: .4rem;
  499. font-size: .32rem;
  500. color: #999;
  501. }
  502. }
  503. }
  504. }
  505. </style>