productCenter.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="common-page">
  3. <!-- <view class="search-box" @click="toSearchList">
  4. </view> -->
  5. <u-search v-model="search" bgColor="#fff" placeholder="请输入关键词"></u-search>
  6. <FilterBar :currentCateId="cateid" @change="handleFilter"/>
  7. <view class="list-box">
  8. <CommercePart :data="data"></CommercePart>
  9. </view>
  10. <tabbarCom current="2"></tabbarCom>
  11. </view>
  12. </template>
  13. <script>
  14. import tabbarCom from "@/components/tabbar/tabbar.vue"
  15. import CommercePart from "@/components/CommercePart.vue";
  16. import FilterBar from "./filterBar.vue";
  17. import {
  18. getGoodList
  19. } from "@/common/api/good.js";
  20. export default {
  21. components: {
  22. tabbarCom,
  23. CommercePart,
  24. FilterBar
  25. },
  26. data() {
  27. return {
  28. page: 1,
  29. pageSize: 10,
  30. total: 0,
  31. search: "",
  32. sort: "",
  33. cateid: "",
  34. subCateId: '',
  35. sortType: "",
  36. data: [],
  37. };
  38. },
  39. onShow() {
  40. const currentCateid = uni.getStorageSync('currentCateid')
  41. if (currentCateid) {
  42. this.cateid = currentCateid
  43. } else {
  44. this.cateid = ""
  45. this.$nextTick(() => {
  46. this._getGoodList(true);
  47. })
  48. }
  49. },
  50. onReachBottom() {
  51. this._getGoodList();
  52. },
  53. onShareAppMessage(res) {
  54. if (res.from === 'button') { // 来自页面内分享按钮
  55. console.log(res.target)
  56. }
  57. let userInfo = uni.getStorageSync('userInfo')
  58. userInfo = userInfo && JSON.parse(userInfo) || {}
  59. let params = {}
  60. if (userInfo.id) {
  61. params = {
  62. id: userInfo.id
  63. }
  64. }
  65. let configs = uni.getStorageSync('configs') || {}
  66. return {
  67. title: configs.shop_share_title,
  68. imageUrl: configs.shop_share_img,
  69. path: `/pages/productCenter/productCenter${this.$stringPageOptions(params)}`
  70. }
  71. },
  72. onShareTimeline(res) {
  73. if (res.from === 'button') { // 来自页面内分享按钮
  74. console.log(res.target)
  75. }
  76. let userInfo = uni.getStorageSync('userInfo')
  77. userInfo = userInfo && JSON.parse(userInfo) || {}
  78. let params = {}
  79. if (userInfo.id) {
  80. params = {
  81. id: userInfo.id
  82. }
  83. }
  84. let configs = uni.getStorageSync('configs') || {}
  85. return {
  86. title: configs.shop_share_title,
  87. imageUrl: configs.shop_share_img,
  88. path: `/pages/productCenter/productCenter${this.$stringPageOptions(params)}`
  89. }
  90. },
  91. computed: {
  92. getGoodListParam() {
  93. return {
  94. cateid: this.cateid,
  95. subCateId: this.subCateId,
  96. sort: this.sort,
  97. sortType: this.sortType,
  98. name: this.search,
  99. }
  100. }
  101. },
  102. watch: {
  103. getGoodListParam() {
  104. this._getGoodList(true);
  105. },
  106. },
  107. methods: {
  108. _getGoodList(initFlag) {
  109. if (!initFlag) {
  110. if (this.page * this.pageSize < this.total) {
  111. this.page++
  112. } else {
  113. return
  114. }
  115. } else {
  116. this.page = 1
  117. this.total = 0
  118. this.data = []
  119. }
  120. let params = {
  121. cateid: this.cateid && this.subCateId ? this.subCateId : this.cateid,
  122. sort: this.sort,
  123. sortType: this.sortType,
  124. page: this.page,
  125. pageSize: this.pageSize,
  126. goods_kind: "线上商品",
  127. name: this.search,
  128. }
  129. getGoodList(params).then(({
  130. data = {}
  131. }) => {
  132. this.data = this.data.concat(data.list)
  133. this.total = data.page.total
  134. });
  135. },
  136. handleFilter({
  137. sort,
  138. sortType,
  139. cateid,
  140. subCateId
  141. }) {
  142. console.log(cateid, subCateId)
  143. this.sort = sort;
  144. this.sortType = sortType;
  145. this.cateid = cateid || "";
  146. this.subCateId = subCateId || ''
  147. },
  148. },
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. .common-page {
  153. padding: 25rpx20rpx;
  154. height: 100vh;
  155. background-color: $primary-bg-color;
  156. }
  157. </style>