index.vue 9.0 KB

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