index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <uni-search-bar placeholder="搜索" bgColor="#EEEEEE" @confirm="toSearch" @input="input" />
  5. </view>
  6. <view class="two">
  7. <uni-grid :column="4" :show-border="false" :square="false">
  8. <uni-grid-item v-for="(item, index) in moduleList" :index="index" :key="index" @tap="change(item)">
  9. <view class="grid">
  10. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode="aspectFill">
  11. </image>
  12. <text class="text">{{ item.name }}</text>
  13. </view>
  14. </uni-grid-item>
  15. </uni-grid>
  16. </view>
  17. <view class="thr">
  18. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  19. <view class="list-scroll-view">
  20. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  21. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="aspectFill">
  22. </image>
  23. <view class="name textOver">{{item.name}}</view>
  24. </view>
  25. <view class="is_bottom" v-if="is_bottom">
  26. <text>已经到底了!</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. moduleList: [],
  38. list: [],
  39. total: 0,
  40. skip: 0,
  41. limit: 6,
  42. page: 0,
  43. // 数据是否触底
  44. is_bottom: false,
  45. scrollTop: 0,
  46. }
  47. },
  48. async onLoad() {
  49. const that = this;
  50. await that.searchToken();
  51. await that.search();
  52. },
  53. onShow() {
  54. },
  55. onPullDownRefresh: async function() {
  56. const that = this;
  57. that.clearPage();
  58. await that.search();
  59. uni.stopPullDownRefresh();
  60. },
  61. methods: {
  62. async searchToken() {
  63. const that = this;
  64. uni.getStorage({
  65. key: 'token',
  66. success: async function(res) {
  67. // 替换底部菜单
  68. let aee = await that.$api(`/Role/menu`, 'GET', {
  69. is_use: '0',
  70. code: res.data.role
  71. });
  72. if (aee.errcode == '0') {
  73. if (aee.data.menu && aee.data.menu.length > 0) {
  74. for (let val of aee.data.menu) {
  75. uni.setTabBarItem({
  76. index: val.index,
  77. text: val.text,
  78. pagePath: val.pagePath,
  79. iconPath: val.iconPath[0].url,
  80. selectedIconPath: val.selectedIconPath[0].url,
  81. })
  82. }
  83. }
  84. }
  85. },
  86. fail: function(err) {
  87. uni.showToast({
  88. title: err.errmsg,
  89. icon: 'error',
  90. duration: 2000
  91. });
  92. }
  93. })
  94. },
  95. async search() {
  96. const that = this;
  97. let res;
  98. res = await that.$api(`/Module`, 'GET', {
  99. is_use: '0'
  100. });
  101. if (res.errcode == '0') that.$set(that, `moduleList`, res.data);
  102. let info = {
  103. skip: that.skip,
  104. limit: that.limit,
  105. is_use: '0'
  106. }
  107. res = await that.$api(`/Good`, 'GET', {
  108. ...info
  109. })
  110. if (res.errcode == '0') {
  111. let list = [...that.list, ...res.data];
  112. that.$set(that, `list`, list)
  113. that.$set(that, `total`, res.total)
  114. } else {
  115. uni.showToast({
  116. title: res.errmsg,
  117. });
  118. }
  119. },
  120. async toSearch(res) {
  121. console.log(res);
  122. },
  123. async input(res) {
  124. console.log(res)
  125. },
  126. async change(e) {
  127. console.log(e);
  128. },
  129. // 分页
  130. toPage(e) {
  131. const that = this;
  132. let list = that.list;
  133. let limit = that.limit;
  134. if (that.total > list.length) {
  135. uni.showLoading({
  136. title: '加载中',
  137. mask: true
  138. })
  139. let page = that.page + 1;
  140. that.$set(that, `page`, page)
  141. let skip = page * limit;
  142. that.$set(that, `skip`, skip)
  143. that.search();
  144. uni.hideLoading();
  145. } else that.$set(that, `is_bottom`, true)
  146. },
  147. toScroll(e) {
  148. const that = this;
  149. let up = that.scrollTop;
  150. that.$set(that, `scrollTop`, e.detail.scrollTop);
  151. let num = Math.sign(up - e.detail.scrollTop);
  152. if (num == 1) that.$set(that, `is_bottom`, false);
  153. },
  154. // 清空列表
  155. clearPage() {
  156. const that = this;
  157. that.$set(that, `moduleList`, [])
  158. that.$set(that, `list`, [])
  159. that.$set(that, `skip`, 0)
  160. that.$set(that, `limit`, 6)
  161. that.$set(that, `page`, 0)
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. .content {
  168. display: flex;
  169. flex-direction: column;
  170. width: 100vw;
  171. height: 100vh;
  172. .one {
  173. width: 100%;
  174. }
  175. .two {
  176. padding: 1vw 2vw;
  177. background-color: var(--f9Color);
  178. .grid {
  179. display: flex;
  180. flex-direction: column;
  181. align-items: center;
  182. padding: 5px 0 0 0;
  183. margin: 5px;
  184. background-color: var(--mainColor);
  185. border-radius: 10px;
  186. .image {
  187. width: 25px;
  188. height: 25px;
  189. }
  190. .text {
  191. font-size: var(--font14Size);
  192. margin-top: 5px;
  193. }
  194. }
  195. }
  196. .thr {
  197. position: relative;
  198. flex-grow: 1;
  199. display: flex;
  200. justify-content: space-between;
  201. flex-wrap: wrap;
  202. padding: 2vw;
  203. background-color: var(--f9Color);
  204. .list {
  205. position: relative;
  206. width: 43vw;
  207. padding: 2vw;
  208. margin: 0 0 2vw 0;
  209. border-radius: 10px;
  210. background-color: var(--mainColor);
  211. .image {
  212. width: 100%;
  213. height: 40vw;
  214. border-top-right-radius: 10px;
  215. border-top-left-radius: 10px;
  216. }
  217. .name {
  218. font-size: var(--font14Size);
  219. }
  220. }
  221. }
  222. }
  223. .scroll-view {
  224. position: absolute;
  225. top: 0;
  226. left: 0;
  227. right: 0;
  228. bottom: 0;
  229. .list-scroll-view {
  230. display: flex;
  231. flex-direction: column;
  232. }
  233. }
  234. .is_bottom {
  235. text-align: center;
  236. text {
  237. padding: 2vw 0;
  238. display: inline-block;
  239. color: var(--f85Color);
  240. font-size: var(--font14Size);
  241. }
  242. }
  243. </style>