index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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: 10,
  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. onPullDownRefresh: async function() {
  64. const that = this;
  65. that.clearPage()
  66. await that.search();
  67. uni.stopPullDownRefresh();
  68. },
  69. methods: {
  70. // 查询基本设置
  71. searchConfig() {
  72. const that = this;
  73. uni.getStorage({
  74. key: 'config',
  75. success: function(res) {
  76. if (res.data) that.$set(that, `config`, res.data)
  77. }
  78. })
  79. },
  80. async search() {
  81. const that = this;
  82. let info = {
  83. skip: that.skip,
  84. limit: that.limit
  85. };
  86. if (that.type == '1') info.tags = that.tags;
  87. else if (that.type == '2') info.act_tags = that.act_tags;
  88. let res = await that.$api(`/goods`, 'GET', {
  89. ...info,
  90. status: '1'
  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. }
  97. },
  98. toPage() {
  99. const that = this;
  100. let list = that.list;
  101. let limit = that.limit;
  102. if (that.total > list.length) {
  103. uni.showLoading({
  104. title: '加载中',
  105. mask: true
  106. })
  107. let page = that.page + 1;
  108. that.$set(that, `page`, page)
  109. let skip = page * limit;
  110. that.$set(that, `skip`, skip)
  111. that.search();
  112. uni.hideLoading();
  113. } else that.$set(that, `is_bottom`, true)
  114. },
  115. toScroll(e) {
  116. const that = this;
  117. let up = that.scrollTop;
  118. that.$set(that, `scrollTop`, e.detail.scrollTop);
  119. let num = Math.sign(up - e.detail.scrollTop);
  120. if (num == 1) that.$set(that, `is_bottom`, false);
  121. },
  122. // 查询其他信息
  123. async searchOther() {
  124. const that = this;
  125. let type = that.type;
  126. let act_tags = that.act_tags;
  127. let tags = that.tags;
  128. let topUrl = [];
  129. let res;
  130. if (type == '1') {
  131. res = await that.$api(`/goodsTags/getData`, 'GET', {
  132. code: tags
  133. })
  134. } else if (type == '2') {
  135. res = await that.$api(`/actTags/getData`, 'GET', {
  136. value: act_tags
  137. })
  138. }
  139. if (res.errcode == '0') {
  140. let data = res.data;
  141. uni.setNavigationBarTitle({
  142. title: data.label
  143. });
  144. if (that.type == '1' && data.tags_file.length > 0) topUrl = data.tags_file
  145. else if (that.type == '2' && data.file.length > 0) topUrl = data.file
  146. }
  147. if (topUrl.length > 0) {
  148. that.$set(that, `topUrl`, topUrl[0].url)
  149. } else {
  150. that.$set(that, `topUrl`, that.config.config.logo[0].url)
  151. }
  152. },
  153. // 购买
  154. toBuy(e) {
  155. const that = this;
  156. uni.navigateTo({
  157. url: `/pagesHome/order/detail?id=${e._id}`
  158. })
  159. },
  160. // 清空列表
  161. clearPage() {
  162. const that = this;
  163. that.$set(that, `list`, [])
  164. that.$set(that, `skip`, 0)
  165. that.$set(that, `limit`, 6)
  166. that.$set(that, `page`, 0)
  167. }
  168. },
  169. }
  170. </script>
  171. <style lang="scss">
  172. .main {
  173. display: flex;
  174. flex-direction: column;
  175. width: 100vw;
  176. height: 100vh;
  177. .one {
  178. .one_1 {
  179. padding: 2vw;
  180. background-color: #ffffff;
  181. .image {
  182. width: 100%;
  183. height: 200px;
  184. box-shadow: 0 0 5px #f1f1f1;
  185. border-radius: 10px;
  186. }
  187. }
  188. .one_2 {
  189. display: flex;
  190. justify-content: space-between;
  191. flex-wrap: wrap;
  192. padding: 0 2vw;
  193. .list {
  194. width: 43vw;
  195. margin: 0 0 2vw 0;
  196. box-shadow: 0 0 5px #f1f1f1;
  197. padding: 2vw;
  198. border-radius: 5px;
  199. .list_1 {
  200. margin: 0 0 1vw 0;
  201. .image {
  202. width: 100%;
  203. height: 30vh;
  204. border-radius: 10px;
  205. box-shadow: 0 0 5px #f1f1f1;
  206. }
  207. }
  208. .name {
  209. font-size: 16px;
  210. }
  211. }
  212. }
  213. }
  214. // .one {
  215. // padding: 2vw;
  216. // background-color: #ffffff;
  217. // .image {
  218. // width: 100%;
  219. // height: 200px;
  220. // box-shadow: 0 0 5px #f1f1f1;
  221. // border-radius: 10px;
  222. // }
  223. // }
  224. // .two {
  225. // position: relative;
  226. // flex-grow: 1;
  227. // // .pubu {
  228. // // // column-count: 2;
  229. // // // column-gap: 3vw;
  230. // // display: flex;
  231. // // justify-content: space-between;
  232. // // flex-wrap: wrap;
  233. // // .list {
  234. // // width: 43vw;
  235. // // // break-inside: avoid;
  236. // // margin: 0 0 2vw 0;
  237. // // box-shadow: 0 0 5px #f1f1f1;
  238. // // padding: 2vw;
  239. // // border-radius: 5px;
  240. // // .list_1 {
  241. // // margin: 0 0 1vw 0;
  242. // // .image {
  243. // // width: 100%;
  244. // // height: 30vh;
  245. // // border-radius: 10px;
  246. // // box-shadow: 0 0 5px #f1f1f1;
  247. // // }
  248. // // }
  249. // // .name {
  250. // // font-size: 16px;
  251. // // }
  252. // // }
  253. // // }
  254. // }
  255. }
  256. .scroll-view {
  257. position: absolute;
  258. top: 0;
  259. left: 0;
  260. right: 0;
  261. bottom: 0;
  262. .list-scroll-view {
  263. display: flex;
  264. flex-direction: column;
  265. }
  266. }
  267. .is_bottom {
  268. text-align: center;
  269. text {
  270. padding: 2vw 0;
  271. display: inline-block;
  272. color: #858585;
  273. font-size: 14px;
  274. }
  275. }
  276. </style>