index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" placeholder="搜索商品" @tap="toCommon('pagesHome/market/search')"
  6. placeholder-class="placss">
  7. </view>
  8. <view class="two">
  9. <view class="two_1">
  10. <scroll-view scroll-y="true" class="scroll-view">
  11. <view class="list-scroll-view">
  12. <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList"
  13. :key="index" @tap="toChange(index,item)">
  14. <text>{{item.label}}</text>
  15. </view>
  16. </view>
  17. </scroll-view>
  18. </view>
  19. <view class="two_2">
  20. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  21. <view class="list-scroll-view">
  22. <view class="two_2_1">
  23. <scroll-view scroll-x="true" class="typeScrollview">
  24. <view class="list" v-for="(item,index) in list" :key="index"
  25. @tap="twoChange(item,index)">
  26. <image class="image"
  27. :src="item.file&&item.file.length>0?item.file[0].url:logoUrl" mode="">
  28. </image>
  29. <view class="label textOver">
  30. <text
  31. :style="{color:twoActive==index?'var(--fFB1Color)':'#000000'}">{{item.label}}</text>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. <view class=" two_2_2">
  37. <view class="list" v-for="(tag,index) in marketList" :key="index" @tap="toBuy(tag)">
  38. <view class="img">
  39. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''"
  40. mode=""></image>
  41. </view>
  42. <view class="info">
  43. <view class="name textOver">
  44. <text>{{tag.name}}</text>
  45. </view>
  46. <view class="num">
  47. <text>库存{{tag.num}}</text>
  48. </view>
  49. <view class="money">
  50. <text>¥{{tag.sell_money}}</text>
  51. </view>
  52. <view class="other" v-if="tag.p_act">
  53. <text class="act" v-for="(tags,indexx) in tag.p_act"
  54. :key="indexx">{{tags}}</text>
  55. </view>
  56. <view class="other" v-if="tag.leader_price">
  57. <view class="leader">
  58. <text>会员价</text><text>¥</text><text>{{tag.leader_price||0}}</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="is_bottom" v-if="is_bottom">
  65. <text>{{config.bottom_title}}</text>
  66. </view>
  67. </view>
  68. </scroll-view>
  69. </view>
  70. </view>
  71. </view>
  72. </mobile-frame>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. frameStyle: {
  79. useBar: true
  80. },
  81. active: '0',
  82. typeList: [],
  83. list: [],
  84. // 平台信息
  85. config: {},
  86. logoUrl: '',
  87. // 商品分类tags
  88. tags: '',
  89. twoActive: null,
  90. // 商品列表
  91. marketList: [],
  92. total: 0,
  93. page: 0,
  94. skip: 0,
  95. limit: 10,
  96. // 数据是否触底
  97. is_bottom: false,
  98. scrollTop: 0,
  99. };
  100. },
  101. onLoad: function() {
  102. const that = this;
  103. that.searchConfig();
  104. that.search();
  105. },
  106. onPullDownRefresh: async function() {
  107. const that = this;
  108. that.clearPages();
  109. await that.search();
  110. uni.stopPullDownRefresh();
  111. },
  112. methods: {
  113. // 查询基本设置
  114. searchConfig() {
  115. const that = this;
  116. uni.getStorage({
  117. key: 'config',
  118. success: function(res) {
  119. let data = res.data;
  120. that.$set(that, `config`, data)
  121. if (data) {
  122. that.$set(that, `logoUrl`, data.config.logo[0].url)
  123. }
  124. },
  125. fail: function(err) {
  126. console.log(err);
  127. }
  128. })
  129. },
  130. // 查询左侧一级列表
  131. async search() {
  132. const that = this;
  133. let res;
  134. res = await that.$api(`/goodsTags`, 'GET', {
  135. status: '0'
  136. })
  137. if (res.errcode == '0') {
  138. that.$set(that, `typeList`, res.data);
  139. if (res.total > 0) {
  140. that.searchRight(res.data[0]);
  141. // 查询产品
  142. that.$set(that, `tags`, res.data[0].code)
  143. that.searchMarket()
  144. }
  145. }
  146. },
  147. // 查询左侧二级信息
  148. async searchRight(e) {
  149. const that = this;
  150. let info = {};
  151. if (e.id) info.pid = e.id;
  152. const res = await that.$api(`/goodsTags/tree`, 'GET', {
  153. ...info
  154. })
  155. if (res.errcode == '0' && res.data.length > 0) {
  156. that.$set(that, `list`, res.data[0].children);
  157. }
  158. },
  159. // 查询产品
  160. async searchMarket() {
  161. const that = this;
  162. let info = {
  163. skip: that.skip,
  164. limit: that.limit,
  165. tags: that.tags
  166. }
  167. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  168. ...info,
  169. })
  170. if (res.errcode == '0') {
  171. let list = [...that.marketList, ...res.data];
  172. that.$set(that, `marketList`, list);
  173. that.$set(that, `total`, res.total)
  174. } else {
  175. uni.showToast({
  176. title: res.errmsg || '错误信息',
  177. icon: 'none'
  178. })
  179. }
  180. },
  181. // 分页
  182. toPage() {
  183. const that = this;
  184. let list = that.marketList;
  185. let limit = that.limit;
  186. if (that.total > list.length) {
  187. uni.showLoading({
  188. title: '加载中',
  189. mask: true
  190. })
  191. let page = that.page + 1;
  192. that.$set(that, `page`, page)
  193. let skip = page * limit;
  194. that.$set(that, `skip`, skip)
  195. that.searchMarket();
  196. uni.hideLoading();
  197. } else that.$set(that, `is_bottom`, true)
  198. },
  199. // 触底
  200. toScroll(e) {
  201. const that = this;
  202. let up = that.scrollTop;
  203. that.$set(that, `scrollTop`, e.detail.scrollTop);
  204. let num = Math.sign(up - e.detail.scrollTop);
  205. if (num == 1) that.$set(that, `is_bottom`, false);
  206. },
  207. // 左侧一级选择
  208. toChange(index, e) {
  209. const that = this;
  210. that.$set(that, `list`, []);
  211. that.$set(that, `active`, index);
  212. that.$set(that, `tags`, e.code);
  213. that.$set(that, `twoActive`, null);
  214. that.clearPage();
  215. that.searchRight(e);
  216. that.searchMarket();
  217. },
  218. // 右侧二级选择
  219. twoChange(e, index) {
  220. const that = this;
  221. that.$set(that, `tags`, e.code);
  222. that.$set(that, `twoActive`, index);
  223. that.clearPage();
  224. that.searchMarket();
  225. },
  226. // 清空列表
  227. clearPage() {
  228. const that = this;
  229. that.$set(that, `marketList`, []);
  230. that.$set(that, `skip`, 0)
  231. that.$set(that, `limit`, 10)
  232. that.$set(that, `page`, 0)
  233. },
  234. // 清空总信息
  235. clearPages() {
  236. const that = this;
  237. that.$set(that, `list`, [])
  238. that.$set(that, `marketList`, [])
  239. that.$set(that, `typeList`, [])
  240. that.$set(that, `active`, '0')
  241. that.$set(that, `skip`, 0)
  242. that.$set(that, `limit`,10)
  243. that.$set(that, `page`, 0)
  244. },
  245. // 搜索商品
  246. toCommon(e) {
  247. const that = this;
  248. uni.navigateTo({
  249. url: `/${e}`
  250. })
  251. },
  252. // 购买
  253. toBuy(e) {
  254. const that = this;
  255. uni.navigateTo({
  256. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  257. })
  258. },
  259. // 菜单跳转
  260. toPath(e) {
  261. let url = `/${e.route}`;
  262. if (e.type == '0') uni.redirectTo({
  263. url
  264. })
  265. else {
  266. uni.navigateTo({
  267. url
  268. })
  269. }
  270. },
  271. },
  272. }
  273. </script>
  274. <style lang="scss">
  275. .main {
  276. display: flex;
  277. flex-direction: column;
  278. width: 100vw;
  279. height: 91vh;
  280. .one {
  281. padding: 2vw;
  282. border: 1px solid var(--f1Color);
  283. input {
  284. background-color: var(--fFB1Color);
  285. border-radius: 30px;
  286. padding: 2vw;
  287. color: var(--fffColor);
  288. font-size: var(--font15Size);
  289. }
  290. .placss {
  291. color: var(--fffColor);
  292. }
  293. }
  294. .two {
  295. height: 83vh;
  296. display: flex;
  297. flex-direction: row;
  298. .two_1 {
  299. position: relative;
  300. width: 25vw;
  301. background-color: #fafafa;
  302. display: flex;
  303. flex-direction: column;
  304. .list {
  305. text-align: center;
  306. padding: 2.5vw 0;
  307. border-bottom: 1px solid var(--f1Color);
  308. text {
  309. font-size: var(--font14Size);
  310. }
  311. }
  312. .listActive {
  313. background-color: var(--fffColor);
  314. }
  315. }
  316. .two_2 {
  317. flex-grow: 1;
  318. position: relative;
  319. display: flex;
  320. flex-direction: column;
  321. .two_2_1 {
  322. padding: 0 2vw;
  323. margin: 0 0 2vw 0;
  324. .typeScrollview {
  325. display: flex;
  326. white-space: nowrap;
  327. .list {
  328. display: inline-block;
  329. width: 14vw;
  330. padding: 1vw;
  331. text-align: center;
  332. border-radius: 5px;
  333. margin: 0 2vw 0 0;
  334. .image {
  335. width: 100%;
  336. height: 7vh;
  337. border-radius: 5px;
  338. border: 1px solid var(--f1Color);
  339. ;
  340. }
  341. .label {
  342. font-size: var(--font12Size);
  343. }
  344. }
  345. }
  346. }
  347. .two_2_2 {
  348. padding: 0 2vw;
  349. width: 70vw;
  350. .list {
  351. display: flex;
  352. width: 66vw;
  353. margin: 0 0 2vw 0;
  354. padding: 2vw;
  355. box-shadow: 0 0 5px var(--f1Color);
  356. ;
  357. border-radius: 5px;
  358. .img {
  359. width: 20vw;
  360. .image {
  361. width: 20vw;
  362. height: 20vw;
  363. border-radius: 5px;
  364. }
  365. }
  366. .info {
  367. width: 45vw;
  368. padding: 0 0 0 2vw;
  369. .name {
  370. font-size: var(--font15Size);
  371. margin: 0 0 1vw 0;
  372. }
  373. .num {
  374. font-size: var(--font14Size);
  375. color: #858585;
  376. margin: 0 0 1vw 0;
  377. }
  378. .money {
  379. font-size: var(--font14Size);
  380. color: var(--fFB1Color);
  381. margin: 0 0 1vw 0;
  382. }
  383. .other {
  384. display: flex;
  385. .leader {
  386. font-size: 12px;
  387. text-align: center;
  388. color: #23B67A;
  389. text:last-child {
  390. font-size: 16px;
  391. padding: 0 0 0 1vw;
  392. }
  393. }
  394. .act {
  395. font-size: 12px;
  396. color: #FFA500;
  397. border: 1px solid #FFA500;
  398. border-radius: 5px;
  399. padding: 0 1vw;
  400. margin: 0 1vw 0 0;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. .scroll-view {
  410. position: absolute;
  411. top: 0;
  412. left: 0;
  413. right: 0;
  414. bottom: 0;
  415. .list-scroll-view {
  416. display: flex;
  417. flex-direction: column;
  418. }
  419. }
  420. .is_bottom {
  421. text-align: center;
  422. text {
  423. padding: 2vw 0;
  424. display: inline-block;
  425. color: #858585;
  426. font-size: 14px;
  427. }
  428. }
  429. </style>