index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  6. <view class="list-scroll-view">
  7. <view class="one_1">
  8. <image class="image" :src="topUrl" mode="aspectFit"></image>
  9. </view>
  10. <view class="one_2">
  11. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  12. <view class="list_1">
  13. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
  14. </view>
  15. <view class="name textOver">
  16. {{item.name}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="is_bottom" v-if="is_bottom">
  21. <text>{{config.bottom_title}}</text>
  22. </view>
  23. </view>
  24. </scroll-view>
  25. </view>
  26. </view>
  27. </mobile-frame>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. // 系统设置
  34. config: {},
  35. // 路由参数
  36. type: '1',
  37. tags: '',
  38. act_tags: '',
  39. topUrl: '',
  40. list: [],
  41. total: 0,
  42. page: 0,
  43. skip: 0,
  44. limit: 6,
  45. // 数据是否触底
  46. is_bottom: false,
  47. scrollTop: 0,
  48. };
  49. },
  50. onLoad(e) {
  51. const that = this;
  52. if (e && e.tags) {
  53. that.$set(that, `type`, '1')
  54. that.$set(that, `tags`, e.tags || '');
  55. } else if (e && e.act_tags) {
  56. that.$set(that, `type`, '2')
  57. that.$set(that, `act_tags`, e.act_tags || '');
  58. }
  59. that.searchConfig();
  60. that.searchOther();
  61. that.search();
  62. },
  63. methods: {
  64. // 查询基本设置
  65. searchConfig() {
  66. const that = this;
  67. uni.getStorage({
  68. key: 'config',
  69. success: function(res) {
  70. if (res.data) that.$set(that, `config`, res.data)
  71. }
  72. })
  73. },
  74. async search() {
  75. const that = this;
  76. let info = {
  77. skip: that.skip,
  78. limit: that.limit
  79. };
  80. if (that.type == '1') info.tags = that.tags;
  81. else if (that.type == '2') info.act_tags = that.act_tags;
  82. let res = await that.$api(`/goods`, 'GET', {
  83. ...info,
  84. status: '1'
  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. }
  91. },
  92. toPage() {
  93. const that = this;
  94. let list = that.list;
  95. let limit = that.limit;
  96. if (that.total > list.length) {
  97. uni.showLoading({
  98. title: '加载中',
  99. mask: true
  100. })
  101. let page = that.page + 1;
  102. that.$set(that, `page`, page)
  103. let skip = page * limit;
  104. that.$set(that, `skip`, skip)
  105. that.search();
  106. uni.hideLoading();
  107. } else that.$set(that, `is_bottom`, true)
  108. },
  109. toScroll(e) {
  110. const that = this;
  111. let up = that.scrollTop;
  112. that.$set(that, `scrollTop`, e.detail.scrollTop);
  113. let num = Math.sign(up - e.detail.scrollTop);
  114. if (num == 1) that.$set(that, `is_bottom`, false);
  115. },
  116. // 查询其他信息
  117. async searchOther() {
  118. const that = this;
  119. let type = that.type;
  120. let act_tags = that.act_tags;
  121. let tags = that.tags;
  122. let topUrl = [];
  123. let res;
  124. if (type == '1') {
  125. res = await that.$api(`/goodsTags/getData`, 'GET', {
  126. code: tags
  127. })
  128. } else if (type == '2') {
  129. res = await that.$api(`/actTags/getData`, 'GET', {
  130. value: act_tags
  131. })
  132. }
  133. if (res.errcode == '0') {
  134. let data = res.data;
  135. uni.setNavigationBarTitle({
  136. title: data.label
  137. });
  138. if (that.type == '1' && data.tags_file.length > 0) topUrl = data.tags_file
  139. else if (that.type == '2' && data.file.length > 0) topUrl = data.file
  140. }
  141. if (topUrl.length > 0) {
  142. that.$set(that, `topUrl`, topUrl[0].url)
  143. } else {
  144. that.$set(that, `topUrl`, that.config.config.logo[0].url)
  145. }
  146. },
  147. // 购买
  148. toBuy(e) {
  149. const that = this;
  150. uni.navigateTo({
  151. url: `/pagesHome/order/detail?id=${e._id}`
  152. })
  153. },
  154. },
  155. onPullDownRefresh: async function() {
  156. const that = this;
  157. that.$set(that, `list`, [])
  158. that.$set(that, `skip`, 0)
  159. that.$set(that, `limit`, 6)
  160. that.$set(that, `page`, 0)
  161. await that.search();
  162. uni.stopPullDownRefresh();
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .main {
  168. display: flex;
  169. flex-direction: column;
  170. width: 100vw;
  171. height: 100vh;
  172. .one {
  173. .one_1 {
  174. padding: 2vw;
  175. background-color: #ffffff;
  176. .image {
  177. width: 100%;
  178. height: 200px;
  179. box-shadow: 0 0 5px #f1f1f1;
  180. border-radius: 10px;
  181. }
  182. }
  183. .one_2 {
  184. display: flex;
  185. justify-content: space-between;
  186. flex-wrap: wrap;
  187. padding: 0 2vw;
  188. .list {
  189. width: 43vw;
  190. margin: 0 0 2vw 0;
  191. box-shadow: 0 0 5px #f1f1f1;
  192. padding: 2vw;
  193. border-radius: 5px;
  194. .list_1 {
  195. margin: 0 0 1vw 0;
  196. .image {
  197. width: 100%;
  198. height: 30vh;
  199. border-radius: 10px;
  200. box-shadow: 0 0 5px #f1f1f1;
  201. }
  202. }
  203. .name {
  204. font-size: 16px;
  205. }
  206. }
  207. }
  208. }
  209. // .one {
  210. // padding: 2vw;
  211. // background-color: #ffffff;
  212. // .image {
  213. // width: 100%;
  214. // height: 200px;
  215. // box-shadow: 0 0 5px #f1f1f1;
  216. // border-radius: 10px;
  217. // }
  218. // }
  219. // .two {
  220. // position: relative;
  221. // flex-grow: 1;
  222. // // .pubu {
  223. // // // column-count: 2;
  224. // // // column-gap: 3vw;
  225. // // display: flex;
  226. // // justify-content: space-between;
  227. // // flex-wrap: wrap;
  228. // // .list {
  229. // // width: 43vw;
  230. // // // break-inside: avoid;
  231. // // margin: 0 0 2vw 0;
  232. // // box-shadow: 0 0 5px #f1f1f1;
  233. // // padding: 2vw;
  234. // // border-radius: 5px;
  235. // // .list_1 {
  236. // // margin: 0 0 1vw 0;
  237. // // .image {
  238. // // width: 100%;
  239. // // height: 30vh;
  240. // // border-radius: 10px;
  241. // // box-shadow: 0 0 5px #f1f1f1;
  242. // // }
  243. // // }
  244. // // .name {
  245. // // font-size: 16px;
  246. // // }
  247. // // }
  248. // // }
  249. // }
  250. }
  251. .scroll-view {
  252. position: absolute;
  253. top: 0;
  254. left: 0;
  255. right: 0;
  256. bottom: 0;
  257. .list-scroll-view {
  258. display: flex;
  259. flex-direction: column;
  260. }
  261. }
  262. .is_bottom {
  263. text-align: center;
  264. text {
  265. padding: 2vw 0;
  266. display: inline-block;
  267. color: #858585;
  268. font-size: 14px;
  269. }
  270. }
  271. </style>