index.vue 8.5 KB

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