小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.1 KiB

  1. <template>
  2. <view class="productSort">
  3. <div class="index">
  4. <view class="header acea-row row-center-wrapper">
  5. <view @click="goGoodSearch()" class="search acea-row row-middle">
  6. <text class="iconfont icon-xiazai5"></text>搜索商品
  7. </view>
  8. </view>
  9. </div>
  10. <view class="aside">
  11. <view
  12. class="item acea-row row-center-wrapper"
  13. :class="categoryDivindex === navActive ? 'on' : ''"
  14. v-for="(item, categoryDivindex) in category"
  15. :key="categoryDivindex"
  16. @click="asideTap(categoryDivindex)"
  17. >
  18. <text>{{ item.cateName }}</text>
  19. </view>
  20. </view>
  21. <view class="conter">
  22. <view v-for="(item, eq) in category" :key="eq">
  23. <view class="listw" v-if="eq === navActive">
  24. <view class="title acea-row row-center-wrapper" ref="title">
  25. <view class="line"></view>
  26. <view class="name">{{ item.cateName }}</view>
  27. <view class="line"></view>
  28. </view>
  29. <view class="list acea-row">
  30. <view
  31. class="item acea-row row-column row-middle"
  32. v-for="(child, categoryIndex) in item.children"
  33. :key="categoryIndex"
  34. @click="goGoodsList(child)"
  35. >
  36. <view class="picture">
  37. <image :src="child.pic" />
  38. </view>
  39. <view class="name line1">{{ child.cateName }}</view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view style="height:100rpx;"></view>
  46. </view>
  47. </template>
  48. <script>
  49. import { getCategory } from "@/api/store";
  50. import { trim } from "@/utils";
  51. export default {
  52. name: "GoodsClass",
  53. components: {},
  54. props: {},
  55. data: function() {
  56. return {
  57. category: [],
  58. navActive: 0,
  59. search: "",
  60. lock: false
  61. };
  62. },
  63. watch: {
  64. "$yroute.query.id": function(n) {
  65. if (n) {
  66. this.activeCateId(n);
  67. }
  68. }
  69. },
  70. mounted: function() {
  71. this.loadCategoryData();
  72. },
  73. methods: {
  74. goGoodSearch() {
  75. this.$yrouter.push("/pages/shop/GoodSearch/index");
  76. },
  77. goGoodsList(child) {
  78. this.$yrouter.push({
  79. path: "/pages/shop/GoodsList/index",
  80. query: { id: child.id, title: child.cateName }
  81. });
  82. },
  83. activeCateId(n) {
  84. let index = 0;
  85. n = parseInt(n);
  86. if (!n) return;
  87. this.category.forEach((cate, i) => {
  88. if (cate.id === n) index = i;
  89. });
  90. if (index !== this.navActive) {
  91. this.asideTap(index);
  92. }
  93. },
  94. loadCategoryData() {
  95. getCategory().then(res => {
  96. this.category = res.data;
  97. this.$nextTick(() => {
  98. if (this.$yroute.query.id) {
  99. this.activeCateId(this.$yroute.query.id);
  100. }
  101. });
  102. });
  103. },
  104. submitForm: function() {
  105. var val = trim(this.search);
  106. if (val) {
  107. this.$yrouter.push({
  108. path: "/pages/shop/GoodsList/index",
  109. query: { s: val }
  110. });
  111. setTimeout(() => (this.search = ""), 500);
  112. }
  113. },
  114. asideTap(index) {
  115. this.navActive = index;
  116. }
  117. }
  118. }
  119. </script>
  120. <style >
  121. .productSort {
  122. height: 100%;
  123. }
  124. </style>