index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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: async function() {
  102. const that = this;
  103. await that.search();
  104. await that.searchConfig();
  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. shop: that.$config.shop,
  137. })
  138. if (res.errcode == '0') {
  139. that.$set(that, `typeList`, res.data);
  140. if (res.total > 0) {
  141. that.searchRight(res.data[0]);
  142. // 查询产品
  143. that.$set(that, `tags`, res.data[0].code)
  144. that.searchMarket()
  145. }
  146. }
  147. },
  148. // 查询左侧二级信息
  149. async searchRight(e) {
  150. const that = this;
  151. let info = {
  152. shop: that.$config.shop,
  153. };
  154. if (e.id) info.pid = e.id;
  155. const res = await that.$api(`/goodsTags/tree`, 'GET', {
  156. ...info
  157. })
  158. if (res.errcode == '0' && res.data.length > 0) {
  159. that.$set(that, `list`, res.data[0].children);
  160. }
  161. },
  162. // 查询产品
  163. async searchMarket() {
  164. const that = this;
  165. let info = {
  166. skip: that.skip,
  167. limit: that.limit,
  168. tags: that.tags,
  169. shop: that.$config.shop,
  170. }
  171. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  172. ...info,
  173. })
  174. if (res.errcode == '0') {
  175. let list = [...that.marketList, ...res.data];
  176. that.$set(that, `marketList`, list);
  177. that.$set(that, `total`, res.total)
  178. } else {
  179. uni.showToast({
  180. title: res.errmsg || '错误信息',
  181. icon: 'none'
  182. })
  183. }
  184. },
  185. // 分页
  186. toPage() {
  187. const that = this;
  188. let list = that.marketList;
  189. let limit = that.limit;
  190. if (that.total > list.length) {
  191. uni.showLoading({
  192. title: '加载中',
  193. mask: true
  194. })
  195. let page = that.page + 1;
  196. that.$set(that, `page`, page)
  197. let skip = page * limit;
  198. that.$set(that, `skip`, skip)
  199. that.searchMarket();
  200. uni.hideLoading();
  201. } else that.$set(that, `is_bottom`, true)
  202. },
  203. // 触底
  204. toScroll(e) {
  205. const that = this;
  206. let up = that.scrollTop;
  207. that.$set(that, `scrollTop`, e.detail.scrollTop);
  208. let num = Math.sign(up - e.detail.scrollTop);
  209. if (num == 1) that.$set(that, `is_bottom`, false);
  210. },
  211. // 左侧一级选择
  212. toChange(index, e) {
  213. const that = this;
  214. that.$set(that, `list`, []);
  215. that.$set(that, `active`, index);
  216. that.$set(that, `tags`, e.code);
  217. that.$set(that, `twoActive`, null);
  218. that.clearPage();
  219. that.searchRight(e);
  220. that.searchMarket();
  221. },
  222. // 右侧二级选择
  223. twoChange(e, index) {
  224. const that = this;
  225. that.$set(that, `tags`, e.code);
  226. that.$set(that, `twoActive`, index);
  227. that.clearPage();
  228. that.searchMarket();
  229. },
  230. // 清空列表
  231. clearPage() {
  232. const that = this;
  233. that.$set(that, `marketList`, []);
  234. that.$set(that, `skip`, 0)
  235. that.$set(that, `limit`, 10)
  236. that.$set(that, `page`, 0)
  237. },
  238. // 清空总信息
  239. clearPages() {
  240. const that = this;
  241. that.$set(that, `list`, [])
  242. that.$set(that, `marketList`, [])
  243. that.$set(that, `typeList`, [])
  244. that.$set(that, `active`, '0')
  245. that.$set(that, `skip`, 0)
  246. that.$set(that, `limit`, 10)
  247. that.$set(that, `page`, 0)
  248. },
  249. // 搜索商品
  250. toCommon(e) {
  251. const that = this;
  252. uni.navigateTo({
  253. url: `/${e}`
  254. })
  255. },
  256. // 购买
  257. toBuy(e) {
  258. const that = this;
  259. uni.navigateTo({
  260. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  261. })
  262. },
  263. // 菜单跳转
  264. toPath(e) {
  265. let url = `/${e.route}`;
  266. if (e.type == '0') uni.redirectTo({
  267. url
  268. })
  269. else {
  270. uni.navigateTo({
  271. url
  272. })
  273. }
  274. }
  275. },
  276. }
  277. </script>
  278. <style lang="scss">
  279. .main {
  280. display: flex;
  281. flex-direction: column;
  282. width: 100vw;
  283. height: 91vh;
  284. .one {
  285. padding: 2vw;
  286. border: 1px solid var(--f1Color);
  287. input {
  288. background-color: var(--fFB1Color);
  289. border-radius: 30px;
  290. padding: 2vw;
  291. color: var(--fffColor);
  292. font-size: var(--font15Size);
  293. }
  294. .placss {
  295. color: var(--fffColor);
  296. }
  297. }
  298. .two {
  299. height: 83vh;
  300. display: flex;
  301. flex-direction: row;
  302. .two_1 {
  303. position: relative;
  304. width: 25vw;
  305. background-color: #fafafa;
  306. display: flex;
  307. flex-direction: column;
  308. .list {
  309. text-align: center;
  310. padding: 2.5vw 0;
  311. border-bottom: 1px solid var(--f1Color);
  312. text {
  313. font-size: var(--font14Size);
  314. }
  315. }
  316. .listActive {
  317. background-color: var(--fffColor);
  318. }
  319. }
  320. .two_2 {
  321. flex-grow: 1;
  322. position: relative;
  323. display: flex;
  324. flex-direction: column;
  325. .two_2_1 {
  326. padding: 0 2vw;
  327. margin: 0 0 2vw 0;
  328. .typeScrollview {
  329. display: flex;
  330. white-space: nowrap;
  331. .list {
  332. display: inline-block;
  333. width: 14vw;
  334. padding: 1vw;
  335. text-align: center;
  336. border-radius: 5px;
  337. margin: 0 2vw 0 0;
  338. .image {
  339. width: 100%;
  340. height: 7vh;
  341. border-radius: 5px;
  342. border: 1px solid var(--f1Color);
  343. ;
  344. }
  345. .label {
  346. font-size: var(--font12Size);
  347. }
  348. }
  349. }
  350. }
  351. .two_2_2 {
  352. padding: 0 2vw;
  353. width: 70vw;
  354. .list {
  355. display: flex;
  356. width: 66vw;
  357. margin: 0 0 2vw 0;
  358. padding: 2vw;
  359. box-shadow: 0 0 5px var(--f1Color);
  360. ;
  361. border-radius: 5px;
  362. .img {
  363. width: 20vw;
  364. .image {
  365. width: 20vw;
  366. height: 20vw;
  367. border-radius: 5px;
  368. }
  369. }
  370. .info {
  371. width: 45vw;
  372. padding: 0 0 0 2vw;
  373. .name {
  374. font-size: var(--font15Size);
  375. margin: 0 0 1vw 0;
  376. }
  377. .num {
  378. font-size: var(--font14Size);
  379. color: #858585;
  380. margin: 0 0 1vw 0;
  381. }
  382. .money {
  383. font-size: var(--font14Size);
  384. color: var(--fFB1Color);
  385. margin: 0 0 1vw 0;
  386. }
  387. .other {
  388. display: flex;
  389. .leader {
  390. font-size: 12px;
  391. text-align: center;
  392. color: #23B67A;
  393. text:last-child {
  394. font-size: 16px;
  395. padding: 0 0 0 1vw;
  396. }
  397. }
  398. .act {
  399. font-size: 12px;
  400. color: #FFA500;
  401. border: 1px solid #FFA500;
  402. border-radius: 5px;
  403. padding: 0 1vw;
  404. margin: 0 1vw 0 0;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. .scroll-view {
  414. position: absolute;
  415. top: 0;
  416. left: 0;
  417. right: 0;
  418. bottom: 0;
  419. .list-scroll-view {
  420. display: flex;
  421. flex-direction: column;
  422. }
  423. }
  424. .is_bottom {
  425. text-align: center;
  426. text {
  427. padding: 2vw 0;
  428. display: inline-block;
  429. color: #858585;
  430. font-size: 14px;
  431. }
  432. }
  433. </style>