index.vue 11 KB

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