index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" v-model="searchInfo.name" @blur="toInput" placeholder="搜索商品">
  6. </view>
  7. <view class="two">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  9. <view class="list-scroll-view">
  10. <view class="two_1">
  11. <view class="list" v-for="(item,index) in list" :key="index">
  12. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  13. </image>
  14. <view class="name textOver">
  15. {{item.name}}
  16. </view>
  17. <view class="other">
  18. <view class="money">
  19. <text>¥</text>
  20. <text>{{item.sell_money}}</text>
  21. </view>
  22. <view class="btn">
  23. <button type="default" size="mini" @click="toBuy(item)">兑换</button>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <view class="is_bottom" v-if="is_bottom">
  32. <text>{{config.bottom_title}}</text>
  33. </view>
  34. </view>
  35. </mobile-frame>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. // 系统设置
  42. config: {},
  43. searchInfo: {},
  44. list: [],
  45. total: 0,
  46. page: 0,
  47. skip: 0,
  48. limit: 6,
  49. // 数据是否触底
  50. is_bottom: false,
  51. scrollTop: 0
  52. };
  53. },
  54. onLoad: async function(e) {
  55. const that = this;
  56. that.searchConfig();
  57. await that.searchOther();
  58. await that.search();
  59. },
  60. methods: {
  61. // 查询基本设置
  62. searchConfig() {
  63. const that = this;
  64. uni.getStorage({
  65. key: 'config',
  66. success: function(res) {
  67. if (res.data) that.$set(that, `config`, res.data)
  68. },
  69. fail: function(err) {
  70. console.log(err);
  71. }
  72. })
  73. },
  74. async searchOther() {
  75. const that = this;
  76. },
  77. async search() {
  78. const that = this;
  79. let info = {
  80. skip: that.skip,
  81. limit: that.limit,
  82. }
  83. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  84. ...info,
  85. ...that.searchInfo
  86. })
  87. if (res.errcode == '0') {
  88. let list = [...that.list, ...res.data]
  89. that.$set(that, `list`, list)
  90. that.$set(that, `total`, res.total)
  91. } else {
  92. uni.showToast({
  93. title: res.errmsg,
  94. });
  95. }
  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. toInput(e) {
  124. const that = this;
  125. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  126. that.clearPage();
  127. that.search();
  128. },
  129. toBuy(e) {
  130. uni.navigateTo({
  131. url: `/pagesIntegral/order/detail?id=${e.id||e._id}`
  132. })
  133. },
  134. // 清空列表
  135. clearPage() {
  136. const that = this;
  137. that.$set(that, `list`, [])
  138. that.$set(that, `skip`, 0)
  139. that.$set(that, `limit`, 6)
  140. that.$set(that, `page`, 0)
  141. }
  142. },
  143. onPullDownRefresh: async function() {
  144. const that = this;
  145. that.$set(that, `list`, [])
  146. that.$set(that, `skip`, 0)
  147. that.$set(that, `limit`, 6)
  148. that.$set(that, `page`, 0)
  149. await that.search();
  150. uni.stopPullDownRefresh();
  151. }
  152. }
  153. </script>
  154. <style lang="scss">
  155. .main {
  156. display: flex;
  157. flex-direction: column;
  158. width: 100vw;
  159. height: 100vh;
  160. .one {
  161. border-bottom: 1px solid var(--f85Color);
  162. padding: 2vw;
  163. input {
  164. padding: 2vw;
  165. background-color: var(--f1Color);
  166. font-size: var(--font14Size);
  167. border-radius: 5px;
  168. }
  169. }
  170. .two {
  171. position: relative;
  172. flex-grow: 1;
  173. .two_1 {
  174. display: flex;
  175. justify-content: space-between;
  176. flex-wrap: wrap;
  177. .list {
  178. // break-inside: avoid;
  179. width: 43vw;
  180. background: #fff;
  181. padding: 2vw;
  182. border-radius: 5px;
  183. margin: 0 0 2vw 0;
  184. .image {
  185. width: 100%;
  186. height: 50vw;
  187. }
  188. .name {
  189. font-size: var(--font15Size);
  190. margin: 0 0 2vw 0;
  191. }
  192. .other {
  193. display: flex;
  194. flex-direction: row;
  195. justify-content: space-between;
  196. .money {
  197. color: var(--ff0Color);
  198. text:nth-child(1) {
  199. font-size: var(--font12Size);
  200. }
  201. }
  202. .btn {
  203. button {
  204. border-radius: 25px;
  205. color: var(--fffColor);
  206. background-color: var(--ff0Color);
  207. font-size: var(--font12Size);
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. .scroll-view {
  216. position: absolute;
  217. top: 0;
  218. left: 0;
  219. right: 0;
  220. bottom: 0;
  221. .list-scroll-view {
  222. display: flex;
  223. flex-direction: column;
  224. }
  225. }
  226. .is_bottom {
  227. text-align: center;
  228. text {
  229. padding: 2vw 0;
  230. display: inline-block;
  231. color: #858585;
  232. font-size: 14px;
  233. }
  234. }
  235. </style>