collect.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="bg-drak" :class="[empty ? '' : 'padding-tb']">
  3. <!-- 空白页 -->
  4. <use-empty v-if="empty" e-style="round" tip="无收藏数据"></use-empty>
  5. <view v-else class="padding-lr" v-for="(item, index) in datas" :key="index">
  6. <view class="product border-radius-sm padding margin-bottom-sm bg-main" style="padding-bottom: 15rpx;">
  7. <view class="left" @click="togoods(item)">
  8. <image :src="item.goodsMainImageUrl" mode="aspectFill"></image>
  9. </view>
  10. <view class="margin-left-sm pos-r w-full">
  11. <text class="clamp-2" @click="togoods(item)">{{ item.goodsName }} </text>
  12. <view class="pos-a dflex-b price-box w-full">
  13. <text class="price padding-tb-sm" @click="togoods(item)">{{ item.goodsPrice }}</text>
  14. <view class="dflex-c ft-dark">
  15. <button class="btn no-border padding-0 fs-sm ft-dark" open-type="share" :id="item.goodsId">
  16. <view class="dflex-c fs-xs padding-tb-sm">
  17. <text class="iconfont iconfenxiang margin-left-xs"></text>
  18. </view>
  19. </button>
  20. <view @tap.stop="deleteCollect(item)" class="dflex-c margin-left-sm padding-tb-sm">
  21. <text class="iconfont iconlajitong-01 margin-left-xs"></text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 上拉加载更多 -->
  29. <use-loadmore v-if="!empty && hasmore" :type="loadmoreType"></use-loadmore>
  30. <!-- 置顶 -->
  31. <use-totop ref="usetop" bottom="150"></use-totop>
  32. <view v-if="!empty" class="fixed-top" @click="clear">
  33. <text class="iconfont iconlajitong-01 fs-xl"></text>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. collectlist,
  40. collectdelete,
  41. collectclear
  42. } from '../../../utils/api_user.js'
  43. import useEmpty from '../../../components/use-empty/use-empty.vue'
  44. import useLoadmore from '../../../components/use-loadmore/use-loadmore.vue'
  45. import useTotop from '../../../components/use-totop/use-totop.vue'
  46. const db = uniCloud.database();
  47. const _collect = 'usemall-member-collect'
  48. import { mapState } from 'vuex';
  49. export default {
  50. computed: {
  51. ...mapState(['islogin', 'member'])
  52. },
  53. components:{
  54. useEmpty,
  55. useLoadmore,
  56. useTotop
  57. },
  58. data() {
  59. return {
  60. // 加载更多状态
  61. loadmoreType: 'nomore',
  62. // 数据源
  63. datas: [],
  64. empty: false,
  65. hasmore: 0,
  66. reqdata: {
  67. rows: 20,
  68. page: 1
  69. },
  70. scrollTop: 0,
  71. };
  72. },
  73. watch: {
  74. datas(e) {
  75. let empty = e.length === 0;
  76. if (this.empty !== empty) {
  77. this.empty = empty;
  78. }
  79. }
  80. },
  81. onShareAppMessage: function(ops) {
  82. let _this = this;
  83. console.log(_this.member)
  84. let mid = 0;
  85. if (_this.member && _this.member.id) {
  86. mid = _this.member.id;
  87. }
  88. let goods = _this.datas.find(x => x.goodsId == ops.target.id);
  89. let share_img = '';
  90. if (goods && goods.id > 0) {
  91. share_img = goods.share_img;
  92. }
  93. return {
  94. imageUrl: share_img,
  95. bgImgUrl: share_img, //[${_this.member.user_name}] 的
  96. title: `来自收藏夹`,
  97. path: `/pages/goods/goods?id=${ops.target.id}&mid=${mid}`,
  98. content: '大魏商城',
  99. desc: '大魏商城',
  100. success: function(res) {
  101. // 转发成功
  102. console.log(res);
  103. console.log('转发成功', JSON.stringify(res));
  104. },
  105. fail: function(res) {
  106. // 转发失败
  107. console.log('转发失败', JSON.stringify(res));
  108. }
  109. };
  110. },
  111. onPageScroll(e) {
  112. //this.scrollTop = e.scrollTop;
  113. this.$refs.usetop.change(e.scrollTop);
  114. },
  115. onShow() {
  116. this.loadData();
  117. },
  118. methods: {
  119. loadData() {
  120. let _self=this
  121. // const goodsTemp = db.collection('usemall-goods').getTemp();
  122. //收藏数据
  123. collectlist().then((res) => {
  124. if(res.success){
  125. let _historyDatas = [];
  126. res.data.list.forEach(x => {
  127. _historyDatas.push(x);
  128. });
  129. _self.datas = _historyDatas;
  130. if (_self.datas.length === 0) {
  131. _self.empty = true;
  132. }
  133. return
  134. }
  135. _self.$api.msg(res.msg);
  136. })
  137. },
  138. // 删除收藏
  139. deleteCollect(item) {
  140. let _this = this
  141. uni.showModal({
  142. title: '提示',
  143. content: '删除收藏',
  144. success: function(res) {
  145. if (res.confirm) {
  146. var data=item.goodsId
  147. collectdelete(data).then((res) => {
  148. if(res.success){
  149. _this.loadData();
  150. return
  151. }
  152. _this.$api.msg(res.msg);
  153. })
  154. } else if (res.cancel) {
  155. console.log('用户点击取消');
  156. }
  157. }
  158. });
  159. },
  160. // 清空收藏
  161. clear() {
  162. let _this = this;
  163. uni.showModal({
  164. title: '提示',
  165. content: '清空收藏',
  166. success: function(res) {
  167. if (res.confirm) {
  168. collectclear().then((res) => {
  169. if(res.success){
  170. _this.datas = [];
  171. return
  172. }
  173. _this.$api.msg(res.msg);
  174. })
  175. } else if (res.cancel) {
  176. console.log('用户点击取消');
  177. }
  178. }
  179. });
  180. },
  181. togoods(item) {
  182. this.$api.togoods({
  183. id: item.goodsId
  184. });
  185. }
  186. }
  187. };
  188. </script>
  189. <style lang="scss">
  190. @import url('/packageShang/components/iconfont/iconfont.css');
  191. @import url('/packageShang/common/common.scss');
  192. page {
  193. background: $page-color-base;
  194. }
  195. .product {
  196. display: flex;
  197. .left {
  198. image {
  199. width: 180rpx;
  200. height: 180rpx;
  201. }
  202. }
  203. .price-box {
  204. bottom: -20rpx;
  205. }
  206. }
  207. </style>