index.vue 5.9 KB

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