BrandCenter.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div class="mobile-brand-center mobile-content">
  3. <div class="mobile-brand-wrap">
  4. <div class="mobile-brand-header">
  5. <img src="/images/mobile/@2x/brand/brandWall.png" alt="">
  6. <div class="mobile-brand-index" :class="{'scrolled': isScrolled}">
  7. <p style="float: left">索引:</p>
  8. <div style="float: left;width: 5.5rem">
  9. <nuxt-link :to="'/mobile/brand/brandCenter/' + item"
  10. :class="{'active': item == activeIndex}"
  11. :key="key" v-for="(item, key) in initArr">{{item}}</nuxt-link>
  12. </div>
  13. <div style="clear: both"></div>
  14. </div>
  15. </div>
  16. <div class="mobile-brand-list">
  17. <div v-for="(brands, initial) in brandList">
  18. <div class="brand-initial">
  19. <p v-text="initial" :style="initial === '0~9' ? 'font-size: .28rem': 'font-size: .32rem'"></p>
  20. <span>
  21. {{initial}}开头共<span>{{brands.length || 0}}</span>个品牌
  22. </span>
  23. </div>
  24. <div class="brand-items">
  25. <nuxt-link :to="`/mobile/brand/${brand.uuid}/`" :key="key" v-for="(brand, key) in brands">
  26. <div>{{brand.nameEn}}</div>
  27. <div v-if="brand.nameCn != brand.nameEn">{{brand.nameCn}}</div>
  28. </nuxt-link>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. function sortList (letter) {
  37. return function (a, b) {
  38. var value1 = a[letter]
  39. var value2 = b[letter]
  40. if (value1 > value2) {
  41. return 1
  42. } else if (value1 < value2) {
  43. return -1
  44. } else {
  45. return 0
  46. }
  47. }
  48. }
  49. export default {
  50. name: 'brandList',
  51. data () {
  52. return {
  53. initArr: [
  54. 'A',
  55. 'B',
  56. 'C',
  57. 'D',
  58. 'E',
  59. 'F',
  60. 'G',
  61. 'H',
  62. 'I',
  63. 'J',
  64. 'K',
  65. 'L',
  66. 'M',
  67. 'N',
  68. 'O',
  69. 'P',
  70. 'Q',
  71. 'R',
  72. 'S',
  73. 'T',
  74. 'U',
  75. 'V',
  76. 'W',
  77. 'X',
  78. 'Y',
  79. 'Z',
  80. '0~9'
  81. ],
  82. activeIndex: this.$route.params.initial,
  83. isScrolled: false
  84. }
  85. },
  86. mounted: function () {
  87. let _this = this
  88. _this.$nextTick(function () {
  89. window.addEventListener('scroll', function () {
  90. _this.onScroll()
  91. }, false)
  92. })
  93. },
  94. watch: {
  95. $route: function (val, oldVal) {
  96. this.activeIndex = val.params.initial
  97. }
  98. },
  99. computed: {
  100. brandList () {
  101. let brandsList = JSON.parse(JSON.stringify(this.$store.state.product.brand.brandList.data))
  102. if (brandsList) {
  103. for (let i in brandsList) {
  104. brandsList[i] = brandsList[i].sort(sortList('nameEn'))
  105. }
  106. }
  107. let temp = {}
  108. let keys = []
  109. for (let key in brandsList) {
  110. keys.push(key)
  111. }
  112. keys = keys.sort()
  113. for (let i = 0; i < keys.length; i++) {
  114. temp[keys[i]] = brandsList[keys[i]]
  115. }
  116. return temp
  117. }
  118. },
  119. methods: {
  120. onScroll () {
  121. if (this.startWith(this.$route.path, '/mobile/brand/brandCenter')) {
  122. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  123. this.isScrolled = scrolled > 0
  124. }
  125. },
  126. startWith: function (str, s) {
  127. let reg = new RegExp('^' + s)
  128. return reg.test(str)
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .mobile-brand-center {
  135. margin-bottom: .98rem;
  136. width: 100%;
  137. background: #f7f7f7;
  138. padding-top: .24rem;
  139. .mobile-brand-wrap {
  140. width: 6.96rem;
  141. background: #fff;
  142. margin: 0 auto;
  143. padding: 0 .21rem;
  144. border-radius: .1rem;
  145. .mobile-brand-header {
  146. text-align: center;
  147. >img {
  148. margin: .24rem auto .19rem;
  149. width: 6.09rem;
  150. height: .66rem;
  151. }
  152. .mobile-brand-index {
  153. font-size: .3rem;
  154. line-height: .62rem;
  155. background: #f4fafd;
  156. margin: .19rem 0 .25rem 0;
  157. padding: 0 .07rem;
  158. text-align: left;
  159. p {
  160. float: left;
  161. }
  162. a {
  163. color: #666;
  164. width: 0.9rem;
  165. display: inline-block;
  166. text-align: center;
  167. &.active, &.hover, &.focus {
  168. color: #418bf6;
  169. }
  170. }
  171. &.scrolled {
  172. position: fixed;
  173. top: .88rem;
  174. width: 100%;
  175. background: #fff;
  176. border-bottom: .04rem solid #ccc;
  177. left: 0;
  178. padding-left: .58rem;
  179. margin-top: 0;
  180. }
  181. }
  182. }
  183. .mobile-brand-list {
  184. font-size: .3rem;
  185. .brand-initial {
  186. border-bottom: .04rem solid #418bf6;
  187. p {
  188. width: .64rem;
  189. height: .43rem;
  190. line-height: .43rem;
  191. margin: 0;
  192. background: #418bf6;
  193. color: #fff;
  194. font-size: .32rem;
  195. text-align: center;
  196. display: inline-block;
  197. border-top-left-radius: .05rem;
  198. border-top-right-radius: .05rem;
  199. }
  200. >span {
  201. font-size: .22rem;
  202. color: #999;
  203. >span {
  204. color: #418bf6;
  205. }
  206. }
  207. }
  208. .brand-items {
  209. overflow: hidden;
  210. margin-bottom: .2rem;
  211. a {
  212. overflow: hidden;
  213. display: inline-block;
  214. color: #333;
  215. border-radius: .05rem;
  216. background: #fff;
  217. margin: .18rem .42rem .12rem 0;
  218. height: .78rem;
  219. float: left;
  220. &:nth-child(3n) {
  221. margin-right: 0;
  222. }
  223. &:active {
  224. color: #418bf6;
  225. }
  226. div {
  227. width: 1.9rem;
  228. height: .39rem;
  229. line-height: .39rem;
  230. text-align: left;
  231. text-overflow: ellipsis;
  232. white-space: nowrap;
  233. overflow: hidden;
  234. &:nth-child(2) {
  235. font-size: .26rem;
  236. color: #666;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. </style>