index.vue 6.1 KB

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