index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  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="toShop(item)">
  8. <view class="list_1">
  9. <view class="l">
  10. <image class="image" :src="item.logo&&item.logo.length>0?item.logo[0].url:''" mode=""></image>
  11. </view>
  12. <view class="c">
  13. <view class="name">
  14. {{item.name}}
  15. </view>
  16. <view class="other">
  17. <text>宝贝数<text>{{item.market_num}}</text></text>
  18. <text>关注数<text>{{item.follow_num}}</text></text>
  19. </view>
  20. </view>
  21. <view class="r" @tap.stop="toFolllow(item)">
  22. <text class="iconfont icon-yduishoucangshixin-copy" v-if="item.is_follow==true"></text>
  23. <text class="iconfont icon-yduishoucangkongxin-copy" v-else></text>
  24. </view>
  25. </view>
  26. <view class="list_2">
  27. <view class="market" v-for="(tag,indexs) in item.market" :key="indexs" @tap.stop="toBuy(tag)">
  28. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''" mode=""></image>
  29. <view class="money">
  30. ¥{{tag.sell_money}}
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. </view>
  38. </view>
  39. </mobile-frame>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. frameStyle: {
  46. useBar: true
  47. },
  48. user: {},
  49. list: [],
  50. total: 0,
  51. page: 0,
  52. skip: 0,
  53. limit: 5,
  54. };
  55. },
  56. onShow: async function() {
  57. const that = this;
  58. await that.watchLogin();
  59. await that.search();
  60. },
  61. methods: {
  62. // 监听用户是否登录
  63. watchLogin() {
  64. const that = this;
  65. uni.getStorage({
  66. key: 'token',
  67. success: function(res) {
  68. let user = that.$jwt(res.data);
  69. that.$set(that, `user`, user)
  70. }
  71. })
  72. },
  73. async search() {
  74. const that = this;
  75. let info = {
  76. skip: that.skip,
  77. limit: that.limit
  78. }
  79. const res = await that.$api(`/viewShop/microIndex`, `GET`, {
  80. ...info,
  81. })
  82. if (res.errcode == '0') {
  83. let list = [...that.list, ...res.data];
  84. that.$set(that, `list`, list)
  85. that.$set(that, `total`, res.total)
  86. } else {
  87. uni.showToast({
  88. title: res.errmsg,
  89. });
  90. }
  91. },
  92. // 分页
  93. toPage() {
  94. const that = this;
  95. let list = that.list;
  96. let limit = that.limit;
  97. if (that.total > list.length) {
  98. uni.showLoading({
  99. title: '加载中',
  100. mask: true
  101. })
  102. let page = that.page + 1;
  103. that.$set(that, `page`, page)
  104. let skip = page * limit;
  105. that.$set(that, `skip`, skip)
  106. that.search();
  107. uni.hideLoading();
  108. } else uni.showToast({
  109. title: '没有更多数据了'
  110. });
  111. },
  112. // 商铺
  113. toShop(e) {
  114. const that = this;
  115. that.clearPage();
  116. uni.navigateTo({
  117. url: `/pagesHome/shop/index?id=${e._id}`
  118. })
  119. },
  120. // 购买
  121. toBuy(e) {
  122. const that = this;
  123. that.clearPage();
  124. uni.navigateTo({
  125. url: `/pagesHome/order/detail?id=${e._id}`
  126. })
  127. },
  128. // 关注
  129. async toFolllow(e) {
  130. const that = this;
  131. let user = that.user;
  132. if (user && user._id && e && e._id) {
  133. let res = await that.$api(`/storeShop`, `POST`, {
  134. customer: user._id,
  135. shop: e._id
  136. });
  137. if (res.errcode == '0') {
  138. uni.showToast({
  139. title: res.data.msg,
  140. icon: 'none'
  141. })
  142. that.clearPage();
  143. that.search()
  144. }
  145. } else {
  146. uni.showToast({
  147. title: '缺少必要信息,无法收藏',
  148. icon: 'none'
  149. })
  150. }
  151. },
  152. toPath(e) {
  153. const that = this;
  154. that.clearPage();
  155. if (e && e.route && e.type == '0') {
  156. uni.redirectTo({
  157. url: `/${e.route}`
  158. })
  159. } else {
  160. uni.navigateTo({
  161. url: `/${e.route}`
  162. })
  163. }
  164. },
  165. // 清空列表
  166. clearPage() {
  167. const that = this;
  168. that.$set(that, `list`, [])
  169. that.$set(that, `skip`, 0)
  170. that.$set(that, `limit`, 5)
  171. that.$set(that, `page`, 0)
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. .main {
  178. .one {
  179. .list {
  180. margin: 2vw 2vw 0 2vw;
  181. padding: 2vw;
  182. border-radius: 5px;
  183. background-color: #f5f5f5;
  184. .list_1 {
  185. display: flex;
  186. flex-direction: row;
  187. margin: 0 0 1vw 0;
  188. .l {
  189. width: 20vw;
  190. .image {
  191. width: 100%;
  192. height: 20vw;
  193. border-radius: 5px;
  194. }
  195. }
  196. .c {
  197. padding: 0 0 0 2vw;
  198. width: 60vw;
  199. .name {
  200. font-size: 16px;
  201. font-weight: bold;
  202. margin: 0 0 1vw 0;
  203. }
  204. .other {
  205. font-size: 14px;
  206. text {
  207. padding: 0 2vw 0 0;
  208. }
  209. }
  210. }
  211. .r {
  212. width: 10vw;
  213. text-align: right;
  214. text {
  215. font-size: 30px;
  216. }
  217. }
  218. }
  219. .list_2 {
  220. display: flex;
  221. flex-direction: row;
  222. flex-wrap: wrap;
  223. .market {
  224. position: relative;
  225. margin: 0 2vw 2vw 0;
  226. width: 29vw;
  227. .image {
  228. width: 100%;
  229. height: 20vw;
  230. }
  231. .money {
  232. position: absolute;
  233. bottom: 0;
  234. font-size: 10px;
  235. width: 100%;
  236. background-color: #0000005f;
  237. color: #fff;
  238. padding: 0.2vw 0;
  239. text-align: center;
  240. font-size: 14px;
  241. }
  242. }
  243. .market:nth-child(3n) {
  244. margin: 0 0 2vw 0;
  245. }
  246. }
  247. }
  248. }
  249. }
  250. .scroll-view {
  251. position: absolute;
  252. top: 0;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. .list-scroll-view {
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. }
  261. </style>