index.vue 5.6 KB

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