categroy-sidebar.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <!-- 分类筛选 -->
  3. <div
  4. :class="[
  5. 'categroy',
  6. (fixedCate ? 'fixed' : '') || (notIndexFixed ? 'fixed2' : ''),
  7. notIndex ? 'shorttop' : ''
  8. ]"
  9. :style="{width:$t('language')==='en'?'120px':''}"
  10. >
  11. <div class="tit">{{$t('categroyCommon.categoryFilter')}}</div>
  12. <div class="con">
  13. <div
  14. class="item"
  15. v-for="(firstCategroy, index) in categoryList"
  16. :key="index"
  17. v-on:mouseover="
  18. onMenuTab(mouseIndex++, index, firstCategroy.categoryId)
  19. "
  20. v-on:mouseout="
  21. onMenuTabOut(mouseIndex - 1, index, firstCategroy.categoryId)
  22. "
  23. >
  24. <div class='firstCategroyBox'
  25. @click.stop="
  26. toCatePage(
  27. firstCategroy.categoryId,
  28. null,
  29. null,
  30. 0
  31. )"
  32. >
  33. <span class="icon">
  34. <img :src="firstCategroy.icon" alt />
  35. </span>
  36. <!-- 图标 -->
  37. <span class="name"
  38. >{{ firstCategroy.categoryName }}</span>
  39. </div>
  40. <div class="select">
  41. <div class="sort">
  42. <div v-for="(subCate, index) in subCategoryList" :key="index">
  43. <!-- @click="toCatePage(subCate.parentId,subCate.categoryId)" -->
  44. <!-- <div class="item-img">
  45. <img :src="subCate.pic" alt />
  46. </div>-->
  47. <div class="select-title">{{ subCate.categoryName }}</div>
  48. <div class="select-item-wrapper">
  49. <div
  50. v-for="(threeCate, index) in subCate.categories"
  51. :key="index"
  52. @click="
  53. toCatePage(
  54. firstCategroy.categoryId,
  55. subCate.categoryId,
  56. threeCate.categoryId,
  57. 0
  58. )
  59. "
  60. class="select-item"
  61. >
  62. <div class="item-img">
  63. <img :src="threeCate.pic" alt />
  64. </div>
  65. <div class="item-name">{{ threeCate.categoryName }}</div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. <!-- <div class="phone-code">
  74. <div class="code">
  75. <div id="qrcode2"></div>
  76. <img src="~/assets/images/mobile-code.png" alt />
  77. </div>
  78. <div class="text">{{$t('categroyCommon.h5Mall')}}</div>
  79. </div> -->
  80. </div>
  81. <!-- /分类筛选 -->
  82. </template>
  83. <script>
  84. import { h5Path } from '~/plugins/config'
  85. export default {
  86. data () {
  87. return {
  88. backgroundPositionX: 'backgroundPositionX',
  89. backgroundPositionY: 'backgroundPositionY',
  90. fixedCate: false,
  91. categoryList: [], //父分类列表
  92. subCategoryList: [], //子分类列表
  93. notIndex: false, //当前非首页
  94. notIndexFixed: false, //当前非首页
  95. mouseoverEventList: [],
  96. mouseIndex: 0,
  97. }
  98. },
  99. mounted () {
  100. document.title = this.$t('commonHead.productList')
  101. // 监听页面滚动
  102. window.addEventListener('scroll', this.scrollToTop);
  103. this.getCategoryList() //一级分类列表
  104. //如果当前处在非首页,则分类侧栏增加一个class
  105. window.location.pathname != '/' ? this.notIndex = true : this.notIndex = false
  106. // this.$nextTick(() => {
  107. // this.loadQRCode()
  108. // })
  109. },
  110. methods: {
  111. /**
  112. * 生成二维码
  113. */
  114. loadQRCode () {
  115. let qrcode = new QRCode('qrcode2', {
  116. text: h5Path,
  117. width: 90,
  118. height: 90,
  119. colorDark: '#000000',
  120. colorLight: '#ffffff',
  121. correctLevel: 3
  122. })
  123. },
  124. /**
  125. * 页面滚动事件
  126. */
  127. scrollToTop () {
  128. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  129. if (window.location.pathname == '/') {
  130. this.fixedCate = scrollTop > 500 ? true : false
  131. } else {
  132. this.notIndexFixed = scrollTop > 130 ? true : false
  133. }
  134. },
  135. /**
  136. * 加载父分类列表
  137. */
  138. getCategoryList () {
  139. this.$axios.get('/category/categoryInfo?parentId=' + '')
  140. .then(({ data }) => {
  141. this.categoryImg = data[0].pic,
  142. this.categoryList = data
  143. this.getProdList(data[0].categoryId)
  144. })
  145. },
  146. /**
  147. * 分类点击事件,获取子分类
  148. */
  149. onMenuTab (mouseIndex, index, id) {
  150. var _this = this
  151. var timeout = setTimeout(() => {
  152. this.getProdList(this.categoryList[index].categoryId);
  153. this.categoryImg = this.categoryList[index].pic,
  154. this.selIndex = index
  155. }, 100)
  156. var eventData = {
  157. index, id,
  158. eventTime: new Date().getTime(),
  159. timeout: timeout
  160. }
  161. this.mouseoverEventList.push(eventData)
  162. },
  163. onMenuTabOut () {
  164. var eventData = this.mouseoverEventList.shift()
  165. // var eventData = this.mouseoverEventList[mouseIndex]
  166. if (new Date().getTime() - eventData.eventTime < 100) {
  167. clearTimeout(eventData.timeout)
  168. }
  169. },
  170. /**
  171. * 加载子分类列表
  172. */
  173. getProdList (categoryId) {
  174. this.$axios.get('/category/categoryInfo?parentId=' + categoryId)
  175. .then(({ data }) => {
  176. this.subCategoryList = data
  177. })
  178. },
  179. /**
  180. * 跳转子分类商品页面 */
  181. toCatePage: function (parentId, categoryId, thCategoryId, st) {
  182. // this.$router.push({ path: '/list?cpid=' + parentId + "&cid=" + categoryId + "&thCid=" + thCategoryId + "&st=" + st })
  183. console.log('跳转和艰苦拉萨机打开拉萨角度来看');
  184. this.$router.push({
  185. path: '/list',
  186. query: {
  187. cpid: parentId,
  188. cid: categoryId,
  189. thCid: thCategoryId,
  190. st: st
  191. }
  192. })
  193. },
  194. },
  195. destroyed () {
  196. // 页面销毁时移除监听
  197. window.removeEventListener('scroll', this.scrollToTop);
  198. }
  199. }
  200. </script>
  201. <style scoped>
  202. /* 分类侧栏位置 */
  203. .fixed {
  204. position: fixed;
  205. top: 130px;
  206. }
  207. .fixed2 {
  208. position: fixed;
  209. top: 100px;
  210. }
  211. .categroy .phone-code .code{
  212. width: 90px;
  213. }
  214. .categroy .con .item .select {
  215. width: auto;
  216. max-height: 700px;
  217. }
  218. .categroy .con .item .select .sort {
  219. max-height: 700px;
  220. overflow: auto;
  221. }
  222. @media screen and ( max-width: 1366px ){
  223. .categroy .con .item .select {
  224. left:90px;
  225. }
  226. .categroy{
  227. width:71px;
  228. top: 60px;
  229. position: fixed !important;
  230. }
  231. .categroy .con .item{
  232. padding-top: 10px;
  233. }
  234. .fixed{
  235. top: 60px;
  236. }
  237. .fixed2{
  238. top: 45px;
  239. }
  240. .categroy .con .item .name{
  241. width: 100%;
  242. margin-left: 0;
  243. }
  244. }
  245. .select-title {
  246. cursor: default;
  247. }
  248. </style>