productCenter.vue 5.7 KB

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