market.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  6. <view class="list-scroll-view">
  7. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  8. <image class="image"
  9. :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  10. </image>
  11. <view class="name">
  12. {{item.name||'暂无'}}
  13. </view>
  14. <view class="money">
  15. <text>¥</text>
  16. <text>{{item.sell_money}}</text>
  17. </view>
  18. <view class="other">
  19. <view class="other_1">
  20. {{item.view_num||0}}人浏览
  21. </view>
  22. <view class="other_2">
  23. <text @tap.stop="toDel(item)" class="iconfont icon-del"></text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </view>
  31. </mobile-frame>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. user: {},
  38. list: [],
  39. total: 0,
  40. skip: 0,
  41. limit: 5,
  42. page: 0
  43. };
  44. },
  45. onShow: function() {
  46. const that = this;
  47. that.watchLogin()
  48. },
  49. methods: {
  50. // 详细信息
  51. toView(e) {
  52. const that = this;
  53. that.clearPage();
  54. uni.navigateTo({
  55. url: `/pagesHome/order/detail?id=${e._id}`
  56. })
  57. },
  58. // 删除
  59. toDel(e) {
  60. const that = this;
  61. let user = that.user;
  62. uni.showModal({
  63. title: '提示',
  64. content: '确定取消收藏吗?',
  65. success: async function(res) {
  66. if (res.confirm) {
  67. let res = await that.$api(`/storeGoods`, `POST`, {
  68. customer: user._id,
  69. goods: that.id
  70. });
  71. const arr = await that.$api(`/storeGoods`, 'POST', {
  72. customer: user._id,
  73. goods: e._id
  74. });
  75. if (arr.errcode == '0') {
  76. uni.showToast({
  77. title: '取消收藏成功',
  78. icon: 'none'
  79. })
  80. that.clearPage();
  81. that.search();
  82. } else {
  83. uni.showToast({
  84. title: arr.errmsg,
  85. icon: 'none'
  86. })
  87. }
  88. }
  89. }
  90. });
  91. },
  92. // 监听用户是否登录
  93. watchLogin() {
  94. const that = this;
  95. uni.getStorage({
  96. key: 'token',
  97. success: function(res) {
  98. let user = that.$jwt(res.data);
  99. that.$set(that, `user`, user);
  100. that.search()
  101. },
  102. fail: function(err) {
  103. uni.reLaunch({
  104. url: `/pages/login/index`
  105. })
  106. }
  107. })
  108. },
  109. // 查询列表
  110. async search() {
  111. const that = this;
  112. let user = that.user;
  113. let info = {
  114. skip: that.skip,
  115. limit: that.limit
  116. }
  117. const res = await that.$api(`/storeGoods/userView`, 'GET', {
  118. ...info
  119. })
  120. if (res.errcode == '0') {
  121. let list = [...that.list, ...res.data];
  122. that.$set(that, `list`, list);
  123. that.$set(that, `total`, res.total)
  124. }
  125. },
  126. // 分页
  127. toPage(e) {
  128. const that = this;
  129. let list = that.list;
  130. let limit = that.limit;
  131. if (that.total > list.length) {
  132. uni.showLoading({
  133. title: '加载中',
  134. mask: true
  135. })
  136. let page = that.page + 1;
  137. that.$set(that, `page`, page)
  138. let skip = page * limit;
  139. that.$set(that, `skip`, skip)
  140. that.search();
  141. uni.hideLoading();
  142. } else uni.showToast({
  143. title: '没有更多数据了'
  144. });
  145. },
  146. // 清空列表
  147. clearPage() {
  148. const that = this;
  149. that.$set(that, `list`, [])
  150. that.$set(that, `skip`, 0)
  151. that.$set(that, `limit`, 5)
  152. that.$set(that, `page`, 0)
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. .main {
  159. display: flex;
  160. flex-direction: column;
  161. width: 100vw;
  162. height: 100vh;
  163. .one {
  164. padding: 2vw 0 0 0;
  165. .list {
  166. width: 42vw;
  167. border: 1px solid var(--f1Color);
  168. margin: 2vw 2vw 0 2vw;
  169. padding: 2vw;
  170. border-radius: 5px;
  171. .image {
  172. width: 100%;
  173. height: 40vw;
  174. }
  175. .name {
  176. font-size: var(--font16Size);
  177. margin: 0 0 1vw 0;
  178. }
  179. .money {
  180. color: var(--fFB1Color);
  181. font-size: var(--font14Size);
  182. margin: 0 0 1vw 0;
  183. }
  184. .other {
  185. display: flex;
  186. flex-direction: row;
  187. justify-content: space-between;
  188. .other_1 {
  189. font-size: var(--font14Size);
  190. color: var(--f85Color);
  191. }
  192. }
  193. }
  194. .list:nth-child(2n) {
  195. margin: 2vw 0 0 0;
  196. }
  197. }
  198. }
  199. .scroll-view {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. .list-scroll-view {
  206. display: flex;
  207. flex-direction: row;
  208. flex-wrap: wrap;
  209. }
  210. }
  211. </style>