index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList"
  8. :key="index" @tap="toChange(index,item)">
  9. <text>{{item.label}}</text>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. <view class="one_2">
  15. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  16. <view class="list-scroll-view">
  17. <view class=" one_2_1">
  18. <view class="list" v-for="(tag,index) in marketList" :key="index" @tap="toBuy(tag)">
  19. <view class="img">
  20. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''" mode="">
  21. </image>
  22. </view>
  23. <view class="info">
  24. <view class="name textOver">
  25. <text>{{tag.name||'暂无'}}</text>
  26. </view>
  27. <view class="num">
  28. <text>销量 {{tag.sell_num||'0'}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="is_bottom" v-if="is_bottom">
  34. <text>{{config.bottom_title}}</text>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. config: {},
  47. user: {},
  48. active: '0',
  49. typeList: [],
  50. type: '',
  51. // 商品列表
  52. marketList: [],
  53. total: 0,
  54. page: 0,
  55. skip: 0,
  56. limit: 10,
  57. // 数据是否触底
  58. is_bottom: false,
  59. scrollTop: 0,
  60. }
  61. },
  62. onLoad: function() {
  63. const that = this;
  64. that.searchToken();
  65. that.searchConfig();
  66. that.search();
  67. },
  68. onPullDownRefresh: async function() {
  69. const that = this;
  70. that.clearPages();
  71. await that.search();
  72. uni.stopPullDownRefresh();
  73. },
  74. methods: {
  75. searchToken() {
  76. const that = this;
  77. try {
  78. const res = uni.getStorageSync('token');
  79. if (res) that.$set(that, `user`, res);
  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. // 查询左侧一级列表
  102. async search() {
  103. const that = this;
  104. let res;
  105. res = await that.$api(`/DictData`, 'GET', {
  106. is_use: '0',
  107. type: 'goods_type'
  108. })
  109. if (res.errcode == '0') {
  110. that.$set(that, `typeList`, res.data);
  111. if (res.total > 0) {
  112. that.$set(that, `type`, res.data[0].value);
  113. that.searchMarket()
  114. }
  115. }
  116. },
  117. // 查询产品
  118. async searchMarket(e) {
  119. const that = this;
  120. let info = {
  121. skip: that.skip,
  122. limit: that.limit,
  123. type: that.type
  124. }
  125. const res = await that.$api(`/Good`, `GET`, {
  126. ...info,
  127. })
  128. if (res.errcode == '0') {
  129. let list = [...that.marketList, ...res.data];
  130. that.$set(that, `marketList`, list);
  131. that.$set(that, `total`, res.total)
  132. } else {
  133. uni.showToast({
  134. title: res.errmsg || '错误信息',
  135. icon: 'none'
  136. })
  137. }
  138. },
  139. // 分页
  140. toPage() {
  141. const that = this;
  142. let list = that.marketList;
  143. let limit = that.limit;
  144. if (that.total > list.length) {
  145. uni.showLoading({
  146. title: '加载中',
  147. mask: true
  148. })
  149. let page = that.page + 1;
  150. that.$set(that, `page`, page)
  151. let skip = page * limit;
  152. that.$set(that, `skip`, skip)
  153. that.searchMarket();
  154. uni.hideLoading();
  155. } else that.$set(that, `is_bottom`, true)
  156. },
  157. // 触底
  158. toScroll(e) {
  159. const that = this;
  160. let up = that.scrollTop;
  161. that.$set(that, `scrollTop`, e.detail.scrollTop);
  162. let num = Math.sign(up - e.detail.scrollTop);
  163. if (num == 1) that.$set(that, `is_bottom`, false);
  164. },
  165. // 左侧一级选择
  166. toChange(index, e) {
  167. const that = this;
  168. that.$set(that, `active`, index);
  169. that.$set(that, `type`, e.value);
  170. that.clearPage();
  171. that.searchMarket();
  172. },
  173. // 清空列表
  174. clearPage() {
  175. const that = this;
  176. that.$set(that, `marketList`, []);
  177. that.$set(that, `skip`, 0)
  178. that.$set(that, `limit`, 10)
  179. that.$set(that, `page`, 0)
  180. },
  181. // 清空总信息
  182. clearPages() {
  183. const that = this;
  184. that.$set(that, `marketList`, [])
  185. that.$set(that, `typeList`, [])
  186. that.$set(that, `active`, '0')
  187. that.$set(that, `skip`, 0)
  188. that.$set(that, `limit`, 10)
  189. that.$set(that, `page`, 0)
  190. },
  191. // 购买
  192. toBuy(e) {
  193. const that = this;
  194. uni.navigateTo({
  195. url: `/pagesGoods/index/index?id=${e.id||e._id}`
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. .content {
  203. .one {
  204. height: 100vh;
  205. display: flex;
  206. flex-direction: row;
  207. .one_1 {
  208. position: relative;
  209. width: 25vw;
  210. background-color: #fafafa;
  211. display: flex;
  212. flex-direction: column;
  213. .list {
  214. text-align: center;
  215. padding: 2.5vw 0;
  216. border-bottom: 1px solid var(--f1Color);
  217. text {
  218. font-size: var(--font14Size);
  219. }
  220. }
  221. .listActive {
  222. background-color: var(--fffColor);
  223. }
  224. }
  225. .one_2 {
  226. flex-grow: 1;
  227. position: relative;
  228. display: flex;
  229. flex-direction: column;
  230. .one_2_1 {
  231. padding: 0 2vw;
  232. width: 70vw;
  233. .list {
  234. display: flex;
  235. width: 66vw;
  236. margin: 0 0 2vw 0;
  237. padding: 2vw;
  238. box-shadow: 0 0 5px var(--f1Color);
  239. border-radius: 5px;
  240. .img {
  241. width: 20vw;
  242. .image {
  243. width: 20vw;
  244. height: 20vw;
  245. border-radius: 5px;
  246. }
  247. }
  248. .info {
  249. width: 45vw;
  250. padding: 0 0 0 2vw;
  251. .name {
  252. font-size: var(--font15Size);
  253. margin: 0 0 1vw 0;
  254. }
  255. .num {
  256. font-size: var(--font14Size);
  257. color: var(--f85Color);
  258. margin: 0 0 1vw 0;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. .scroll-view {
  267. position: absolute;
  268. top: 0;
  269. left: 0;
  270. right: 0;
  271. bottom: 0;
  272. .list-scroll-view {
  273. display: flex;
  274. flex-direction: column;
  275. }
  276. }
  277. .is_bottom {
  278. width: 100%;
  279. text-align: center;
  280. text {
  281. padding: 2vw 0;
  282. display: inline-block;
  283. color: var(--f85Color);
  284. font-size: var(--font14Size);
  285. }
  286. }
  287. </style>