index.vue 5.0 KB

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