platformProducts.vue 2.2 KB

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