BrandDetail.vue 16 KB

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