type.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view class="type">
  3. <!-- 搜索框 -->
  4. <van-search :value="value" placeholder="请输入搜索关键词" />
  5. <!-- 分类选择 -->
  6. <van-tree-select :items="categoryInfoList" :main-active-index.sync="active" height="100vh" @click-nav="onClickNav">
  7. <!-- v-slot="content" => #content -->
  8. <template #content>
  9. <!-- 分类类型图片 -->
  10. <image v-if="categoryInfoList[active]" :src="categoryInfoList[active].pic"></image>
  11. <!-- 当前分类下的商品 -->
  12. <van-card
  13. v-for="(item,index) in prodList" :key="index"
  14. @click.native = "onClickItem(item)"
  15. :num="item.totalStocks"
  16. :price="item.price"
  17. :desc="item.brief"
  18. :title="item.prodName"
  19. :thumb="item.pic"
  20. ></van-card>
  21. <!-- 如果没有商品信息 -->
  22. <van-empty v-if="prodList < 0" description="当前分类没有商品" />
  23. </template>
  24. </van-tree-select>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. pageProd,
  30. categoryInfo
  31. } from '../../api/type.js'
  32. export default {
  33. data() {
  34. return {
  35. value: "",
  36. active: 0,
  37. prodList:[],
  38. categoryInfoList:[]
  39. }
  40. },
  41. onLoad() {
  42. let menu;
  43. categoryInfo().then(res => {
  44. menu = res;
  45. menu.map((item) => {
  46. item.text = item.categoryName;
  47. })
  48. this.categoryInfoList = menu;
  49. this.onClickNav();
  50. })
  51. },
  52. methods: {
  53. onClickNav(event) {
  54. let ind = event ? event.detail.index : 0;
  55. pageProd({
  56. categoryId:this.categoryInfoList[ind].categoryId
  57. }).then(res => {
  58. this.prodList = res.records;
  59. })
  60. },
  61. onClickItem(event) {
  62. uni.navigateTo({
  63. url:`/pages/detail/detail?id=${event.prodId}`
  64. })
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="less">
  70. .van-tree-select__content {
  71. image {
  72. height: 200rpx;
  73. }
  74. }
  75. </style>