BrandDetail.vue 18 KB

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