index.vue 7.2 KB

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