index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="">
  29. </image>
  30. <view class="money">
  31. ¥{{tag.sell_money}}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </mobile-frame>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. frameStyle: {
  47. useBar: true
  48. },
  49. user: {},
  50. list: [],
  51. total: 0,
  52. page: 0,
  53. skip: 0,
  54. limit: 10,
  55. };
  56. },
  57. onLoad: async function() {
  58. const that = this;
  59. // 监听用户是否登录
  60. await that.watchLogin();
  61. // 查询列表
  62. await that.search();
  63. },
  64. onPullDownRefresh: async function() {
  65. const that = this;
  66. that.clearPage();
  67. await that.search();
  68. uni.stopPullDownRefresh();
  69. },
  70. methods: {
  71. // 监听用户是否登录
  72. watchLogin() {
  73. const that = this;
  74. uni.getStorage({
  75. key: 'token',
  76. success: function(res) {
  77. let user = that.$jwt(res.data);
  78. that.$set(that, `user`, user)
  79. }
  80. })
  81. },
  82. // 查询列表
  83. async search() {
  84. const that = this;
  85. let info = {
  86. skip: that.skip,
  87. limit: that.limit
  88. }
  89. const res = await that.$api(`/viewShop/microIndex`, `GET`, {
  90. ...info,
  91. })
  92. if (res.errcode == '0') {
  93. let list = [...that.list, ...res.data];
  94. that.$set(that, `list`, list)
  95. that.$set(that, `total`, res.total)
  96. } else {
  97. uni.showToast({
  98. title: res.errmsg,
  99. });
  100. }
  101. },
  102. // 分页
  103. toPage() {
  104. const that = this;
  105. let list = that.list;
  106. let limit = that.limit;
  107. if (that.total > list.length) {
  108. uni.showLoading({
  109. title: '加载中',
  110. mask: true
  111. })
  112. let page = that.page + 1;
  113. that.$set(that, `page`, page)
  114. let skip = page * limit;
  115. that.$set(that, `skip`, skip)
  116. that.search();
  117. uni.hideLoading();
  118. } else {}
  119. },
  120. // 商铺
  121. toShop(e) {
  122. const that = this;
  123. uni.navigateTo({
  124. url: `/pagesHome/shop/index?id=${e._id}`
  125. })
  126. },
  127. // 购买
  128. toBuy(e) {
  129. const that = this;
  130. uni.navigateTo({
  131. url: `/pagesHome/order/detail?id=${e._id}`
  132. })
  133. },
  134. // 关注
  135. async toFolllow(e) {
  136. const that = this;
  137. let user = that.user;
  138. if (user && user._id && e && e._id) {
  139. let res = await that.$api(`/storeShop`, `POST`, {
  140. customer: user._id,
  141. shop: e._id
  142. });
  143. if (res.errcode == '0') {
  144. uni.showToast({
  145. title: res.data.msg,
  146. icon: 'none'
  147. })
  148. that.clearPage();
  149. that.search()
  150. }
  151. } else {
  152. uni.showToast({
  153. title: '缺少必要信息,无法收藏',
  154. icon: 'none'
  155. })
  156. }
  157. },
  158. // 清空列表
  159. clearPage() {
  160. const that = this;
  161. that.$set(that, `list`, [])
  162. that.$set(that, `skip`, 0)
  163. that.$set(that, `limit`, 6)
  164. that.$set(that, `page`, 0)
  165. },
  166. toPath(e) {
  167. let url = `/${e.route}`;
  168. if (e.type == '0') uni.redirectTo({
  169. url
  170. })
  171. else {
  172. uni.navigateTo({
  173. url
  174. })
  175. }
  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>