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. uni.startPullDownRefresh();
  67. },
  68. methods: {
  69. // 监听用户是否登录
  70. watchLogin() {
  71. const that = this;
  72. uni.getStorage({
  73. key: 'token',
  74. success: function(res) {
  75. let user = that.$jwt(res.data);
  76. that.$set(that, `user`, user)
  77. }
  78. })
  79. },
  80. // 查询列表
  81. async search() {
  82. const that = this;
  83. let info = {
  84. skip: that.skip,
  85. limit: that.limit
  86. }
  87. const res = await that.$api(`/viewShop/microIndex`, `GET`, {
  88. ...info,
  89. })
  90. if (res.errcode == '0') {
  91. let list = [...that.list, ...res.data];
  92. that.$set(that, `list`, list)
  93. that.$set(that, `total`, res.total)
  94. } else {
  95. uni.showToast({
  96. title: res.errmsg,
  97. });
  98. }
  99. },
  100. // 分页
  101. toPage() {
  102. const that = this;
  103. let list = that.list;
  104. let limit = that.limit;
  105. if (that.total > list.length) {
  106. uni.showLoading({
  107. title: '加载中',
  108. mask: true
  109. })
  110. let page = that.page + 1;
  111. that.$set(that, `page`, page)
  112. let skip = page * limit;
  113. that.$set(that, `skip`, skip)
  114. that.search();
  115. uni.hideLoading();
  116. } else uni.showToast({
  117. title: '没有更多数据了'
  118. });
  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`, 5)
  164. that.$set(that, `page`, 0)
  165. },
  166. toPath(e) {
  167. const that = this;
  168. if (e && e.route && e.type == '0') {
  169. uni.redirectTo({
  170. url: `/${e.route}`
  171. })
  172. } else {
  173. uni.navigateTo({
  174. url: `/${e.route}`
  175. })
  176. }
  177. }
  178. },
  179. onPullDownRefresh: async function() {
  180. const that = this;
  181. that.$set(that, `list`, [])
  182. that.$set(that, `skip`, 0)
  183. that.$set(that, `limit`, 6)
  184. that.$set(that, `page`, 0)
  185. await that.search();
  186. uni.stopPullDownRefresh();
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. .main {
  192. .one {
  193. .list {
  194. margin: 2vw 2vw 0 2vw;
  195. padding: 2vw;
  196. border-radius: 5px;
  197. background-color: #f5f5f5;
  198. .list_1 {
  199. display: flex;
  200. flex-direction: row;
  201. margin: 0 0 1vw 0;
  202. .l {
  203. width: 20vw;
  204. .image {
  205. width: 100%;
  206. height: 20vw;
  207. border-radius: 5px;
  208. }
  209. }
  210. .c {
  211. padding: 0 0 0 2vw;
  212. width: 60vw;
  213. .name {
  214. font-size: 16px;
  215. font-weight: bold;
  216. margin: 0 0 1vw 0;
  217. }
  218. .other {
  219. font-size: 14px;
  220. text {
  221. padding: 0 2vw 0 0;
  222. }
  223. }
  224. }
  225. .r {
  226. width: 10vw;
  227. text-align: right;
  228. text {
  229. font-size: 30px;
  230. }
  231. }
  232. }
  233. .list_2 {
  234. display: flex;
  235. flex-direction: row;
  236. flex-wrap: wrap;
  237. .market {
  238. position: relative;
  239. margin: 0 2vw 2vw 0;
  240. width: 29vw;
  241. .image {
  242. width: 100%;
  243. height: 20vw;
  244. }
  245. .money {
  246. position: absolute;
  247. bottom: 0;
  248. font-size: 10px;
  249. width: 100%;
  250. background-color: #0000005f;
  251. color: #fff;
  252. padding: 0.2vw 0;
  253. text-align: center;
  254. font-size: 14px;
  255. }
  256. }
  257. .market:nth-child(3n) {
  258. margin: 0 0 2vw 0;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. .scroll-view {
  265. position: absolute;
  266. top: 0;
  267. left: 0;
  268. right: 0;
  269. bottom: 0;
  270. .list-scroll-view {
  271. display: flex;
  272. flex-direction: column;
  273. }
  274. }
  275. </style>