index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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: 6,
  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. 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. toCommon(e) {
  219. const that = this;
  220. uni.navigateTo({
  221. url: `/${e}`
  222. })
  223. },
  224. // 购买
  225. toBuy(e) {
  226. const that = this;
  227. uni.navigateTo({
  228. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  229. })
  230. },
  231. // 菜单跳转
  232. toPath(e) {
  233. const that = this;
  234. that.clearPage();
  235. if (e && e.route && e.type == '0') {
  236. uni.redirectTo({
  237. url: `/${e.route}`
  238. })
  239. } else {
  240. uni.navigateTo({
  241. url: `/${e.route}`
  242. })
  243. }
  244. }
  245. },
  246. onPullDownRefresh: async function() {
  247. const that = this;
  248. that.$set(that, `list`, [])
  249. that.$set(that, `marketList`, [])
  250. that.$set(that, `typeList`, [])
  251. that.$set(that, `active`, '0')
  252. that.$set(that, `skip`, 0)
  253. that.$set(that, `limit`, 6)
  254. that.$set(that, `page`, 0)
  255. await that.search();
  256. uni.stopPullDownRefresh();
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. .main {
  262. display: flex;
  263. flex-direction: column;
  264. width: 100vw;
  265. height: 91vh;
  266. .one {
  267. padding: 2vw;
  268. border: 1px solid var(--f1Color);
  269. input {
  270. background-color: var(--fFB1Color);
  271. border-radius: 30px;
  272. padding: 2vw;
  273. color: var(--fffColor);
  274. font-size: var(--font15Size);
  275. }
  276. .placss {
  277. color: var(--fffColor);
  278. }
  279. }
  280. .two {
  281. height: 83vh;
  282. display: flex;
  283. flex-direction: row;
  284. .two_1 {
  285. position: relative;
  286. width: 25vw;
  287. background-color: #fafafa;
  288. display: flex;
  289. flex-direction: column;
  290. .list {
  291. text-align: center;
  292. padding: 2.5vw 0;
  293. border-bottom: 1px solid var(--f1Color);
  294. text {
  295. font-size: var(--font14Size);
  296. }
  297. }
  298. .listActive {
  299. background-color: var(--fffColor);
  300. }
  301. }
  302. .two_2 {
  303. flex-grow: 1;
  304. position: relative;
  305. display: flex;
  306. flex-direction: column;
  307. .two_2_1 {
  308. padding: 0 2vw;
  309. margin: 0 0 2vw 0;
  310. .typeScrollview {
  311. display: flex;
  312. white-space: nowrap;
  313. .list {
  314. display: inline-block;
  315. width: 14vw;
  316. padding: 1vw;
  317. text-align: center;
  318. border-radius: 5px;
  319. margin: 0 2vw 0 0;
  320. .image {
  321. width: 100%;
  322. height: 7vh;
  323. border-radius: 5px;
  324. border: 1px solid var(--f1Color);
  325. ;
  326. }
  327. .label {
  328. font-size: var(--font12Size);
  329. }
  330. }
  331. }
  332. }
  333. .two_2_2 {
  334. padding: 0 2vw;
  335. width: 70vw;
  336. .list {
  337. display: flex;
  338. width: 66vw;
  339. margin: 0 0 2vw 0;
  340. padding: 2vw;
  341. box-shadow: 0 0 5px var(--f1Color);
  342. ;
  343. border-radius: 5px;
  344. .img {
  345. width: 19vw;
  346. .image {
  347. width: 19vw;
  348. height: 12vh;
  349. border-radius: 5px;
  350. }
  351. }
  352. .info {
  353. width: 45vw;
  354. padding: 0 0 0 2vw;
  355. .name {
  356. font-size: var(--font15Size);
  357. margin: 0 0 1vw 0;
  358. }
  359. .num {
  360. font-size: var(--font14Size);
  361. color: #858585;
  362. margin: 0 0 1vw 0;
  363. }
  364. .money {
  365. font-size: var(--font14Size);
  366. color: #ff0000;
  367. margin: 0 0 1vw 0;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. .scroll-view {
  376. position: absolute;
  377. top: 0;
  378. left: 0;
  379. right: 0;
  380. bottom: 0;
  381. .list-scroll-view {
  382. display: flex;
  383. flex-direction: column;
  384. }
  385. }
  386. .is_bottom {
  387. text-align: center;
  388. text {
  389. padding: 2vw 0;
  390. display: inline-block;
  391. color: #858585;
  392. font-size: 14px;
  393. }
  394. }
  395. </style>