productCenter.vue 6.8 KB

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