index.vue 9.0 KB

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