productCenter.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view >
  3. <view style="width:100%; height: 316rpx; margin-top: 25rpx; position: relative;">
  4. <van-image src="/static/haowu-a.png" height="316rpx" width="750rpx"></van-image>
  5. <view class="goods-list" style="position: absolute; top: 124rpx;">
  6. <view class="goods-list-item" v-for="(item, index) in goodsList" :key="index" @click="toggleSelect(index,item)">
  7. <view style="height: 98rpx; display: flex; justify-content: center; align-items: center;" >
  8. <image :style="[getStyles(index)]" :src="item.logo">
  9. </image>
  10. </view>
  11. <view style="" :style="[getStylesText(index)]" >{{ item.name }}</view>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="common-page">
  16. <FilterBar :currentCateId="cateid" @change="handleFilter" />
  17. <view class="list-box">
  18. <CommercePart :data="data"></CommercePart>
  19. </view>
  20. <tabbarCom current="1"></tabbarCom>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import tabbarCom from "@/components/tabbar/tabbar.vue"
  26. import CommercePart from "@/components/CommercePart.vue";
  27. import FilterBar from "./filterBar.vue";
  28. import {
  29. getGoodList,getGoodCate
  30. } from "@/common/api/good.js";
  31. export default {
  32. components: {
  33. tabbarCom,
  34. CommercePart,
  35. FilterBar
  36. },
  37. data() {
  38. return {
  39. page: 1,
  40. pageSize: 10,
  41. total: 0,
  42. search: "",
  43. sort: "",
  44. cateid: "",
  45. subCateId: '',
  46. sortType: "",
  47. data: [],
  48. selectedIndexes: [],
  49. goodsList: [],
  50. };
  51. },
  52. onLoad() {
  53. this.getGoodCate();
  54. },
  55. onShow() {
  56. this.$nextTick(() => {
  57. this._getGoodList(true);
  58. })
  59. },
  60. onReachBottom() {
  61. this._getGoodList();
  62. },
  63. onShareAppMessage(res) {
  64. if (res.from === 'button') { // 来自页面内分享按钮
  65. }
  66. let userInfo = uni.getStorageSync('userInfo')
  67. userInfo = userInfo && JSON.parse(userInfo) || {}
  68. let params = {}
  69. if (userInfo.id) {
  70. params = {
  71. id: userInfo.id
  72. }
  73. }
  74. let configs = uni.getStorageSync('configs') || {}
  75. return {
  76. title: configs.shop_share_title,
  77. imageUrl: configs.shop_share_img,
  78. path: `/pages/productCenter/productCenter${this.$stringPageOptions(params)}`
  79. }
  80. },
  81. onShareTimeline(res) {
  82. if (res.from === 'button') { // 来自页面内分享按钮
  83. }
  84. let userInfo = uni.getStorageSync('userInfo')
  85. userInfo = userInfo && JSON.parse(userInfo) || {}
  86. let params = {}
  87. if (userInfo.id) {
  88. params = {
  89. id: userInfo.id
  90. }
  91. }
  92. let configs = uni.getStorageSync('configs') || {}
  93. return {
  94. title: configs.shop_share_title,
  95. imageUrl: configs.shop_share_img,
  96. path: `/pages/productCenter/productCenter${this.$stringPageOptions(params)}`
  97. }
  98. },
  99. computed: {
  100. getGoodListParam() {
  101. return {
  102. cateid: this.cateid,
  103. subCateId: this.subCateId,
  104. sort: this.sort,
  105. sortType: this.sortType,
  106. name: this.search,
  107. }
  108. }
  109. },
  110. watch: {
  111. getGoodListParam() {
  112. this._getGoodList(true);
  113. },
  114. },
  115. methods: {
  116. _getGoodList(initFlag) {
  117. if (!initFlag) {
  118. if (this.page * this.pageSize < this.total) {
  119. this.page++
  120. } else {
  121. return
  122. }
  123. } else {
  124. this.page = 1
  125. this.total = 0
  126. this.data = []
  127. }
  128. let params = {
  129. cateid: this.cateid && this.subCateId ? this.subCateId : this.cateid,
  130. sort: this.sort,
  131. sortType: this.sortType,
  132. goods_kind: "线上商品",
  133. page: this.page,
  134. pageSize: this.pageSize,
  135. name: this.search,
  136. }
  137. getGoodList(params).then(({
  138. data = {}
  139. }) => {
  140. this.data = this.data.concat(data.list)
  141. this.total = data.page.total
  142. });
  143. },
  144. toggleSelect(index,item) {
  145. const indexInSelected = this.selectedIndexes.indexOf(index);
  146. if (indexInSelected !== -1) {
  147. this.selectedIndexes.splice(indexInSelected, 1); // 取消选中
  148. this.cateid="0";
  149. } else {
  150. this.selectedIndexes=[]
  151. this.selectedIndexes.push(index); // 选中
  152. this.cateid=item.id;
  153. }
  154. },
  155. getStyles(index) {
  156. if (this.selectedIndexes.includes(index)) {
  157. return {width: '96rpx', height: '96rpx',borderRadius: '96rpx' ,border: '1rpx solid #C79C53'}
  158. }
  159. return {width: '88rpx', height: '88rpx',borderRadius: '88rpx'}
  160. },
  161. getStylesText(index) {
  162. if (this.selectedIndexes.includes(index)) {
  163. return {color: '#333333',marginTop: "14rpx",fontWeight: 'bold'}
  164. }
  165. return {color: '#666666',marginTop: "14rpx"}
  166. },
  167. getGoodCate() {
  168. getGoodCate().then(({
  169. data = []
  170. }) => {
  171. // 只取前五个
  172. this.goodsList = data.slice(0, 5);
  173. });
  174. },
  175. handleFilter({
  176. sort,
  177. sortType,
  178. cateid,
  179. subCateId
  180. }) {
  181. this.sort = sort;
  182. this.sortType = sortType;
  183. this.cateid = cateid || "";
  184. this.subCateId = subCateId || ''
  185. },
  186. },
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .common-page {
  191. padding: 0rpx 20rpx 25rpx 20rpx ;
  192. height: 100vh;
  193. background-color: #F8F9FA;
  194. }
  195. .goods-list {
  196. display: flex;
  197. width: 94%;
  198. flex-wrap: wrap;
  199. justify-content: flex-start;
  200. background-color: transparent;
  201. padding: 0 20rpx 0 20rpx;
  202. &-item {
  203. height: 138rpx;
  204. width: 20%;
  205. flex-shrink: 0;
  206. text-align: center;
  207. margin-bottom: 30rpx;
  208. color: #1d161f;
  209. font-family: PingFang SC, PingFang SC;
  210. font-weight: 400;
  211. font-size: 26rpx;
  212. transition: width 0.3s, height 0.3s, border 0.3s; // 添加过渡效果
  213. }
  214. }
  215. </style>