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