index.vue 8.6 KB

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