index.vue 5.8 KB

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