index.vue 4.9 KB

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