BrandDetail.vue 17 KB

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