myCollect.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="content">
  3. <view class="navbar">
  4. <!-- 循环出顶部nav栏 -->
  5. <view v-for="(item, index) in navList" :key="index" class="nav-item" @click="tabClick(index)">
  6. <text :class="{current: tabCurrentIndex === index}">{{item.text}}</text>
  7. </view>
  8. </view>
  9. <view class="swiper-box">
  10. <!-- 显示商品栏 -->
  11. <view v-if="tabCurrentIndex == 0" class="tab-content">
  12. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadMore">
  13. <!-- 空白页 -->
  14. <u-empty text="暂无收藏商品数据" mode="favor" v-if="goodsEmpty"></u-empty>
  15. <!-- 商品展示数据 -->
  16. <u-swipe-action @open="openLeftChange(item,index,'goods')" :show="item.selected" btn-width="180" :options="LeftOptions" v-else v-for="(item,index) in goodList"
  17. @click="clickGoodsSwiperAction(item,index)" :index="index" :key="index">
  18. <view class="goods" @click="goGoodsDetail(item)">
  19. <u-image width="131rpx" height="131rpx" :src="item.image" mode="aspectFit">
  20. <u-loading slot="loading"></u-loading>
  21. </u-image>
  22. <view class="goods-intro">
  23. <view>{{item.goodsName}}</view>
  24. <view class="goods-sn">{{item.goods_sn}}</view>
  25. <view>¥{{item.price | unitPrice}}</view>
  26. </view>
  27. </view>
  28. </u-swipe-action>
  29. <uni-load-more :status="goodsLoad"></uni-load-more>
  30. </scroll-view>
  31. </view>
  32. <!-- 显示收藏的店铺栏 -->
  33. <view v-else class="tab-content">
  34. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadMore">
  35. <!-- 空白页 -->
  36. <u-empty text="暂无收藏店铺数据" mode="favor" v-if="storeEmpty"></u-empty>
  37. <!-- 店铺展示数据 -->
  38. <u-swipe-action @open="openLeftChange(item,'store')" :show="item.selected" btn-width="180" :options="LeftOptions" v-else v-for="(item,index) in storeList" :key="index"
  39. @click="clickstoreSwiperAction(item)">
  40. <view class="store" @click="gostoreMainPage(item.storeId)">
  41. <view class="intro">
  42. <view class="store-logo">
  43. <u-image width="102rpx" height="102rpx" :src="item.logo" :alt="item.storeName" mode="aspectFit">
  44. <u-loading slot="loading"></u-loading>
  45. </u-image>
  46. </view>
  47. <view class="store-name">
  48. <view>{{item.storeName}}</view>
  49. <u-tag size="mini" type="error" :color="$mainColor" v-if="item.selfOperated" text="自营" mode="plain" shape="circle" />
  50. </view>
  51. <view class="store-collect">
  52. <view>进店逛逛</view>
  53. </view>
  54. </view>
  55. </view>
  56. </u-swipe-action>
  57. <uni-load-more :status="storeLoad"></uni-load-more>
  58. </scroll-view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. getGoodsCollection,
  66. deleteGoodsCollection,
  67. deleteStoreCollection,
  68. } from "@/api/members.js";
  69. export default {
  70. data() {
  71. return {
  72. // 商品左滑侧边栏
  73. LeftOptions: [
  74. {
  75. text: "取消",
  76. style: {
  77. backgroundColor: this.$lightColor,
  78. },
  79. },
  80. ],
  81. tabCurrentIndex: 0, //tab的下标默认为0,也就是说会默认请求商品
  82. navList: [
  83. //tab显示数据
  84. {
  85. text: "商品(0)",
  86. loadingType: "more",
  87. params: {
  88. pageNumber: 1,
  89. pageSize: 10,
  90. },
  91. },
  92. {
  93. text: "店铺(0)",
  94. loadingType: "more",
  95. params: {
  96. pageNumber: 1,
  97. pageSize: 10,
  98. },
  99. },
  100. ],
  101. goodsLoad: "more", //商品加载
  102. storeLoad: "more", //店铺加载
  103. goodsEmpty: false, //商品数据是否为空
  104. storeEmpty: false, //店铺数据是否为空
  105. goodList: [], //商品集合
  106. storeList: [], //店铺集合
  107. };
  108. },
  109. onLoad() {
  110. this.getGoodList();
  111. this.getstoreList();
  112. },
  113. methods: {
  114. /**
  115. * 打开商品左侧取消收藏
  116. */
  117. openLeftChange(val, type) {
  118. const { goodList, storeList } = this;
  119. let way;
  120. type == "goods" ? (way = goodList) : (way = storeList);
  121. way.forEach((item) => {
  122. this.$set(item, "selected", false);
  123. });
  124. this.$set(val, "selected", false);
  125. val.selected = true;
  126. },
  127. /**
  128. * 点击商品左侧取消收藏
  129. */
  130. clickGoodsSwiperAction(val) {
  131. deleteGoodsCollection(val.skuId).then((res) => {
  132. if (res.statusCode == 200) {
  133. this.storeList = [];
  134. this.goodList = [];
  135. this.getGoodList();
  136. }
  137. });
  138. },
  139. /**
  140. * 点击店铺左侧取消收藏
  141. */
  142. clickstoreSwiperAction(val) {
  143. deleteStoreCollection(val.storeId).then((res) => {
  144. if (res.statusCode == 200) {
  145. this.storeList = [];
  146. this.getstoreList();
  147. }
  148. });
  149. },
  150. /**
  151. * 顶部tab点击
  152. */
  153. tabClick(index) {
  154. this.tabCurrentIndex = index;
  155. },
  156. /**
  157. * 查看商品详情
  158. */
  159. goGoodsDetail(val) {
  160. //商品详情
  161. uni.navigateTo({
  162. url: "/pages/product/goods?id=" + val.skuId + "&goodsId=" + val.goodsId,
  163. });
  164. },
  165. /**
  166. * 查看店铺详情
  167. */
  168. gostoreMainPage(id) {
  169. //店铺主页
  170. uni.navigateTo({
  171. url: "/pages/product/shopPage?id=" + id,
  172. });
  173. },
  174. /**
  175. * 获取商品集合
  176. */
  177. getGoodList() {
  178. uni.showLoading({
  179. title: "加载中",
  180. });
  181. getGoodsCollection(this.navList[0].params, "GOODS").then((res) => {
  182. uni.hideLoading();
  183. uni.stopPullDownRefresh();
  184. if (res.data.success) {
  185. let data = res.data.result;
  186. data.selected = false;
  187. this.navList[0].text = `商品(${data.total})`;
  188. if (data.total == 0) {
  189. this.goodsEmpty = true;
  190. } else if (data.total < 10) {
  191. this.goodsLoad = "noMore";
  192. this.goodList.push(...data.records);
  193. } else {
  194. this.goodList.push(...data.records);
  195. if (data.total.length < 10) this.goodsLoad = "noMore";
  196. }
  197. }
  198. });
  199. },
  200. /**
  201. * 获取店铺集合
  202. */
  203. getstoreList() {
  204. uni.showLoading({
  205. title: "加载中",
  206. });
  207. getGoodsCollection(this.navList[1].params, "store").then((res) => {
  208. uni.hideLoading();
  209. uni.stopPullDownRefresh();
  210. if (res.data.success) {
  211. let data = res.data.result;
  212. data.selected = false;
  213. this.navList[1].text = `店铺(${data.total})`;
  214. if (data.total == 0) {
  215. this.storeEmpty = true;
  216. } else if (data.total < 10) {
  217. this.storeLoad = "noMore";
  218. this.storeList.push(...data.records);
  219. } else {
  220. this.storeList.push(...data.records);
  221. if (data.total.length < 10) this.storeLoad = "noMore";
  222. }
  223. }
  224. });
  225. },
  226. /**
  227. * 底部加载更多
  228. */
  229. loadMore() {
  230. if (this.tabCurrentIndex == 0) {
  231. this.navList[0].params.pageNumber++;
  232. this.getGoodList();
  233. } else {
  234. this.navList[1].params.pageNumber++;
  235. this.getstoreList();
  236. }
  237. },
  238. },
  239. /**
  240. * 下拉刷新时
  241. */
  242. onPullDownRefresh() {
  243. if (this.tabCurrentIndex == 0) {
  244. this.navList[0].params.pageNumber = 1;
  245. this.goodList = [];
  246. this.getGoodList();
  247. } else {
  248. this.navList[1].params.pageNumber = 1;
  249. this.storeList = [];
  250. this.getstoreList();
  251. }
  252. },
  253. };
  254. </script>
  255. <style lang="scss">
  256. page,
  257. .content {
  258. background: $page-color-base;
  259. height: 100%;
  260. }
  261. .content {
  262. width: 100%;
  263. overflow: hidden;
  264. }
  265. .swiper-box {
  266. overflow-y: auto;
  267. }
  268. .list-scroll-content {
  269. height: 100%;
  270. width: 100%;
  271. }
  272. /deep/ .u-swipe-content {
  273. overflow: hidden;
  274. }
  275. .goods {
  276. background-color: #fff;
  277. border-bottom: 1px solid $border-color-light;
  278. height: 190rpx;
  279. display: flex;
  280. align-items: center;
  281. padding: 30rpx 20rpx;
  282. margin-top: 20rpx;
  283. image {
  284. width: 131rpx;
  285. height: 131rpx;
  286. border-radius: 10rpx;
  287. }
  288. .goods-intro {
  289. flex: 1;
  290. font-size: $font-base;
  291. line-height: 48rpx;
  292. margin-left: 30rpx;
  293. view:nth-child(1) {
  294. line-height: 1.4em;
  295. font-size: 24rpx;
  296. max-height: 2.8em; //height是line-height的整数倍,防止文字显示不全
  297. overflow: hidden;
  298. color: #666;
  299. }
  300. view:nth-child(2) {
  301. color: #cccccc;
  302. font-size: 24rpx;
  303. }
  304. view:nth-child(3) {
  305. color: $light-color;
  306. }
  307. }
  308. button {
  309. color: $main-color;
  310. height: 50rpx;
  311. width: 120rpx;
  312. font-size: $font-sm;
  313. padding: 0;
  314. line-height: 50rpx;
  315. background-color: #ffffff;
  316. margin-top: 80rpx;
  317. &::after {
  318. border-color: $main-color;
  319. }
  320. }
  321. }
  322. .store {
  323. background-color: #fff;
  324. border: 1px solid $border-color-light;
  325. border-radius: 16rpx;
  326. margin: 20rpx 10rpx;
  327. .intro {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. padding: 0 30rpx 0 40rpx;
  332. height: 170rpx;
  333. .store-logo {
  334. width: 102rpx;
  335. height: 102rpx;
  336. border-radius: 50%;
  337. overflow: hidden;
  338. image {
  339. width: 100%;
  340. height: 100%;
  341. border-radius: 50%;
  342. }
  343. }
  344. .store-name {
  345. flex: 1;
  346. margin-left: 30rpx;
  347. line-height: 2em;
  348. :first-child {
  349. font-size: $font-base;
  350. }
  351. :last-child {
  352. font-size: $font-sm;
  353. color: #999;
  354. }
  355. }
  356. .store-collect {
  357. border-left: 1px solid $border-color-light;
  358. padding-left: 20rpx;
  359. text-align: center;
  360. :last-child {
  361. color: #999;
  362. font-size: $font-sm;
  363. }
  364. }
  365. }
  366. }
  367. .navbar {
  368. display: flex;
  369. height: 40px;
  370. padding: 0 5px;
  371. background: #fff;
  372. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
  373. position: relative;
  374. z-index: 10;
  375. .nav-item {
  376. flex: 1;
  377. display: flex;
  378. justify-content: center;
  379. align-items: center;
  380. height: 100%;
  381. font-size: 26rpx;
  382. text {
  383. position: relative;
  384. }
  385. text.current {
  386. color: $light-color;
  387. font-weight: bold;
  388. font-size: 28rpx;
  389. &::after {
  390. content: "";
  391. position: absolute;
  392. left: 20rpx;
  393. bottom: -10rpx;
  394. width: 30rpx;
  395. height: 0;
  396. border-bottom: 2px solid $light-color;
  397. }
  398. }
  399. }
  400. }
  401. </style>