index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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>{{item.cost}}</text>
  20. </view>
  21. <view class="btn">
  22. <button type="default" size="mini" @click="toBuy(item)">兑换</button>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. <view class="is_bottom" v-if="is_bottom">
  31. <text>{{config.bottom_title}}</text>
  32. </view>
  33. </view>
  34. </mobile-frame>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. // 系统设置
  41. config: {},
  42. searchInfo: {},
  43. list: [],
  44. total: 0,
  45. page: 0,
  46. skip: 0,
  47. limit: 10,
  48. // 数据是否触底
  49. is_bottom: false,
  50. scrollTop: 0
  51. };
  52. },
  53. onLoad: async function(e) {
  54. const that = this;
  55. that.searchConfig();
  56. await that.search();
  57. },
  58. onPullDownRefresh: async function() {
  59. const that = this;
  60. that.clearPage();
  61. await that.search();
  62. uni.stopPullDownRefresh();
  63. },
  64. methods: {
  65. // 查询基本设置
  66. searchConfig() {
  67. const that = this;
  68. uni.getStorage({
  69. key: 'config',
  70. success: function(res) {
  71. if (res.data) that.$set(that, `config`, res.data)
  72. },
  73. fail: function(err) {
  74. console.log(err);
  75. }
  76. })
  77. },
  78. async search() {
  79. const that = this;
  80. let info = {
  81. skip: that.skip,
  82. limit: that.limit,
  83. }
  84. const res = await that.$api(`/zrGoods`, `GET`, {
  85. ...info,
  86. ...that.searchInfo
  87. }, `integral`)
  88. if (res.errcode == '0') {
  89. let list = [...that.list, ...res.data]
  90. that.$set(that, `list`, list)
  91. that.$set(that, `total`, res.total)
  92. } else {
  93. uni.showToast({
  94. title: res.errmsg,
  95. });
  96. }
  97. },
  98. // 分页
  99. toPage() {
  100. const that = this;
  101. let list = that.list;
  102. let limit = that.limit;
  103. if (that.total > list.length) {
  104. uni.showLoading({
  105. title: '加载中',
  106. mask: true
  107. })
  108. let page = that.page + 1;
  109. that.$set(that, `page`, page)
  110. let skip = page * limit;
  111. that.$set(that, `skip`, skip)
  112. that.search();
  113. uni.hideLoading();
  114. } else that.$set(that, `is_bottom`, true)
  115. },
  116. toScroll(e) {
  117. const that = this;
  118. let up = that.scrollTop;
  119. that.$set(that, `scrollTop`, e.detail.scrollTop);
  120. let num = Math.sign(up - e.detail.scrollTop);
  121. if (num == 1) that.$set(that, `is_bottom`, false);
  122. },
  123. // 输入框
  124. toInput(e) {
  125. const that = this;
  126. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  127. that.clearPage();
  128. that.search();
  129. },
  130. toBuy(e) {
  131. uni.navigateTo({
  132. url: `/pagesIntegral/order/detail?id=${e._id}`
  133. })
  134. },
  135. // 清空列表
  136. clearPage() {
  137. const that = this;
  138. that.$set(that, `list`, [])
  139. that.$set(that, `skip`, 0)
  140. that.$set(that, `limit`, 6)
  141. that.$set(that, `page`, 0)
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss">
  147. .main {
  148. display: flex;
  149. flex-direction: column;
  150. width: 100vw;
  151. height: 100vh;
  152. .one {
  153. border-bottom: 1px solid var(--f85Color);
  154. padding: 2vw;
  155. input {
  156. padding: 2vw;
  157. background-color: var(--f1Color);
  158. font-size: var(--font14Size);
  159. border-radius: 5px;
  160. }
  161. }
  162. .two {
  163. position: relative;
  164. flex-grow: 1;
  165. .two_1 {
  166. display: flex;
  167. justify-content: space-between;
  168. flex-wrap: wrap;
  169. .list {
  170. width: 43vw;
  171. background: #fff;
  172. padding: 2vw;
  173. border-radius: 5px;
  174. margin: 2vw 1vw 0 1vw;
  175. border: 1px solid var(--f1Color);
  176. .image {
  177. width: 100%;
  178. height: 43vw;
  179. }
  180. .name {
  181. font-size: var(--font15Size);
  182. margin: 0 0 2vw 0;
  183. }
  184. .other {
  185. display: flex;
  186. flex-direction: row;
  187. justify-content: space-between;
  188. .money {
  189. color: var(--fFB1Color);
  190. }
  191. .btn {
  192. button {
  193. border-radius: 25px;
  194. color: var(--fffColor);
  195. background-color: #6A5ACD;
  196. font-size: var(--font12Size);
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. .scroll-view {
  205. position: absolute;
  206. top: 0;
  207. left: 0;
  208. right: 0;
  209. bottom: 0;
  210. .list-scroll-view {
  211. display: flex;
  212. flex-direction: column;
  213. }
  214. }
  215. .is_bottom {
  216. text-align: center;
  217. text {
  218. padding: 2vw 0;
  219. display: inline-block;
  220. color: #858585;
  221. font-size: 14px;
  222. }
  223. }
  224. </style>