BrandCenter.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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>{{showKeyword}}</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="`抱歉,暂无与“${pageParams.keyword}”匹配的品牌信息`"
  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. import { startWith } from '~utils/baseUtils'
  54. export default {
  55. name: 'brandList',
  56. data () {
  57. return {
  58. 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'],
  59. activeIndex: this.$route.params.initial,
  60. isScrolled: false,
  61. isMore: false,
  62. pageParams: {
  63. page: 1,
  64. count: 60,
  65. keyword: ''
  66. },
  67. isChange: false,
  68. brandListTemplate: [],
  69. isSearch: false,
  70. showKeyword: ''
  71. }
  72. },
  73. components: {
  74. SearchHeader,
  75. PullUp,
  76. EmptyStatus
  77. },
  78. mounted: function () {
  79. let _this = this
  80. _this.$nextTick(function () {
  81. window.addEventListener('scroll', function () {
  82. _this.onScroll()
  83. }, false)
  84. })
  85. },
  86. watch: {
  87. 'brandData.data': {
  88. handler: function (val) {
  89. let list = [...val.content]
  90. if (this.isChange) {
  91. this.brandListTemplate = list
  92. this.isChange = false
  93. } else {
  94. this.brandListTemplate = [...this.brandListTemplate, ...list]
  95. }
  96. },
  97. immediate: true
  98. }
  99. },
  100. computed: {
  101. brandData () {
  102. return this.$store.state.product.brand.brandPagerList
  103. },
  104. brandList () {
  105. return this.brandData.data
  106. },
  107. allPage () {
  108. return this.brandList.totalPages
  109. },
  110. fetching () {
  111. return this.brandData.fetching
  112. }
  113. },
  114. methods: {
  115. onScroll () {
  116. if (startWith(this.$route.path, '/mobile/brand/brandCenter')) {
  117. let scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  118. this.isScrolled = scrolled > 200
  119. }
  120. },
  121. // reloadData: function () {
  122. // this.$store.dispatch('product/loadBrandsPager', {'initial': this.activeIndex, page: this.pageParams.page, count: this.pageParams.count, keyword: this.pageParams.keyword})
  123. // },
  124. reloadData: function () {
  125. !this.isSearch ? this.$store.dispatch('product/loadBrandsPager', {'initial': this.activeIndex, page: this.pageParams.page, count: this.pageParams.count, keyword: this.pageParams.keyword})
  126. : this.$store.dispatch('product/loadBrandsPagerWithoutIndex', this.pageParams)
  127. },
  128. onSearch: function (keyObj) {
  129. if (keyObj.keyword && keyObj.keyword !== '') {
  130. this.pageParams.keyword = keyObj.keyword
  131. this.pageParams.page = 1
  132. this.isChange = true
  133. this.isSearch = true
  134. this.showKeyword = this.pageParams.keyword
  135. this.reloadData()
  136. } else {
  137. this.isSearch = false
  138. this.pageParams.page = 1
  139. this.isChange = true
  140. this.pageParams.keyword = ''
  141. this.reloadData()
  142. }
  143. },
  144. onPullUpAction: function () {
  145. this.pageParams.page++
  146. this.reloadData()
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .mobile-brand-center {
  153. margin-bottom: .98rem;
  154. width: 100%;
  155. background: #f7f7f7;
  156. padding-top: .24rem;
  157. .mobile-brand-wrap {
  158. width: 6.96rem;
  159. background: #fff;
  160. margin: 0 auto;
  161. padding: 0 .21rem;
  162. border-radius: .1rem;
  163. .mobile-brand-header {
  164. text-align: center;
  165. height: 4.32rem;
  166. >img {
  167. margin: .24rem auto .19rem;
  168. width: 6.09rem;
  169. height: .66rem;
  170. }
  171. .mobile-brand-index {
  172. font-size: .3rem;
  173. line-height: .62rem;
  174. background: #f4fafd;
  175. margin: .19rem 0 .25rem 0;
  176. padding: 0 .07rem;
  177. text-align: left;
  178. p {
  179. float: left;
  180. }
  181. a {
  182. color: #666;
  183. width: 0.9rem;
  184. display: inline-block;
  185. text-align: center;
  186. &.active, &.hover, &.focus {
  187. color: #418bf6;
  188. }
  189. }
  190. &.scrolled {
  191. position: fixed;
  192. top: .88rem;
  193. width: 100%;
  194. background: #fff;
  195. border-bottom: .04rem solid #ccc;
  196. left: 0;
  197. padding-left: .58rem;
  198. margin-top: 0;
  199. .more-index {
  200. position: absolute;
  201. right: .1rem;
  202. color: #5078cb;
  203. }
  204. }
  205. &.is-more {
  206. height: 1.32rem;
  207. overflow: hidden;
  208. img {
  209. width: .2rem;
  210. margin-left: -.1rem;
  211. }
  212. }
  213. }
  214. }
  215. .mobile-brand-list {
  216. font-size: .3rem;
  217. .brand-initial {
  218. border-bottom: .04rem solid #418bf6;
  219. p {
  220. width: .64rem;
  221. height: .43rem;
  222. line-height: .43rem;
  223. margin: 0;
  224. background: #418bf6;
  225. color: #fff;
  226. font-size: .32rem;
  227. text-align: center;
  228. display: inline-block;
  229. border-top-left-radius: .05rem;
  230. border-top-right-radius: .05rem;
  231. }
  232. >span {
  233. font-size: .22rem;
  234. color: #999;
  235. >span {
  236. color: #418bf6;
  237. }
  238. }
  239. }
  240. .brand-items {
  241. overflow: hidden;
  242. margin-bottom: .2rem;
  243. a {
  244. overflow: hidden;
  245. display: inline-block;
  246. color: #333;
  247. border-radius: .05rem;
  248. background: #fff;
  249. margin: .18rem .42rem .12rem 0;
  250. height: .78rem;
  251. float: left;
  252. &:nth-child(3n) {
  253. margin-right: 0;
  254. }
  255. &:active {
  256. color: #418bf6;
  257. }
  258. div {
  259. width: 1.9rem;
  260. height: .39rem;
  261. line-height: .39rem;
  262. text-align: left;
  263. text-overflow: ellipsis;
  264. white-space: nowrap;
  265. overflow: hidden;
  266. &:nth-child(2) {
  267. font-size: .26rem;
  268. color: #666;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. &.is-search {
  275. width: 100%;
  276. padding-top: .5rem;
  277. .mobile-brand-header {
  278. height: auto;
  279. }
  280. .mobile-brand-list {
  281. .brand-initial {
  282. line-height: .5rem;
  283. > span {
  284. font-size: .26rem;
  285. > span {
  286. color: red;
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. </style>