index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. async onLoad() {
  53. await that.searchToken();
  54. that.searchConfig();
  55. },
  56. async onShow() {
  57. const that = this;
  58. that.clearPage();
  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. toBuy(e) {
  151. const that = this;
  152. uni.navigateTo({
  153. url: `/pagesGoods/index/index?id=${e.id||e._id}`
  154. })
  155. },
  156. // 分页
  157. toPage(e) {
  158. const that = this;
  159. let list = that.list;
  160. let limit = that.limit;
  161. if (that.total > list.length) {
  162. uni.showLoading({
  163. title: '加载中',
  164. mask: true
  165. })
  166. let page = that.page + 1;
  167. that.$set(that, `page`, page)
  168. let skip = page * limit;
  169. that.$set(that, `skip`, skip)
  170. that.search();
  171. uni.hideLoading();
  172. } else that.$set(that, `is_bottom`, true)
  173. },
  174. toScroll(e) {
  175. const that = this;
  176. let up = that.scrollTop;
  177. that.$set(that, `scrollTop`, e.detail.scrollTop);
  178. let num = Math.sign(up - e.detail.scrollTop);
  179. if (num == 1) that.$set(that, `is_bottom`, false);
  180. },
  181. // 清空列表
  182. clearPage() {
  183. const that = this;
  184. that.$set(that, `moduleList`, [])
  185. that.$set(that, `list`, [])
  186. that.$set(that, `skip`, 0)
  187. that.$set(that, `limit`, 6)
  188. that.$set(that, `page`, 0)
  189. },
  190. }
  191. }
  192. </script>
  193. <style lang="scss">
  194. .content {
  195. display: flex;
  196. flex-direction: column;
  197. width: 100vw;
  198. height: 100vh;
  199. .one {
  200. width: 100%;
  201. }
  202. .two {
  203. padding: 1vw 2vw;
  204. background-color: var(--f9Color);
  205. .grid {
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. padding: 5px 0 0 0;
  210. margin: 5px;
  211. background-color: var(--mainColor);
  212. border-radius: 10px;
  213. .image {
  214. width: 25px;
  215. height: 25px;
  216. }
  217. .text {
  218. font-size: var(--font14Size);
  219. margin-top: 5px;
  220. }
  221. }
  222. }
  223. .thr {
  224. position: relative;
  225. flex-grow: 1;
  226. background-color: var(--f9Color);
  227. .thr_1 {
  228. display: flex;
  229. justify-content: space-between;
  230. flex-wrap: wrap;
  231. padding: 2vw;
  232. .list {
  233. width: 43vw;
  234. padding: 2vw;
  235. margin: 0 0 2vw 0;
  236. border-radius: 10px;
  237. background-color: var(--mainColor);
  238. .image {
  239. width: 100%;
  240. height: 40vw;
  241. border-top-right-radius: 10px;
  242. border-top-left-radius: 10px;
  243. }
  244. .name {
  245. font-size: var(--font14Size);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. .scroll-view {
  252. position: absolute;
  253. top: 0;
  254. left: 0;
  255. right: 0;
  256. bottom: 0;
  257. .list-scroll-view {
  258. display: flex;
  259. flex-direction: column;
  260. }
  261. }
  262. .is_bottom {
  263. text-align: center;
  264. text {
  265. padding: 2vw 0;
  266. display: inline-block;
  267. color: var(--f85Color);
  268. font-size: var(--font14Size);
  269. }
  270. }
  271. </style>