collect.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <!-- 我的收藏页面 -->
  2. <template>
  3. <view class="container" :class="{container_FF: recommendLen == 0 && collectList.length == 0}">
  4. <!-- 空白页 start-->
  5. <view v-if="!collectList.length&&loadingState != 'first_loading'" class="flex_column_start_center empty_part" :class="{empty_part_FF:recommendLen == 0 && collectList.length == 0}">
  6. <image class="img" :src="imgUrl+'empty_collect.png'" />
  7. <text class="tip_con">{{$L('暂无收藏的商品哦')}}~</text>
  8. <view class="ope_btn flex_row_center_center" @click="goGoodsList()">
  9. {{$L('马上去逛逛')}}
  10. </view>
  11. </view>
  12. <!-- 空白页 end-->
  13. <!-- 收藏的商品 start-->
  14. <view v-if='collectList.length' class="goods_list flex_column_start_start">
  15. <goodsCollectItemH v-for="(item,index) in collectList" :goods_info="item" :key='index' :isWeiXinBrower="isWeiXinBrower" @delGoods='delCollectGoods' @goShare="shareGoods1" @touchstart.native="handleTouchStart($event,item.followId)" @touchmove.native="handleTouchMove($event,item.followId)" :style="{left:is_show_btn && followId == item.followId?'-160rpx':'0'}" :left="is_show_btn && followId == item.followId"/>
  16. </view>
  17. <loadingState v-if="loadingState == 'first_loading'||collectList.length > 0" :state='loadingState'/>
  18. <!-- 收藏的商品 end-->
  19. <!-- 推荐商品 start-->
  20. <view v-if='!hasMore'>
  21. <recommendGoods ref='recomment_goods' />
  22. </view>
  23. <!-- 推荐商品 end-->
  24. <!-- 微信浏览器分享提示 start-->
  25. <view class="wx_brower_share_mask" v-if="showWeiXinBrowerTip">
  26. <view class="wx_brower_share_top_wrap">
  27. <image :src="imgUrl+'wx_share_tip.png'" mode="widthFix" @tap="closeShareModel" class="wx_brower_share_img"></image>
  28. </view>
  29. </view>
  30. <!-- 微信浏览器分享提示 end-->
  31. <!-- 分享弹框 start -->
  32. <view class="share_model" v-if="share_model" @touchmove.stop.prevent="moveHandle">
  33. <view class="share_model_list">
  34. <!-- #ifdef H5 -->
  35. <view class="share_model_pre" @tap.stop="sldShareBrower" v-if="isWeiXinBrower">
  36. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  37. <text>{{$L('微信好友')}}</text>
  38. </view>
  39. <!-- #endif -->
  40. <!-- #ifdef MP-WEIXIN -->
  41. <button open-type="share" class="share_model_pre">
  42. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  43. <text>{{$L('微信好友')}}</text>
  44. </button>
  45. <!-- #endif -->
  46. <!-- #ifdef APP-PLUS -->
  47. <view class="share_model_pre" @tap.stop="sldShare(0,'WXSceneSession')">
  48. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  49. <text>{{$L('微信好友')}}</text>
  50. </view>
  51. <view class="share_model_pre" @tap.stop="sldShare(0,'WXSenceTimeline')">
  52. <image :src="imgUrl+'goods_detail/wechat_moments.png'" mode=""></image>
  53. <text>{{$L('微信朋友圈')}}</text>
  54. </view>
  55. <!-- #endif -->
  56. </view>
  57. <view class="share_model_close" @click="closeShareModel">
  58. <image :src="imgUrl+'goods_detail/share_close.png'" mode=""></image>
  59. </view>
  60. </view>
  61. <!-- 分享弹框 end -->
  62. </view>
  63. </template>
  64. <script>
  65. import recommendGoods from "@/components/recommend-goods.vue"
  66. import goodsCollectItemH from "@/components/goods_collect_item_h.vue";
  67. import loadingState from "@/components/loading-state.vue";
  68. import {
  69. mapState
  70. } from 'vuex';
  71. export default {
  72. components: {
  73. recommendGoods,
  74. goodsCollectItemH,
  75. loadingState
  76. },
  77. data() {
  78. return {
  79. imgUrl: getApp().globalData.imgUrl,
  80. collectList: [], //收藏列表
  81. hasMore: true, //是否还有数据
  82. pageSize: 10,
  83. current: 1,
  84. loadingState: 'first_loading',
  85. share_model:false, //分享弹框
  86. isWeiXinBrower:false,//是否微信浏览器
  87. showWeiXinBrowerTip:false,//微信浏览器分享的提示操作
  88. recommendLen:0, //推荐商品的length长度
  89. followId:'',
  90. startX:'',
  91. startY:'',
  92. is_show_btn:false, //是否展示
  93. };
  94. },
  95. onLoad(option) {
  96. // #ifdef H5
  97. this.isWeiXinBrower = this.$isWeiXinBrower();
  98. // #endif
  99. // 父页面接收子组件recommend——goods.vue传过来的值
  100. uni.$on("recommendGoods",(options)=>{
  101. this.recommendLen = JSON.parse(options.recommendLen)
  102. })
  103. },
  104. onShow() {
  105. this.getList();
  106. },
  107. computed: {
  108. ...mapState(['userInfo'])
  109. },
  110. onShareAppMessage: function() {
  111. return {
  112. title: this.shareGoods.goodsName,
  113. path: '/pages/product/detail?productId='+this.shareGoods.productId+'&goodsId='+this.shareGoods.goodsId,
  114. imageUrl: this.shareGoods.goodsImage
  115. };
  116. },
  117. methods: {
  118. //浏览器分享
  119. sldShareBrower() {
  120. this.showWeiXinBrowerTip = true;
  121. this.share_model = false;
  122. this.$weiXinBrowerShare(1,{
  123. title:this.shareGoods.goodsName,
  124. desc:this.shareGoods.goodsBrief,
  125. link:this.shareGoods.shareLink,
  126. imgUrl:this.shareGoods.productImage,
  127. });
  128. },
  129. //分享 type:分享类型 0 图文 2图片,scene 场景 WXSceneSession:分享朋友 WXSenceTimeline:分享朋友圈
  130. sldShare: function(type,scene) {
  131. let shareData = {};
  132. shareData.href = this.shareGoods.shareLink;
  133. shareData.title = this.shareGoods.goodsName;
  134. shareData.summary = this.shareGoods.goodsBrief;
  135. shareData.imageUrl = this.shareGoods.productImage;
  136. this.$weiXinAppShare(type,scene,shareData);
  137. this.closeShareModel();//关闭分享
  138. },
  139. //分享当前商品
  140. shareGoods1(shareGoods){
  141. this.shareGoods = shareGoods;
  142. this.share_model = true;
  143. },
  144. //关闭分享弹框
  145. closeShareModel(){
  146. this.share_model = false;
  147. this.showWeiXinBrowerTip = false;
  148. },
  149. //获取收藏的商品
  150. getList() {
  151. let params = {};
  152. params.url = 'v3/member/front/followProduct/list';
  153. params.method = 'GET';
  154. params.data = {};
  155. params.data.pageSize = this.pageSize;
  156. params.data.current = this.current;
  157. this.loadingState = this.loadingState == 'first_loading' ? this.loadingState : 'loading';
  158. this.$request(params).then(res => {
  159. if (res.state == 200) {
  160. if (this.current == 1) {
  161. this.collectList = res.data.list;
  162. } else {
  163. this.collectList = this.collectList.concat(res.data.list);
  164. }
  165. this.collectList.map(item=>{
  166. item.is_show_btn = false
  167. })
  168. this.hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  169. if (this.hasMore) {
  170. this.current++;
  171. this.loadingState = 'allow_loading_more';
  172. } else {
  173. this.loadingState = 'no_more_data';
  174. }
  175. } else {
  176. this.$api.msg(res.msg);
  177. }
  178. }).catch((e) => {
  179. //异常处理
  180. })
  181. },
  182. //马上去逛逛事件
  183. goGoodsList() {
  184. uni.navigateTo({
  185. url: `/pages/product/list`
  186. })
  187. },
  188. //页面触底事件
  189. onReachBottom() {
  190. if (this.hasMore == false) {
  191. this.$refs.recomment_goods.getMoreData();
  192. } else {
  193. this.getList();
  194. }
  195. },
  196. //取消收藏
  197. delCollectGoods(id) {
  198. this.$request({
  199. url: 'v3/member/front/followProduct/edit',
  200. data: {
  201. key: this.userInfo.access_token,
  202. productIds: id,
  203. isCollect:false,
  204. },
  205. method: 'POST'
  206. }).then(res => {
  207. this.$api.msg(res.msg);
  208. if (res.state == 200) {
  209. //更新页面数据
  210. this.getList();
  211. }
  212. }).catch((e) => {
  213. //异常处理
  214. })
  215. },
  216. handleTouchStart(e,followId){
  217. this.startX = e.touches[0].clientX;
  218. this.startY = e.touches[0].clientY;
  219. },
  220. handleTouchMove(e,followId){
  221. // 获得当前坐标
  222. this.followId = followId
  223. this.currentX = e.touches[0].clientX;
  224. this.currentY = e.touches[0].clientY;
  225. const x = this.startX - this.currentX; //横向移动距离
  226. const y = Math.abs(this.startY - this.currentY); //纵向移动距离,若向左移动有点倾斜也可以接受
  227. if (x > 5) {
  228. //向左滑显示
  229. this.is_show_btn = true
  230. } else if (x < 5) {
  231. //向右滑隐藏
  232. this.is_show_btn = false
  233. }
  234. if(y>50 || y<-50){
  235. this.is_show_btn = false
  236. }
  237. },
  238. onPageScroll(e){
  239. this.followId = ''
  240. },
  241. }
  242. }
  243. </script>
  244. <style lang='scss'>
  245. page {
  246. width: 750rpx;
  247. margin: 0 auto;
  248. background-color: #f5f5f5;;
  249. }
  250. .container{
  251. background: $bg-color-split;
  252. }
  253. .container_FF{
  254. background: #FFFFFF;
  255. }
  256. .empty_part {
  257. display: flex;
  258. flex: 1;
  259. width: 100%;
  260. height: 516rpx;
  261. background: #fff;
  262. border-top: 20rpx solid $bg-color-split;
  263. .img {
  264. width: 210rpx;
  265. height: 210rpx;
  266. margin-bottom: 37rpx;
  267. margin-top: 88rpx;
  268. }
  269. .tip_con {
  270. color: $main-third-color;
  271. font-size: 26rpx;
  272. }
  273. .ope_btn {
  274. color: $main-color;
  275. font-size: 28rpx;
  276. padding: 0 25rpx;
  277. height: 54rpx;
  278. background: rgba(252, 28, 28, .1);
  279. border-radius: 27rpx;
  280. margin-top: 20rpx;
  281. }
  282. }
  283. .empty_part_FF{
  284. height: auto;
  285. padding-top: 200rpx;
  286. }
  287. .goods_list {
  288. border-top: 20rpx solid $bg-color-split;
  289. width: 750rpx;
  290. overflow-x: hidden;
  291. }
  292. /* 分享弹框 start */
  293. .share_model{
  294. width:750rpx;
  295. height:100%;
  296. position: fixed;
  297. top: 0;
  298. left: 0;
  299. right: 0;
  300. margin: 0 auto;
  301. background: rgba(0,0,0,0.6);
  302. z-index: 100;
  303. }
  304. .share_model_list{
  305. display: flex;
  306. justify-content: space-around;
  307. padding: 0 50rpx;
  308. box-sizing: border-box;
  309. position: fixed;
  310. bottom: 150rpx;
  311. z-index: 110;
  312. width: 750rpx;
  313. .share_model_pre{
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. background: transparent;
  318. border-radius: 0;
  319. height: auto;
  320. line-height: auto;
  321. &::after{
  322. border-width: 0;
  323. }
  324. image{
  325. width: 105rpx;
  326. height: 105rpx;
  327. }
  328. text{
  329. font-size: 24rpx;
  330. font-family: PingFang SC;
  331. font-weight: 500;
  332. color: #FFFFFF;
  333. line-height: 36rpx;
  334. margin-top: 30rpx;
  335. }
  336. }
  337. }
  338. .share_model_close{
  339. width: 46rpx;
  340. height: 46rpx;
  341. bottom: 60rpx;
  342. position: fixed;
  343. z-index: 110;
  344. left: 0;
  345. right: 0;
  346. margin: 0 auto;
  347. image{
  348. width: 46rpx;
  349. height: 46rpx;
  350. }
  351. }
  352. button{
  353. padding: 0;
  354. margin: 0;
  355. }
  356. /* 分享弹框 end */
  357. </style>