BrandDetail.vue 17 KB

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