index.vue 5.8 KB

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