type.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="type">
  3. <!-- 搜索框 -->
  4. <van-search :value="value" placeholder="请输入搜索关键词" />
  5. <!-- 分类选择 -->
  6. <van-tree-select
  7. :items="categoryList"
  8. :main-active-index="active"
  9. height="100vh"
  10. @click-nav="seleectMain"
  11. >
  12. <!-- v-slot="content" -->
  13. <template #content>
  14. <image :src="categoryList[active].pic" mode="" class="pictures"></image>
  15. <van-card
  16. v-for="(item,index) in pageProdList" :key="index"
  17. @click.native="goDetail(item)"
  18. :num="item.totalStocks"
  19. :price="item.price"
  20. :desc="item.brief"
  21. :title="item.prodName"
  22. :thumb="item.pic"
  23. ></van-card>
  24. </template>
  25. </van-tree-select>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. categoryInfo,
  31. pageProd
  32. } from '@/api/type.js'
  33. export default {
  34. data() {
  35. return {
  36. value: "",
  37. categoryList:[],
  38. active: 0,
  39. pageProdList:[]
  40. }
  41. },
  42. async onLoad() {
  43. this.categoryList = await categoryInfo();
  44. console.log(this.categoryList,'categoryList')
  45. this.categoryList.map((item) => {
  46. item.text = item.categoryName;
  47. })
  48. this.getList();
  49. },
  50. methods: {
  51. seleectMain(event) {
  52. console.log(event,'选择');
  53. this.active = event.detail.index;
  54. this.getList(this.active)
  55. },
  56. getList(event) {
  57. let index = event ? event : this.active;
  58. pageProd({
  59. categoryId: this.categoryList[index].categoryId
  60. }).then(res => {
  61. this.pageProdList = res.records;
  62. })
  63. },
  64. goDetail(event) {
  65. console.log(event,'事件')
  66. uni.navigateTo({
  67. url:`/pages/detail/detail?id=${event.prodId}`
  68. })
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="less">
  74. .van-card__img {
  75. margin-top: -4rpx;
  76. }
  77. .pictures {
  78. height: 200rpx;
  79. }
  80. </style>