platformProducts.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="page">
  3. <u--input
  4. style="background: #f4f4f4"
  5. placeholder="搜索商品名称"
  6. shape="circle"
  7. prefixIcon="search"
  8. prefixIconStyle="font-size: 22px;color: #909399"
  9. @change="search"
  10. v-model="keyword"
  11. ></u--input>
  12. <view class="content-list" v-for="item in goodsList" :key="item.id">
  13. <GoodsInformation status="1" :itemInfo="item" @toDetail="toDetail" />
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import GoodsInformation from "../components/goodsInformation.vue";
  19. export default {
  20. components: {
  21. GoodsInformation,
  22. },
  23. data() {
  24. return {
  25. goodsList: [],
  26. page: 1,
  27. total: 0,
  28. keyword: "",
  29. };
  30. },
  31. methods: {
  32. //搜索
  33. search(e) {
  34. this.page = 0;
  35. this.getProductsList(0);
  36. },
  37. //获取平台库商品
  38. getProductsList(num) {
  39. uni.$u.http
  40. .post(`/api/goods/platform_goods`, {
  41. page: this.page,
  42. limit: 10,
  43. keyword: this.keyword,
  44. })
  45. .then((res) => {
  46. if (num) {
  47. //判断是否为触底加载 不是直接赋值,是则连接两个数组
  48. if (this.goodsList.length == 0) {
  49. this.goodsList = res.data;
  50. } else {
  51. this.goodsList = this.goodsList.concat(res.data);
  52. }
  53. } else {
  54. this.goodsList = res.data;
  55. }
  56. this.total = res.total;
  57. //循环数组
  58. this.goodsList.map((item) => {
  59. let arr = [];
  60. item.labels = [];
  61. //将标签名称单独取出,在子组件中使用
  62. if (item.label_arr.length > 0) {
  63. item.label_arr.forEach((items) => {
  64. arr.push(items.name_cn);
  65. });
  66. item.labels = arr;
  67. }
  68. });
  69. });
  70. },
  71. toDetail(value) {
  72. uni.navigateTo({
  73. url: `/pageD/productDetails/productDetails?goodsId=${value.id}&pageStatus=platform`,
  74. });
  75. },
  76. },
  77. onReachBottom() {
  78. //商品总数量小于当前获取到的商品数量
  79. if (this.total > this.goodsList.length) {
  80. this.page++;
  81. this.getProductsList(1);
  82. }
  83. },
  84. mounted() {
  85. this.getProductsList(0);
  86. uni.setNavigationBarTitle({
  87. title: "平台商品库",
  88. });
  89. },
  90. };
  91. </script>
  92. <style scoped lang="scss">
  93. .page {
  94. background-color: #fff;
  95. padding: 20rpx 24rpx;
  96. .content-list {
  97. margin-top: 20rpx;
  98. }
  99. ::v-deep .u-input {
  100. background-color: #f4f4f4;
  101. }
  102. }
  103. </style>