index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-view" @scroll="scroll">
  18. <view class="list-scroll-view">
  19. <view class="thr">
  20. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  21. <image :src="item.file" class="image" mode="aspectFill" />
  22. <view class="name textOver">{{item.name}}</view>
  23. </view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. moduleList: [],
  34. list: [{
  35. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  36. type: '0',
  37. file: '/static/lenovo.jpeg',
  38. brief: '联想(Lenovo)LT201黑色墨粉盒',
  39. },
  40. {
  41. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  42. type: '0',
  43. file: '/static/lenovo.jpeg',
  44. brief: '联想(Lenovo)LT201黑色墨粉盒',
  45. },
  46. {
  47. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  48. type: '0',
  49. file: '/static/lenovo.jpeg',
  50. brief: '联想(Lenovo)LT201黑色墨粉盒',
  51. },
  52. {
  53. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  54. type: '0',
  55. file: '/static/lenovo.jpeg',
  56. brief: '联想(Lenovo)LT201黑色墨粉盒',
  57. },
  58. {
  59. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  60. type: '0',
  61. file: '/static/lenovo.jpeg',
  62. brief: '联想(Lenovo)LT201黑色墨粉盒',
  63. },
  64. {
  65. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  66. type: '0',
  67. file: '/static/lenovo.jpeg',
  68. brief: '联想(Lenovo)LT201黑色墨粉盒',
  69. },
  70. {
  71. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  72. type: '0',
  73. file: '/static/lenovo.jpeg',
  74. brief: '联想(Lenovo)LT201黑色墨粉盒',
  75. },
  76. {
  77. name: '联想(Lenovo)LT201黑色墨粉盒(适用S1801/LJ2205/M1851/M7206W/M7255F/F2081/LJ2206W/M7256WHF打印机)',
  78. type: '0',
  79. file: '/static/lenovo.jpeg',
  80. brief: '联想(Lenovo)LT201黑色墨粉盒',
  81. }
  82. ],
  83. total: 0,
  84. skip: 0,
  85. limit: 6,
  86. page: 0,
  87. // 返回顶部
  88. scrollTop: 0,
  89. }
  90. },
  91. async onLoad() {
  92. const that = this;
  93. await that.searchToken();
  94. await that.search();
  95. },
  96. onShow() {
  97. },
  98. methods: {
  99. async searchToken() {
  100. const that = this;
  101. uni.getStorage({
  102. key: 'token',
  103. success: async function(res) {
  104. // 替换底部菜单
  105. let aee = await that.$api(`/Role/menu`, 'GET', {
  106. is_use: '0',
  107. code: res.data.role
  108. });
  109. if (aee.errcode == '0') {
  110. if (aee.data.menu && aee.data.menu.length > 0) {
  111. for (let val of aee.data.menu) {
  112. uni.setTabBarItem({
  113. index: val.index,
  114. text: val.text,
  115. pagePath: val.pagePath,
  116. iconPath: val.iconPath[0].url,
  117. selectedIconPath: val.selectedIconPath[0].url,
  118. })
  119. }
  120. }
  121. }
  122. },
  123. fail: function(err) {
  124. uni.showToast({
  125. title: err.errmsg,
  126. icon: 'error',
  127. duration: 2000
  128. });
  129. }
  130. })
  131. },
  132. async search() {
  133. const that = this;
  134. let res = await that.$api(`/Module`, 'GET', {
  135. is_use: '0'
  136. });
  137. if (res.errcode == '0') that.$set(that, `moduleList`, res.data);
  138. },
  139. async toSearch(res) {
  140. console.log(res);
  141. },
  142. async input(res) {
  143. console.log(res)
  144. },
  145. async change(e) {
  146. console.log(e);
  147. },
  148. // 分页
  149. toPage(e) {
  150. const that = this;
  151. let list = that.list;
  152. let limit = that.limit;
  153. if (that.total > list.length) {
  154. uni.showLoading({
  155. title: '加载中',
  156. mask: true
  157. })
  158. let page = that.page + 1;
  159. that.$set(that, `page`, page)
  160. let skip = page * limit;
  161. that.$set(that, `skip`, skip)
  162. that.searchMarket();
  163. uni.hideLoading();
  164. }
  165. },
  166. // 计算高度
  167. scroll: function(e) {
  168. const that = this;
  169. that.old_scrollTop = e.detail.scrollTop
  170. },
  171. clearPage() {
  172. const that = this;
  173. that.$set(that, `moduleList`, [])
  174. that.$set(that, `list`, [])
  175. that.$set(that, `skip`, 0)
  176. that.$set(that, `limit`, 6)
  177. that.$set(that, `page`, 0)
  178. },
  179. }
  180. }
  181. </script>
  182. <style lang="scss">
  183. .content {
  184. display: flex;
  185. flex-direction: column;
  186. .one {
  187. width: 100%;
  188. }
  189. .two {
  190. padding: 1vw 2vw;
  191. background-color: var(--f8Color);
  192. .grid {
  193. display: flex;
  194. flex-direction: column;
  195. align-items: center;
  196. padding: 5px 0 0 0;
  197. margin: 5px;
  198. background-color: var(--mainColor);
  199. border-radius: 10px;
  200. .image {
  201. width: 25px;
  202. height: 25px;
  203. }
  204. .text {
  205. font-size: var(--font14Size);
  206. margin-top: 5px;
  207. }
  208. }
  209. }
  210. .thr {
  211. display: flex;
  212. justify-content: space-between;
  213. flex-wrap: wrap;
  214. padding: 2vw;
  215. background-color: var(--f8Color);
  216. .list {
  217. position: relative;
  218. width: 43vw;
  219. padding: 2vw;
  220. margin: 0 0 2vw 0;
  221. border-radius: 10px;
  222. background-color: var(--mainColor);
  223. .image {
  224. width: 100%;
  225. height: 40vw;
  226. border-top-right-radius: 10px;
  227. border-top-left-radius: 10px;
  228. }
  229. .name {
  230. font-size: var(--font14Size);
  231. }
  232. }
  233. }
  234. }
  235. .scroll-view {
  236. // height: 100vw;
  237. }
  238. </style>