index.vue 9.8 KB

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