index.vue 5.3 KB

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