index.vue 9.4 KB

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