index.vue 6.3 KB

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