history.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <!-- 我的足迹页面 -->
  2. <template>
  3. <view class="container" :class="{container_FF: recommendLen == 0 && historyList.length == 0}">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <uni-nav-bar fixed='true' color='#333' status-bar='true' :left-icon="nav_left_icon" :right-text="topRightText" title="我的足迹"
  6. @clickRight='clearHistory' @clickLeft="goBack"></uni-nav-bar>
  7. <!-- #endif -->
  8. <!-- #ifdef MP-WEIXIN -->
  9. <view class="clear_history" v-if="historyList.length > 0">
  10. <view class="clear_history_text" v-if="settings && settings.length > 0">
  11. <image :src="settings[1]" mode="" v-if="settings[1]"></image>
  12. <text v-if="settings[0]">{{settings[0]}}</text>
  13. </view>
  14. <view class="clear_history_btn" @click="clearHistory">{{$L('清空')}}</view>
  15. </view>
  16. <!-- #endif-->
  17. <!-- 空白页 start-->
  18. <view v-if="!historyList.length&&loadingState != 'first_loading'" class="flex_column_start_center empty_part" :class="{empty_part_FF:recommendLen == 0 && historyList.length == 0}">
  19. <image class="img" :src="imgUrl+'empty_footprint.png'" />
  20. <text class="tip_con">{{$L('暂无浏览的足迹哦')}}~</text>
  21. <view class="ope_btn flex_row_center_center" @click="goGoodsList()">
  22. {{$L('马上去逛逛')}}
  23. </view>
  24. </view>
  25. <!-- 空白页 end-->
  26. <!-- 足迹里的商品 start-->
  27. <view v-if='historyList.length' class="goods_list flex_column_start_start">
  28. <view class="history_item flex_column_start_start" v-for="(item,index) in historyList" :key='index'>
  29. <view class="time_tag flex_row_center_center">
  30. {{item.time}}
  31. </view>
  32. <goodsHistoryItemH v-for="(item_goods,index_goods) in item.productLookLogInfoList" :key='index_goods' :goods_info="item_goods" :isWeiXinBrower="isWeiXinBrower"
  33. @delGoods='delHistoryGoods' :goods_index='index_goods' :item_index='index_goods' @goShare="shareGoods1" @touchstart.native="handleTouchStart($event,item_goods.followId)" @touchmove.native="handleTouchMove($event,item_goods.followId)" :style="{left:is_show_btn && followId == item_goods.followId?'-160rpx':'0'}" :left="is_show_btn && followId == item_goods.followId"/>
  34. </view>
  35. </view>
  36. <loadingState v-if="loadingState == 'first_loading'||historyList.length > 0" :state='loadingState' :showEndFlag='showEndFlag' />
  37. <!-- 足迹里的商品 end-->
  38. <!-- 推荐商品 start-->
  39. <view v-if='!hasMore || !historyList.length'>
  40. <recommendGoods ref='recomment_goods' />
  41. </view>
  42. <!-- 推荐商品 end-->
  43. <uni-popup ref="popup" type="dialog">
  44. <uni-popup-dialog type="input" :title="$L('提示')" :content="$L('确定清空浏览记录吗?')" :duration="2000" before-close="true" @close="cancleEmpty"
  45. @confirm="confirmEmpty"></uni-popup-dialog>
  46. </uni-popup>
  47. <!-- 微信浏览器分享提示 start-->
  48. <view class="wx_brower_share_mask" v-if="showWeiXinBrowerTip">
  49. <view class="wx_brower_share_top_wrap">
  50. <image :src="imgUrl+'wx_share_tip.png'" mode="widthFix" @tap="closeShareModel" class="wx_brower_share_img"></image>
  51. </view>
  52. </view>
  53. <!-- 微信浏览器分享提示 end-->
  54. <!-- 分享弹框 start -->
  55. <view class="share_model" v-if="share_model" @touchmove.stop.prevent="moveHandle">
  56. <view class="share_model_list">
  57. <!-- #ifdef H5 -->
  58. <view class="share_model_pre" @tap.stop="sldShareBrower" v-if="isWeiXinBrower">
  59. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  60. <text>{{$L('微信好友')}}</text>
  61. </view>
  62. <!-- #endif -->
  63. <!-- #ifdef MP-WEIXIN -->
  64. <button open-type="share" class="share_model_pre">
  65. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  66. <text>{{$L('微信好友')}}</text>
  67. </button>
  68. <!-- #endif -->
  69. <!-- #ifdef APP-PLUS -->
  70. <view class="share_model_pre" @tap.stop="sldShare(0,'WXSceneSession')">
  71. <image :src="imgUrl+'goods_detail/wx_share.png'" mode=""></image>
  72. <text>{{$L('微信好友')}}</text>
  73. </view>
  74. <view class="share_model_pre" @tap.stop="sldShare(0,'WXSenceTimeline')">
  75. <image :src="imgUrl+'goods_detail/wechat_moments.png'" mode=""></image>
  76. <text>{{$L('微信朋友圈')}}</text>
  77. </view>
  78. <!-- #endif -->
  79. </view>
  80. <view class="share_model_close" @click="closeShareModel">
  81. <image :src="imgUrl+'goods_detail/share_close.png'" mode=""></image>
  82. </view>
  83. </view>
  84. <!-- 分享弹框 end -->
  85. </view>
  86. </template>
  87. <script>
  88. import recommendGoods from "@/components/recommend-goods.vue"
  89. import goodsHistoryItemH from "@/components/goods_history_item_h.vue";
  90. import loadingState from "@/components/loading-state.vue";
  91. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  92. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
  93. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  94. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
  95. import {
  96. mapState
  97. } from 'vuex';
  98. export default {
  99. components: {
  100. recommendGoods,
  101. goodsHistoryItemH,
  102. loadingState,
  103. uniPopup,
  104. uniPopupMessage,
  105. uniPopupDialog,
  106. uniNavBar
  107. },
  108. data() {
  109. return {
  110. imgUrl: getApp().globalData.imgUrl,
  111. historyList: [], //足迹列表
  112. hasMore: true, //是否还有数据
  113. pageSize: 10,
  114. current: 1,
  115. loadingState: 'first_loading',
  116. showEndFlag: true, //设置为false则不展示最后的加载完成提示
  117. settings:[], //配置信息
  118. topRightText:'清空',
  119. nav_left_icon: 'back', //底部tab进入的话为空,否则为back
  120. share_model:false, //分享弹框
  121. isWeiXinBrower:false,//是否微信浏览器
  122. showWeiXinBrowerTip:false,//微信浏览器分享的提示操作
  123. recommendLen:0, //推荐商品的length长度
  124. followId:'',
  125. startX:'',
  126. startY:'',
  127. is_show_btn:false, //是否展示
  128. };
  129. },
  130. onLoad(option) {
  131. this.getSettings();
  132. // #ifdef H5
  133. this.isWeiXinBrower = this.$isWeiXinBrower();
  134. // #endif
  135. // 父页面接收子组件recommend——goods.vue传过来的值
  136. uni.$on("recommendGoods",(options)=>{
  137. this.recommendLen = JSON.parse(options.recommendLen)
  138. })
  139. },
  140. onShow(option){
  141. this.getList();
  142. },
  143. computed: {
  144. ...mapState(['userInfo'])
  145. },
  146. onShareAppMessage: function() {
  147. setTimeout(()=>{
  148. this.share_model=false;
  149. },1000);
  150. return {
  151. title: this.shareGoods.goodsName,
  152. path: '/pages/product/detail?productId='+this.shareGoods.productId+'&goodsId='+this.shareGoods.goodsId,
  153. imageUrl: this.shareGoods.goodsImage
  154. };
  155. },
  156. methods: {
  157. //浏览器分享
  158. sldShareBrower() {
  159. this.showWeiXinBrowerTip = true;
  160. this.share_model = false;
  161. this.$weiXinBrowerShare(1,{
  162. title:this.shareGoods.goodsName,
  163. desc:this.shareGoods.goodsBrief,
  164. link:this.shareGoods.shareLink,
  165. imgUrl:this.shareGoods.goodsImage,
  166. });
  167. },
  168. //分享 type:分享类型 0 图文 2图片,scene 场景 WXSceneSession:分享朋友 WXSenceTimeline:分享朋友圈
  169. sldShare: function(type,scene) {
  170. let shareData = {};
  171. shareData.href = this.shareGoods.shareLink;
  172. shareData.title = this.shareGoods.goodsName;
  173. shareData.summary = this.shareGoods.goodsBrief;
  174. shareData.imageUrl = this.shareGoods.goodsImage;
  175. this.$weiXinAppShare(type,scene,shareData);
  176. this.closeShareModel();//关闭分享
  177. },
  178. //分享当前商品
  179. shareGoods1(shareGoods){
  180. this.shareGoods = shareGoods;
  181. this.share_model = true;
  182. },
  183. //关闭分享弹框
  184. closeShareModel(){
  185. this.share_model = false;
  186. this.showWeiXinBrowerTip = false;
  187. },
  188. //清空足迹
  189. clearHistory(){
  190. this.$refs.popup.open();
  191. },
  192. //获取足迹里的商品
  193. getList() {
  194. let params = {};
  195. params.url = 'v3/member/front/productLookLog/list';
  196. params.method = 'GET';
  197. params.data = {};
  198. params.data.pageSize = this.pageSize;
  199. params.data.current = this.current;
  200. this.loadingState = this.loadingState == 'first_loading' ? this.loadingState : 'loading';
  201. this.$request(params).then(res => {
  202. if (res.state == 200) {
  203. if (this.current == 1) {
  204. this.historyList = res.data.list;
  205. } else {
  206. this.historyList = this.historyList.concat(res.data.list);
  207. }
  208. this.hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  209. if (this.hasMore) {
  210. this.current++;
  211. this.loadingState = 'allow_loading_more';
  212. } else {
  213. this.loadingState = 'no_more_data';
  214. }
  215. if(this.historyList.length > 0){
  216. this.topRightText = '清空'
  217. }else{
  218. this.topRightText = ''
  219. }
  220. } else {
  221. this.$api.msg(res.msg);
  222. }
  223. }).catch((e) => {
  224. //异常处理
  225. })
  226. },
  227. //马上去逛逛事件
  228. goGoodsList() {
  229. uni.navigateTo({
  230. url: `/pages/product/list`
  231. })
  232. },
  233. //页面触底事件
  234. onReachBottom() {
  235. if (this.hasMore == false) {
  236. this.$refs.recomment_goods.getMoreData();
  237. } else {
  238. this.getList();
  239. }
  240. },
  241. //删除足迹
  242. delHistoryGoods(itemIndex, goodsIndex, id) {
  243. this.$request({
  244. url: 'v3/member/front/productLookLog/del',
  245. data: {
  246. logIds: id
  247. },
  248. method: 'POST'
  249. }).then(res => {
  250. this.$api.msg(res.msg);
  251. if (res.state == 200) {
  252. //更新页面数据
  253. // this.historyList = []
  254. if(this.current!=1){
  255. this.current-=1
  256. }
  257. this.getList();
  258. // if (this.historyList[itemIndex].productLookLogInfoList.length > 1) {
  259. // //只删除商品
  260. // this.historyList[itemIndex].productLookLogInfoList.splice(goodsIndex, 1);
  261. // } else {
  262. // //商品商品和日期
  263. // this.historyList.splice(itemIndex, 1);
  264. // }
  265. // if (this.historyList.length == 4) {
  266. // this.getList();
  267. // }
  268. }
  269. }).catch((e) => {
  270. //异常处理
  271. })
  272. },
  273. //取消清空足迹
  274. cancleEmpty() {
  275. this.$refs.popup.close();
  276. },
  277. //确认清空足迹事件
  278. confirmEmpty() {
  279. this.$request({
  280. url: 'v3/member/front/productLookLog/empty',
  281. method: 'GET'
  282. }).then(res => {
  283. this.$api.msg(res.msg);
  284. if (res.state == 200) {
  285. //更新页面数据
  286. this.historyList = [];
  287. this.topRightText = '';
  288. }
  289. this.cancleEmpty();
  290. }).catch((e) => {
  291. //异常处理
  292. })
  293. },
  294. //获取配置信息接口
  295. getSettings(){
  296. this.$request({
  297. url: 'v3/system/front/setting/getSettings',
  298. data: {
  299. names: 'basic_site_name,main_site_logo'
  300. },
  301. method: 'GET'
  302. }).then(res => {
  303. if (res.state == 200) {
  304. //更新页面数据
  305. this.settings = res.data || [];
  306. }
  307. }).catch((e) => {
  308. this.$api.msg(res.msg);
  309. //异常处理
  310. })
  311. },
  312. //返回上一页
  313. goBack(){
  314. uni.navigateBack()
  315. },
  316. handleTouchStart(e,followId){
  317. this.startX = e.touches[0].clientX;
  318. this.startY = e.touches[0].clientY;
  319. },
  320. handleTouchMove(e,followId){
  321. // 获得当前坐标
  322. this.followId = followId
  323. this.currentX = e.touches[0].clientX;
  324. this.currentY = e.touches[0].clientY;
  325. const x = this.startX - this.currentX; //横向移动距离
  326. const y = Math.abs(this.startY - this.currentY); //纵向移动距离,若向左移动有点倾斜也可以接受
  327. if (x > 5) {
  328. //向左滑显示
  329. this.is_show_btn = true
  330. } else if (x < 5) {
  331. //向右滑隐藏
  332. this.is_show_btn = false
  333. }
  334. if(y>50 || y<-50){
  335. this.is_show_btn = false
  336. }
  337. },
  338. onPageScroll(e){
  339. this.followId = ''
  340. },
  341. }
  342. }
  343. </script>
  344. <style lang='scss'>
  345. page {
  346. width: 750rpx;
  347. margin: 0 auto;
  348. }
  349. .container{
  350. background: $bg-color-split;
  351. }
  352. .container_FF{
  353. background: #FFFFFF;
  354. }
  355. .clear_history{
  356. background: #FFFFFF;
  357. padding: 30rpx;
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: center;
  361. .clear_history_text{
  362. display: flex;
  363. align-items: center;
  364. image{
  365. width: 32rpx;
  366. height: 32rpx;
  367. margin-right: 10rpx;
  368. }
  369. text{
  370. font-size: 28rpx;
  371. }
  372. }
  373. .clear_history_btn{
  374. font-size: 28rpx;
  375. }
  376. }
  377. .empty_part {
  378. display: flex;
  379. flex: 1;
  380. width: 100%;
  381. height: 516rpx;
  382. background: #fff;
  383. border-top: 20rpx solid $bg-color-split;
  384. .img {
  385. width: 210rpx;
  386. height: 210rpx;
  387. margin-bottom: 37rpx;
  388. margin-top: 88rpx;
  389. }
  390. .tip_con {
  391. color: $main-third-color;
  392. font-size: 26rpx;
  393. }
  394. .ope_btn {
  395. color: $main-color;
  396. font-size: 28rpx;
  397. padding: 0 25rpx;
  398. height: 54rpx;
  399. background: rgba(252, 28, 28, .1);
  400. border-radius: 27rpx;
  401. margin-top: 20rpx;
  402. }
  403. }
  404. .empty_part_FF{
  405. height: auto;
  406. padding-top: 200rpx;
  407. }
  408. .goods_list {
  409. .history_item {
  410. border-top: 20rpx solid $bg-color-split;
  411. background: #fff;
  412. overflow: hidden;
  413. .time_tag {
  414. margin: 20rpx 0;
  415. /* width: 137rpx; */
  416. padding: 5rpx 10rpx;
  417. height: 40rpx;
  418. background: rgba(252, 28, 28, .05);
  419. border-radius: 0 20rpx 20rpx 0;
  420. color: $main-color;
  421. font-size: 28rpx;
  422. line-height: 40rpx;
  423. }
  424. }
  425. }
  426. /* 分享弹框 start */
  427. .share_model{
  428. width:750rpx;
  429. height:100%;
  430. position: fixed;
  431. top: 0;
  432. left: 0;
  433. right: 0;
  434. margin: 0 auto;
  435. background: rgba(0,0,0,0.6);
  436. z-index: 100;
  437. }
  438. .share_model_list{
  439. display: flex;
  440. justify-content: space-around;
  441. padding: 0 50rpx;
  442. box-sizing: border-box;
  443. position: fixed;
  444. bottom: 150rpx;
  445. z-index: 110;
  446. width: 750rpx;
  447. .share_model_pre{
  448. display: flex;
  449. flex-direction: column;
  450. align-items: center;
  451. background: transparent;
  452. border-radius: 0;
  453. height: auto;
  454. line-height: auto;
  455. &::after{
  456. border-width: 0;
  457. }
  458. image{
  459. width: 105rpx;
  460. height: 105rpx;
  461. }
  462. text{
  463. font-size: 24rpx;
  464. font-family: PingFang SC;
  465. font-weight: 500;
  466. color: #FFFFFF;
  467. line-height: 36rpx;
  468. margin-top: 30rpx;
  469. }
  470. }
  471. }
  472. .share_model_close{
  473. width: 46rpx;
  474. height: 46rpx;
  475. bottom: 60rpx;
  476. position: fixed;
  477. z-index: 110;
  478. left: 0;
  479. right: 0;
  480. margin: 0 auto;
  481. image{
  482. width: 46rpx;
  483. height: 46rpx;
  484. }
  485. }
  486. button{
  487. padding: 0;
  488. margin: 0;
  489. }
  490. /* 分享弹框 end */
  491. uni-page-body {
  492. display: flex;
  493. height: 100%;
  494. }
  495. </style>