BrandCenter.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div>
  3. <search-header @searchAction="onSearch" :placeholder="'请输入品牌名称'" :similarType="'brand'" :useMatchRule="false"></search-header>
  4. <div class="mobile-brand-center mobile-content">
  5. <div class="mobile-brand-wrap" :class="{'is-search': isSearch}">
  6. <div class="mobile-brand-header" v-if="!isSearch">
  7. <img src="/images/mobile/@2x/brand/brandWall.png" alt="">
  8. <div class="mobile-brand-index" :class="{'scrolled': isScrolled, 'is-more': isScrolled && !isMore}">
  9. <p style="float: left">索引:</p>
  10. <div style="float: left;width: 5.5rem">
  11. <nuxt-link :to="'/mobile/brand/brandCenter/' + item"
  12. :class="{'active': item == activeIndex}"
  13. :key="key" v-for="(item, key) in initArr">{{item}}</nuxt-link>
  14. </div>
  15. <div v-if="isScrolled" class="more-index" @click="isMore = !isMore">
  16. {{!isMore ? '更多' : '收起'}}
  17. <img v-if="!isMore" src="/images/mobile/@2x/applyPurchase/currency-arrow-down.png" alt="">
  18. <img src="/images/mobile/@2x/applyPurchase/currency-arrow-up.png" v-else alt="">
  19. </div>
  20. <div class="clear-float"></div>
  21. </div>
  22. </div>
  23. <div class="mobile-brand-list">
  24. <div>
  25. <div class="brand-initial">
  26. <p v-if="!isSearch" v-text="activeIndex" :style="activeIndex === '0~9' ? 'font-size: .28rem': 'font-size: .32rem'"></p>
  27. <span v-if="!isSearch">
  28. {{activeIndex}}开头共<span>{{brandList.totalElements || 0}}</span>个品牌
  29. </span>
  30. <span v-if="isSearch">搜索<span>{{baseUtils.filterStringEllipsis(pageParams.keyword, 25)}}</span>,共有<span>{{brandList.totalElements || 0}}</span>个品牌</span>
  31. </div>
  32. <div class="brand-items" v-if="brandListTemplate.length">
  33. <nuxt-link :to="`/mobile/brand/${brand.uuid}/`" :key="brand.uuid" v-for="brand in brandListTemplate">
  34. <div>{{brand.nameEn}}</div>
  35. <div v-if="brand.nameCn != brand.nameEn">{{brand.nameCn}}</div>
  36. </nuxt-link>
  37. </div>
  38. <empty-status :type="'search'"
  39. :text="`抱歉,暂无与“${baseUtils.filterStringEllipsis(pageParams.keyword, 25)}”匹配的品牌信息`"
  40. :showLink="false"
  41. v-else
  42. ></empty-status>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <pull-up :searchMore="fetching" :allPage="allPage" :page="pageParams.page" @pullUpAction="onPullUpAction"></pull-up>
  48. </div>
  49. </template>
  50. <script>
  51. import {SearchHeader} from '~components/mobile/base'
  52. import { PullUp, EmptyStatus } from '~components/mobile/common'
  53. export default {
  54. name: 'brandList',
  55. data () {
  56. return {
  57. initArr: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0~9'],
  58. activeIndex: this.$route.params.initial,
  59. isScrolled: false,
  60. isMore: false,
  61. pageParams: {
  62. page: 1,
  63. count: 60,
  64. keyword: ''
  65. },
  66. isChange: false,
  67. brandListTemplate: [],
  68. isSearch: false,
  69. showKeyword: ''
  70. }
  71. },
  72. components: {
  73. SearchHeader,
  74. PullUp,
  75. EmptyStatus
  76. },
  77. mounted: function () {
  78. let _this = this
  79. _this.$nextTick(function () {
  80. window.addEventListener('scroll', function () {
  81. _this.onScroll()
  82. }, false)
  83. })
  84. },
  85. watch: {
  86. 'brandData.data': {
  87. handler: function (val) {
  88. let list = [...val.content]
  89. if (this.isChange) {
  90. this.brandListTemplate = list
  91. this.isChange = false
  92. } else {
  93. this.brandListTemplate = [...this.brandListTemplate, ...list]
  94. }
  95. },
  96. immediate: true
  97. }
  98. },
  99. computed: {
  100. brandData () {
  101. return this.$store.state.product.brand.brandPagerList
  102. },
  103. brandList () {
  104. return this.brandData.data
  105. },
  106. allPage () {
  107. return this.brandList.totalPages
  108. },
  109. fetching () {
  110. return this.brandData.fetching
  111. }
  112. },
  113. methods: {
  114. onScroll () {
  115. if (this.baseUtils.startWith(this.$route.path, '/mobile/brand/brandCenter')) {
  116. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  117. this.isScrolled = scrolled > 200
  118. }
  119. },
  120. // reloadData: function () {
  121. // this.$store.dispatch('product/loadBrandsPager', {'initial': this.activeIndex, page: this.pageParams.page, count: this.pageParams.count, keyword: this.pageParams.keyword})
  122. // },
  123. reloadData: function () {
  124. !this.isSearch ? this.$store.dispatch('product/loadBrandsPager', {'initial': this.activeIndex, page: this.pageParams.page, count: this.pageParams.count, keyword: this.pageParams.keyword})
  125. : this.$store.dispatch('product/loadBrandsPagerWithoutIndex', this.pageParams)
  126. },
  127. onSearch: function (keyObj) {
  128. if (keyObj.keyword && keyObj.keyword !== '') {
  129. this.pageParams.keyword = keyObj.keyword
  130. this.pageParams.page = 1
  131. this.isChange = true
  132. this.isSearch = true
  133. this.showKeyword = this.pageParams.keyword
  134. this.reloadData()
  135. } else {
  136. this.isSearch = false
  137. this.pageParams.page = 1
  138. this.isChange = true
  139. this.pageParams.keyword = ''
  140. this.reloadData()
  141. }
  142. },
  143. onPullUpAction: function () {
  144. this.pageParams.page++
  145. this.reloadData()
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .mobile-brand-center {
  152. margin-bottom: .98rem;
  153. width: 100%;
  154. background: #f7f7f7;
  155. padding-top: .24rem;
  156. .mobile-brand-wrap {
  157. width: 6.96rem;
  158. background: #fff;
  159. margin: 0 auto;
  160. padding: 0 .21rem;
  161. border-radius: .1rem;
  162. .mobile-brand-header {
  163. text-align: center;
  164. height: 4.32rem;
  165. >img {
  166. margin: .24rem auto .19rem;
  167. width: 6.09rem;
  168. height: .66rem;
  169. }
  170. .mobile-brand-index {
  171. font-size: .3rem;
  172. line-height: .62rem;
  173. background: #f4fafd;
  174. margin: .19rem 0 .25rem 0;
  175. padding: 0 .07rem;
  176. text-align: left;
  177. p {
  178. float: left;
  179. }
  180. a {
  181. color: #666;
  182. width: 0.9rem;
  183. display: inline-block;
  184. text-align: center;
  185. &.active, &.hover, &.focus {
  186. color: #418bf6;
  187. }
  188. }
  189. &.scrolled {
  190. position: fixed;
  191. top: .88rem;
  192. width: 100%;
  193. background: #fff;
  194. border-bottom: .04rem solid #ccc;
  195. left: 0;
  196. padding-left: .58rem;
  197. margin-top: 0;
  198. .more-index {
  199. position: absolute;
  200. right: .1rem;
  201. color: #5078cb;
  202. }
  203. }
  204. &.is-more {
  205. height: 1.32rem;
  206. overflow: hidden;
  207. img {
  208. width: .2rem;
  209. margin-left: -.1rem;
  210. }
  211. }
  212. }
  213. }
  214. .mobile-brand-list {
  215. font-size: .3rem;
  216. .brand-initial {
  217. border-bottom: .04rem solid #418bf6;
  218. p {
  219. width: .64rem;
  220. height: .43rem;
  221. line-height: .43rem;
  222. margin: 0;
  223. background: #418bf6;
  224. color: #fff;
  225. font-size: .32rem;
  226. text-align: center;
  227. display: inline-block;
  228. border-top-left-radius: .05rem;
  229. border-top-right-radius: .05rem;
  230. }
  231. >span {
  232. font-size: .22rem;
  233. color: #999;
  234. >span {
  235. color: #418bf6;
  236. }
  237. }
  238. }
  239. .brand-items {
  240. overflow: hidden;
  241. margin-bottom: .2rem;
  242. a {
  243. overflow: hidden;
  244. display: inline-block;
  245. color: #333;
  246. border-radius: .05rem;
  247. background: #fff;
  248. margin: .18rem .42rem .12rem 0;
  249. height: .78rem;
  250. float: left;
  251. &:nth-child(3n) {
  252. margin-right: 0;
  253. }
  254. &:active {
  255. color: #418bf6;
  256. }
  257. div {
  258. width: 1.9rem;
  259. height: .39rem;
  260. line-height: .39rem;
  261. text-align: left;
  262. text-overflow: ellipsis;
  263. white-space: nowrap;
  264. overflow: hidden;
  265. &:nth-child(2) {
  266. font-size: .26rem;
  267. color: #666;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. &.is-search {
  274. width: 100%;
  275. padding-top: .5rem;
  276. .mobile-brand-header {
  277. height: auto;
  278. }
  279. .mobile-brand-list {
  280. .brand-initial {
  281. line-height: .5rem;
  282. > span {
  283. font-size: .26rem;
  284. > span {
  285. color: red;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. </style>