index.vue 5.8 KB

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