index.vue 8.5 KB

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