You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

343 lines
9.6 KiB

6 months ago
  1. <template>
  2. <view>
  3. <view class="list">
  4. <!-- 收藏列表 -->
  5. <view class="sub-list goods" :class="subState">
  6. <!-- 空白页 -->
  7. <empty v-if="goodsList.length === 0" tip='无收藏'></empty>
  8. <view class="row" v-for="(row,index) in goodsList" :key="index" >
  9. <!-- 删除按钮 -->
  10. <view class="menu" @tap.stop="deleteCoupon(row.cpid,goodsList)">
  11. <view class="icon shanchu"></view>
  12. </view>
  13. <!-- content -->
  14. <view class="carrier" :class="[typeClass=='goods'?theIndex==index?'open':oldIndex==index?'close':'':'']" @touchstart="touchStart(index,$event)" @touchmove="touchMove(index,$event)" @touchend="touchEnd(index,$event)" @click="navTo('/pages/product/product?cpid='+row.cpid)" >
  15. <view class="goods-info">
  16. <view class="img">
  17. <image :src="row.img"></image>
  18. </view>
  19. <view class="info">
  20. <view class="title">{{row.mc}}</view>
  21. <view class="price-number">
  22. <view class="keep-num">
  23. 收藏于{{row.createtime}}
  24. </view>
  25. <!-- <view class="price">{{row.price}}</view> -->
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import empty from "@/components/empty";
  37. export default {
  38. components: {
  39. empty
  40. },
  41. data() {
  42. return {
  43. goodsList:[],
  44. headerTop:0,
  45. //控制滑动效果
  46. typeClass:'goods',
  47. subState:'',
  48. theIndex:null,
  49. oldIndex:null,
  50. isStop:false,
  51. uid:0
  52. }
  53. },
  54. onPageScroll(e){
  55. },
  56. //下拉刷新,需要自己在page.json文件中配置开启页面下拉刷新 "enablePullDownRefresh": true
  57. onPullDownRefresh() {
  58. setTimeout(function () {
  59. uni.stopPullDownRefresh();
  60. }, 1000);
  61. },
  62. onLoad() {
  63. //兼容H5下排序栏位置
  64. // #ifdef H5
  65. //定时器方式循环获取高度为止,这么写的原因是onLoad中head未必已经渲染出来。
  66. let Timer = setInterval(()=>{
  67. let uniHead = document.getElementsByTagName('uni-page-head');
  68. if(uniHead.length>0){
  69. this.headerTop = uniHead[0].offsetHeight+'px';
  70. clearInterval(Timer);//清除定时器
  71. }
  72. },1);
  73. // #endif
  74. //获取当前用户信息
  75. let getuserinfo=uni.getStorageSync('userinfo');
  76. this.uid=getuserinfo.uid;
  77. uni.showLoading({title:'加载中'})
  78. this.collectionlist()
  79. },
  80. onShow(){
  81. this.collectionlist()
  82. },
  83. methods: {
  84. async collectionlist() {
  85. let userinfo=uni.getStorageSync('userinfo');
  86. let redata=await this.$api.collectionlist({action:'collectionlist',uid:userinfo.uid});
  87. this.goodsList=redata.data;
  88. uni.hideLoading()
  89. },
  90. switchType(type){
  91. if(this.typeClass==type){
  92. return ;
  93. }
  94. uni.pageScrollTo({
  95. scrollTop:0,
  96. duration:0
  97. })
  98. this.typeClass = type;
  99. this.subState = this.typeClass==''?'':'show'+type;
  100. setTimeout(()=>{
  101. this.oldIndex = null;
  102. this.theIndex = null;
  103. this.subState = this.typeClass=='goods'?'':this.subState;
  104. },200)
  105. },
  106. //控制左滑删除效果-begin
  107. touchStart(index,event){
  108. //多点触控不触发
  109. if(event.touches.length>1){
  110. this.isStop = true;
  111. return ;
  112. }
  113. this.oldIndex = this.theIndex;
  114. this.theIndex = null;
  115. //初始坐标
  116. this.initXY = [event.touches[0].pageX,event.touches[0].pageY];
  117. },
  118. touchMove(index,event){
  119. //多点触控不触发
  120. if(event.touches.length>1){
  121. this.isStop = true;
  122. return ;
  123. }
  124. let moveX = event.touches[0].pageX - this.initXY[0];
  125. let moveY = event.touches[0].pageY - this.initXY[1];
  126. if(this.isStop||Math.abs(moveX)<5){
  127. return ;
  128. }
  129. if (Math.abs(moveY) > Math.abs(moveX)){
  130. // 竖向滑动-不触发左滑效果
  131. this.isStop = true;
  132. return;
  133. }
  134. if(moveX<0){
  135. this.theIndex = index;
  136. this.isStop = true;
  137. }else if(moveX>0){
  138. if(this.theIndex!=null&&this.oldIndex==this.theIndex){
  139. this.oldIndex = index;
  140. this.theIndex = null;
  141. this.isStop = true;
  142. setTimeout(()=>{
  143. this.oldIndex = null;
  144. },150)
  145. }
  146. }
  147. },
  148. touchEnd(index,$event){
  149. //解除禁止触发状态
  150. this.isStop = false;
  151. },
  152. navTo(url){
  153. // if(!this.hasLogin){
  154. // url = '/pages/public/login';
  155. // }
  156. uni.navigateTo({
  157. url
  158. })
  159. },
  160. //删除商品
  161. async deleteCoupon(id,List){
  162. let len = List.length;
  163. let redata=await this.$api.addcollection({action:'addcollection',type:'false',uid:this.uid,id:id});
  164. uni.showLoading({
  165. title:'删除中...'
  166. })
  167. if(redata.code==1){
  168. this.collectionlist()
  169. }
  170. uni.hideLoading();
  171. },
  172. discard() {
  173. //丢弃
  174. }
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. view{
  180. display: flex;
  181. flex-wrap: wrap;
  182. }
  183. page{position: relative;background-color: #f5f5f5;}
  184. @font-face {font-family:"HMfont-home";src:url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAYcAAsAAAAAC7AAAAXPAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCDMgqKTIgRATYCJAMUCwwABCAFhG0HShufCciemjxtEyiE0MJUUYjN7gIePI911ftJqrY61RxhAeHWc1taR0BXaRAvS0cGxd7FXycwvQF4WLxnP3czaSZwFdHkmjTO77s3Gq8T2hKtbaWhlUQDcsL+/+Ne1UzbGprPvsVxjwUYCnAsmHRvDnUssKU9L4hXRPoIr6uBbOALl0MAS25cYBo2vnuELAZbIlAwchg7gGxBi+mgCp7CbTjUIPNx8NQMdRvAvOj75TNe4oHC0di7th18Poajd/VebNbx/+gZoODNZwbEo0ADJQEYkPGN1pEkEnHJSGqbliepC2DxUKi5FjV4MezF5v+HTHgiuXWsoGb5wzMgLrY0CPi6MQPvIj0ECt5FI9Dwrg6BwLtl/CdG6uAhFsgEyC6Qn9iEguyVBIPgZBXzMrVu0DJLNGoTpYZ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/rvYjG+TOQ/62Nb86vnfh5kHD1Lmofs/A00KH24ZZN6vgEccMYbA1jlGa/e4Wq4j5YGAzxX/A9/y2Xcm8GAeeTKZ9yOTJ2egyEU2aDwKog2+JDj4VAQXjzpgKUH80T6JdCGBmABQnOEMhCgbQRHmHGiinEcb/H1wSOE9uERFg6WzJJ7Sp7AMsw3G08CiMZb3xroKVWFcg5WPC++JtaWBkRdE9GcyTD6Anm4e5cQlKWTMsUfXHuxmt24MVndRZYxjVyNJUrFTF1WgkbVa283Sdtzdq5vWtFrRIkOeBhgQAyyIMUg5PkgdI1QUmGC6Rb7y9fcQLDYSA4yOjjrnM4SBCT8/4okbHgT0pVQhddxLeVccWDbphmEGpFrMV5FB4tBMSE5UBenUvJEAMcJildoRYY0d3HFSNVW6ur5cfox5f8Gu9qkdUaLFiCMugWnDTI73+IGaGO6Lk55LyUwYCpERZwMAAA==') format('woff2');}
  185. .icon {
  186. font-family:"HMfont-home" !important;
  187. font-size:60upx;
  188. font-style:normal;
  189. color:#000000;
  190. &.jia {
  191. &:before{content:"\e641";}
  192. }
  193. &.jian {
  194. &:before{content:"\e643";}
  195. }
  196. &.shanchu {
  197. &:before{content:"\e6a4";}
  198. }
  199. &.shixiao {
  200. &:before{content:"\e669";}
  201. }
  202. }
  203. .hidden{
  204. display: none !important;
  205. }
  206. .list{
  207. width: 100%;
  208. display: block;
  209. position: relative;
  210. }
  211. @keyframes showGoods {
  212. 0% {transform: translateX(-100%);}100% {transform: translateX(0);}
  213. }
  214. .sub-list{
  215. &.showgoods{
  216. display: flex;
  217. animation: showGoods 0.20s linear both;
  218. }
  219. width: 100%;
  220. padding: 20upx 0 120upx 0;
  221. .tis{
  222. width: 100%;
  223. height: 60upx;
  224. justify-content: center;
  225. align-items: center;
  226. font-size: 32upx;
  227. }
  228. .row{
  229. width: 100%;
  230. height: 30vw;
  231. align-items: center;
  232. position: relative;
  233. overflow: hidden;
  234. border-bottom: solid 1upx #dedede;
  235. .menu{
  236. .icon{
  237. color: #fff;
  238. font-size:50upx;
  239. }
  240. position: absolute;
  241. width: 28%;
  242. height: 100%;
  243. right: 0;
  244. justify-content: center;
  245. align-items: center;
  246. background-color: red;
  247. color: #fff;
  248. z-index: 2;
  249. }
  250. .carrier{
  251. @keyframes showMenu {
  252. 0% {transform: translateX(0);}100% {transform: translateX(-28%);}
  253. }
  254. @keyframes closeMenu {
  255. 0% {transform: translateX(-28%);}100% {transform: translateX(0);}
  256. }
  257. &.open{
  258. animation: showMenu 0.25s linear both;
  259. }
  260. &.close{
  261. animation: closeMenu 0.15s linear both;
  262. }
  263. background-color: #fff;
  264. position: absolute;
  265. width: 100%;
  266. padding: 0 0;
  267. height: 100%;
  268. z-index: 3;
  269. flex-wrap: nowrap;
  270. .goods-info{
  271. width: calc(100% - 40upx);
  272. padding: 10upx;
  273. flex-wrap: nowrap;
  274. .img{
  275. width: calc(30vw - 50upx);
  276. height: calc(30vw - 50upx);
  277. border-radius: 10upx;
  278. overflow: hidden;
  279. flex-shrink: 0;
  280. margin-right: 20upx;
  281. image{
  282. width: calc(30vw - 50upx);
  283. height: calc(30vw - 50upx);
  284. }
  285. }
  286. .info{
  287. width: 100%;
  288. height: calc(30vw - 40upx);
  289. overflow: hidden;
  290. flex-wrap: wrap;
  291. align-content: space-between;
  292. position: relative;
  293. .title{
  294. width: 100%;
  295. font-size: 28upx;
  296. display: -webkit-box;
  297. -webkit-box-orient: vertical;
  298. -webkit-line-clamp: 2;
  299. overflow: hidden;
  300. }
  301. .price-number{
  302. width: 100%;
  303. justify-content: space-between;
  304. align-items: baseline;
  305. .keep-num{
  306. font-size: 26upx;
  307. color: #999;
  308. }
  309. .price{
  310. font-size: 30upx;
  311. color: #f06c7a;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. </style>