box.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="cargory_all_box">
  3. <template v-if="show_type === 'all'">
  4. <div class="category_box_all" v-for="categoryItem in category" :key="categoryItem.id">
  5. <div class="category_title" @click.stop="toCategoryChild({id: categoryItem.id})">
  6. <span class="line"></span><span>{{categoryItem.name}}</span>
  7. </div>
  8. <div class="category_box flex">
  9. <div class="category_item flex box flex-col flex-a-c" v-for="item in categoryItem.children" :key="item.id"
  10. @click.stop="toCategoryChild({id: item.id})">
  11. <div class="circle">
  12. <img :src="item.thumb_src" alt=""/>
  13. </div>
  14. <div class="box_title">{{item.name}}</div>
  15. </div>
  16. <div class="no-goods" v-if="categoryItem.children.length <= 0">
  17. 暂无更多
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <div class="category_box flex" v-if="show_type === 'three'">
  23. <div class="category_item flex box flex-col flex-a-c" v-for="item in category" :key="item.id" @click="changeCategory(item)">
  24. <div class="circle">
  25. <img :src="item.thumb" alt=""/>
  26. </div>
  27. <div class="box_title">{{item.name}}</div>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import {mapState} from "vuex";
  34. export default {
  35. props: {
  36. show_type: String,
  37. category: Array
  38. },
  39. data() {
  40. return {
  41. category_template: "03"
  42. };
  43. },
  44. computed: {
  45. ...mapState(["basicSet", "basic_info"]),
  46. },
  47. mounted() {
  48. // 获取分类模板
  49. if (this.basic_info.home.item && this.basic_info.home.item.is_decorate === 1) {
  50. if (this.basic_info.home.item.ViewSet.category.is_default != 0) {
  51. this.category_template = this.basic_info.home.item.ViewSet.category.code.substring(8);
  52. } else {
  53. this.category_template = "03"
  54. }
  55. }
  56. },
  57. methods: {
  58. toCategoryChild(params) {
  59. if (this.category_template === '03') {
  60. if(this.$baseURL) {
  61. // 静态部署环境下
  62. this.$router.push(this.fun.getUrl('category_child',{}, params));
  63. }else {
  64. this.$router.push(this.fun.getUrl('category_child-id', params));
  65. }
  66. }else {
  67. if(this.$baseURL) {
  68. // 静态部署环境下
  69. this.$router.push(this.fun.getUrl('catelist',{}, params));
  70. }else {
  71. this.$router.push(this.fun.getUrl('catelist-id', params));
  72. }
  73. }
  74. },
  75. toUrl(url,params) {
  76. this.$router.push(this.fun.getUrl(url,params));
  77. },
  78. changeCategory(item) {
  79. this.$emit('changeCategory', item.id)
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. .cargory_all_box {
  86. /*padding: 20px 0;*/
  87. }
  88. .category_box_all {
  89. margin-bottom: 30px;
  90. }
  91. .category_title {
  92. cursor: pointer;
  93. padding: 5px 5px 10px 5px;
  94. font-weight: bold;
  95. display: flex;
  96. align-items: center;
  97. font-size: 18px;
  98. .line {
  99. display: inline-block;
  100. width: 3px;
  101. height: 14px;
  102. background:var(--color);
  103. margin-right: 6px;
  104. }
  105. }
  106. .category_box {
  107. flex-wrap: wrap;
  108. .box {
  109. margin: 20px;
  110. .circle {
  111. width: 70px;
  112. height: 70px;
  113. box-sizing: border-box;
  114. img {
  115. width: 100%;
  116. height: 100%;
  117. border-radius: 50%;
  118. }
  119. }
  120. .box_title {
  121. color: #4f585c;
  122. margin-top: 7px;
  123. }
  124. }
  125. .box:nth-child(10n) {
  126. margin-right: 0;
  127. }
  128. .no-goods {
  129. margin: 20px;
  130. font-size: 16px;
  131. color: var(--color);
  132. }
  133. }
  134. .category_item {
  135. cursor: pointer;
  136. }
  137. </style>