platformProducts.vue 2.7 KB

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