index.vue 6.5 KB

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