activity.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <view
  3. class="app-container"
  4. :style="
  5. 'background:' + (pageConfig[2] && hasData ? pageConfig[2] : '#F5F5F5')
  6. "
  7. >
  8. <view class="banner-container" v-if="pageConfig[1]">
  9. <image :src="pageConfig[1]" mode="widthFix"></image>
  10. </view>
  11. <view class="top-container">
  12. <view class="tab">
  13. <view
  14. class="item"
  15. :class="screenType === 0 ? 'current' : ''"
  16. @tap="changeScreen(0)"
  17. >综合</view
  18. >
  19. <view
  20. class="item"
  21. :class="screenType === 1 ? 'current' : ''"
  22. @tap="changeScreen(1)"
  23. >销量</view
  24. >
  25. <view
  26. class="item"
  27. :class="screenType === 2 || screenType === 3 ? 'current' : ''"
  28. @tap="changeScreen(2)"
  29. >价格
  30. <image
  31. src="@/static/icon/price_1.png"
  32. v-if="screenType === 2"
  33. ></image>
  34. <image
  35. src="@/static/icon/price_2.png"
  36. v-if="screenType === 3"
  37. ></image>
  38. <image
  39. src="@/static/icon/price_0.png"
  40. v-if="screenType != 2 && screenType != 3"
  41. ></image>
  42. </view>
  43. <view
  44. class="item"
  45. :class="screenType === 4 ? 'current' : ''"
  46. @tap="changeScreen(4)"
  47. >上架时间</view
  48. >
  49. </view>
  50. <view class="icon">
  51. <image
  52. src="@/static/icon/show_1.png"
  53. v-if="showType == 1"
  54. @tap="showType = 2"
  55. ></image>
  56. <image
  57. src="@/static/icon/show_2.png"
  58. v-if="showType == 2"
  59. @tap="showType = 1"
  60. ></image>
  61. </view>
  62. </view>
  63. <view class="goods-waterfall-list" v-show="showType == 1">
  64. <view class="left">
  65. <block v-for="(item, index) in goodsList" :key="index">
  66. <view
  67. class="item"
  68. v-if="index % 2 == 0"
  69. @tap="toGoodsDetail(item.goodsId)"
  70. >
  71. <view class="image">
  72. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  73. <image
  74. :src="item.logo"
  75. mode="aspectFill"
  76. class="water"
  77. v-if="item.isShowWater"
  78. ></image>
  79. </view>
  80. <view class="content">
  81. <view class="title ellipsis-2">{{ item.goodsName }}</view>
  82. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  83. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{
  84. it
  85. }}</view>
  86. </view>
  87. <view class="price">
  88. <view class="price-1">¥{{ item.goodsPrice | numToFixed }}</view>
  89. <view class="price-2"
  90. >¥{{ item.orgGoodsPrice | numToFixed }}</view
  91. >
  92. </view>
  93. <view class="tags2" v-if="item.tags2 && item.tags2.length > 0">
  94. <view class="it" v-for="(it, idx) in item.tags2" :key="idx">{{
  95. it
  96. }}</view>
  97. </view>
  98. <view class="text">销量:{{ item.soldNum }}</view>
  99. </view>
  100. </view>
  101. </block>
  102. </view>
  103. <view class="right">
  104. <block v-for="(item, index) in goodsList" :key="index">
  105. <view
  106. class="item"
  107. v-if="index % 2 == 1"
  108. @tap="toGoodsDetail(item.goodsId)"
  109. >
  110. <view class="image">
  111. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  112. <image
  113. :src="item.logo"
  114. mode="aspectFill"
  115. class="water"
  116. v-if="item.isShowWater"
  117. ></image>
  118. </view>
  119. <view class="content">
  120. <view class="title ellipsis-2">{{ item.goodsName }}</view>
  121. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  122. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{
  123. it
  124. }}</view>
  125. </view>
  126. <view class="price">
  127. <view class="price-1">¥{{ item.goodsPrice | numToFixed }}</view>
  128. <view class="price-2"
  129. >¥{{ item.orgGoodsPrice | numToFixed }}</view
  130. >
  131. </view>
  132. <view class="tags2" v-if="item.tags2 && item.tags2.length > 0">
  133. <view class="it" v-for="(it, idx) in item.tags2" :key="idx">{{
  134. it
  135. }}</view>
  136. </view>
  137. <view class="text">销量:{{ item.soldNum }}</view>
  138. </view>
  139. </view>
  140. </block>
  141. </view>
  142. </view>
  143. <view class="goods-row-list" v-show="showType == 2">
  144. <block v-for="(item, index) in goodsList" :key="index">
  145. <view class="item" @tap="toGoodsDetail(item.goodsId)">
  146. <view class="image">
  147. <image :src="item.imgUrl" mode="aspectFill" class="img"></image>
  148. <image
  149. :src="item.logo"
  150. mode="aspectFill"
  151. class="water"
  152. v-if="item.isShowWater"
  153. ></image>
  154. </view>
  155. <view class="right">
  156. <view>
  157. <view class="title ellipsis-2">{{ item.goodsName }}</view>
  158. <view class="tags" v-if="item.tags1 && item.tags1.length > 0">
  159. <view class="it" v-for="(it, idx) in item.tags1" :key="idx">{{
  160. it
  161. }}</view>
  162. </view>
  163. </view>
  164. <view>
  165. <view class="bottom">
  166. <view class="price">
  167. <view class="price-1"
  168. >¥{{ item.goodsPrice | numToFixed }}</view
  169. >
  170. <view class="price-2"
  171. >¥{{ item.orgGoodsPrice | numToFixed }}</view
  172. >
  173. </view>
  174. <view class="text">销量:{{ item.soldNum }}</view>
  175. </view>
  176. </view>
  177. </view>
  178. </view>
  179. </block>
  180. </view>
  181. <no-data v-if="!goodsList.length" :showText="'暂无商品'"></no-data>
  182. <loading-text
  183. v-if="goodsList.length"
  184. :loading="loading"
  185. :noMore="noMore"
  186. ></loading-text>
  187. </view>
  188. </template>
  189. <script>
  190. export default {
  191. data() {
  192. return {
  193. type: null,
  194. screenType: '',
  195. goodsList: [],
  196. pageNum: 1,
  197. pageSize: 8,
  198. noMore: false,
  199. loading: false,
  200. showType: 1,
  201. hasData: false,
  202. };
  203. },
  204. computed: {
  205. pageConfig() {
  206. const templateInfo = uni.getStorageSync('templateInfo');
  207. const MAP = {
  208. 2: [
  209. '首页弹窗',
  210. templateInfo.popupHeadImage,
  211. templateInfo.popupBackgroundColor,
  212. ],
  213. 3: [
  214. '活动专区1',
  215. templateInfo.active1HeadImage,
  216. templateInfo.active1BackgroundColor,
  217. ],
  218. 4: [
  219. '活动专区2左侧',
  220. templateInfo.active2LeftHeadImage,
  221. templateInfo.active2LeftBackgroundColor,
  222. ],
  223. 5: [
  224. '活动专区2右侧',
  225. templateInfo.active2RightHeadImage,
  226. templateInfo.active2RightBackgroundColor,
  227. ],
  228. 6: [
  229. '专场专区1',
  230. templateInfo.only1HeadImage,
  231. templateInfo.only1BackgroundColor,
  232. ],
  233. 7: [
  234. '专场专区2',
  235. templateInfo.only2HeadImage,
  236. templateInfo.only2BackgroundColor,
  237. ],
  238. 8: [
  239. '专场专区3',
  240. templateInfo.only3HeadImage,
  241. templateInfo.only3BackgroundColor,
  242. ],
  243. 9: [
  244. '专场专区4',
  245. templateInfo.only4HeadImage,
  246. templateInfo.only4BackgroundColor,
  247. ],
  248. 10: [
  249. '专题精选1',
  250. templateInfo.topics1HeadImage,
  251. templateInfo.topics1BackgroundColor,
  252. ],
  253. 11: [
  254. '专题精选2',
  255. templateInfo.topics2HeadImage,
  256. templateInfo.topics2BackgroundColor,
  257. ],
  258. 12: [
  259. '专题精选3',
  260. templateInfo.topics3HeadImage,
  261. templateInfo.topics3BackgroundColor,
  262. ],
  263. 13: [
  264. '底部广告图',
  265. templateInfo.bottomBannerHeadImage,
  266. templateInfo.bottomBannerBackgroundColor,
  267. ],
  268. };
  269. console.log(this.type ? MAP[this.type] : ['', '', '']);
  270. return this.type ? MAP[this.type] : ['', '', ''];
  271. },
  272. cuStyle() {
  273. return `height:${this.CustomBar - this.StatusBar}px; padding-top:${
  274. this.StatusBar
  275. }px;`;
  276. },
  277. },
  278. onShow() {
  279. uni.$on('hanbleShare', () => {});
  280. },
  281. onHide() {
  282. uni.$off('hanbleShare');
  283. },
  284. onLoad({ type }) {
  285. // uni.setNavigationBarTitle({
  286. //   title: cname
  287. // })
  288. this.type = type;
  289. this.getGoodsList();
  290. },
  291. // 下拉刷新
  292. onPullDownRefresh() {
  293. this.pageNum = 1;
  294. this.getGoodsList();
  295. },
  296. // 上拉加载
  297. onReachBottom() {
  298. this.getGoodsList(1);
  299. },
  300. methods: {
  301. // 获取商品列表
  302. getGoodsList(loadMore) {
  303. if (this.noMore && loadMore) return;
  304. this.noMore = false;
  305. if (!loadMore) {
  306. this.pageNum = 1;
  307. } else {
  308. this.loading = true;
  309. }
  310. this.$axios({
  311. url: '/renovation/goods/list',
  312. method: 'get',
  313. params: {
  314. pageNo: this.pageNum,
  315. pageSize: this.pageSize,
  316. type: this.type,
  317. objId: uni.getStorageSync('templateInfo').companyWechatTemplateId,
  318. sort: this.screenType,
  319. },
  320. isLoading: !loadMore,
  321. }).then((res) => {
  322. res.data.records.forEach((item) => {
  323. if (item.logo && item.logoStartTime) {
  324. item.isShowWater = this.$compareTime(
  325. item.logoStartTime,
  326. item.logoEndTime
  327. );
  328. } else {
  329. item.isShowWater = false;
  330. }
  331. });
  332. let _list = res.data.records;
  333. let pageTotal = res.data.pages;
  334. if (this.pageNum >= pageTotal) {
  335. this.noMore = true;
  336. }
  337. if (_list.length) {
  338. this.pageNum += 1;
  339. }
  340. if (loadMore) {
  341. this.goodsList = this.goodsList.concat(_list);
  342. this.loading = false;
  343. } else {
  344. this.goodsList = _list;
  345. }
  346. if (this.goodsList.length > 0) {
  347. this.hasData = true;
  348. } else {
  349. this.hasData = false;
  350. }
  351. uni.stopPullDownRefresh();
  352. });
  353. },
  354. // 切换筛选类型
  355. changeScreen(type) {
  356. if (type != 2) {
  357. if (this.screenType !== type) {
  358. this.screenType = type;
  359. } else {
  360. this.screenType = '';
  361. }
  362. } else {
  363. if (this.screenType != 2 && this.screenType != 3) {
  364. this.screenType = 2;
  365. } else if (this.screenType == 2) {
  366. this.screenType = 3;
  367. } else {
  368. this.screenType = '';
  369. }
  370. }
  371. this.pageNum = 1;
  372. this.getGoodsList();
  373. },
  374. toGoodsDetail(id) {
  375. uni.navigateTo({
  376. url: '/packageGoods/pages/detail?id=' + id,
  377. });
  378. },
  379. },
  380. };
  381. </script>
  382. <style lang="scss" scoped>
  383. .app-container {
  384. box-sizing: border-box;
  385. &.noBg {
  386. background: #f4f2f2 !important;
  387. }
  388. }
  389. .banner-container {
  390. image {
  391. width: 100%;
  392. display: block;
  393. }
  394. }
  395. .top-container {
  396. position: sticky;
  397. top: 0;
  398. left: 0;
  399. z-index: 99;
  400. width: 100%;
  401. background: #ffffff;
  402. display: flex;
  403. padding: 0 20rpx;
  404. align-items: center;
  405. box-sizing: border-box;
  406. .tab {
  407. flex: 1;
  408. display: flex;
  409. padding: 0 80rpx 0 30rpx;
  410. box-sizing: border-box;
  411. justify-content: space-between;
  412. .item {
  413. height: 88rpx;
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. font-size: 30rpx;
  418. color: #666666;
  419. &.current {
  420. color: #ff3f42;
  421. }
  422. image {
  423. width: 18rpx;
  424. height: 30rpx;
  425. display: block;
  426. margin-left: 10rpx;
  427. }
  428. }
  429. }
  430. .icon {
  431. padding-right: 10rpx;
  432. image {
  433. width: 36rpx;
  434. height: 36rpx;
  435. display: block;
  436. }
  437. }
  438. }
  439. </style>