productlist.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <view class="menuBox">
  3. <view class="menuContent">
  4. <scroll-view scroll-y="true" class="menuLeft">
  5. <view class="menuType" @click="changeCurrent(index)" v-for="(item,index) in prdList"
  6. :class="{currentMenu:currentIndex==index}">
  7. <text class="text2row">{{item.name}}</text>
  8. </view>
  9. <view class="line" :style="{top:currentIndex*100 +'rpx'}"></view>
  10. </scroll-view>
  11. <scroll-view :scroll-top="scrollTop" @scroll="scrollRight" class="menuRight" scroll-y="true">
  12. <div class="menuDetailBox" v-for="(item,index) in prdList" :key="index">
  13. <div class="title">{{item.name}}</div>
  14. <div class="menu" v-for="(menu,index) in item.children" :key="index">
  15. <div class="d2">
  16. <netImage style="margin-top: 10rpx;" width="180" height="180" :mysrc="menu.image" mymode="scaleToFill"></netImage>
  17. </div>
  18. <div class="menuName">
  19. <view class="contentColumnS" style="height: 200rpx;">
  20. <view class="contentColumn" style="width: 100%;">
  21. <text class="pdName text2row">{{menu.name}}</text>
  22. <text class="pdDetail text1row">{{menu.name}}</text>
  23. </view>
  24. <view class="contentColumn" style="width: 100%;">
  25. <view class="contentInRowL">
  26. <text class="redktext">特价</text>
  27. <text class="greedKtext" style="margin-left: 10rpx;">24H发货</text>
  28. </view>
  29. <view class="contentInRowS">
  30. <view class="">
  31. <text class="pricetext">123.32</text>
  32. <text class="pricedw">{{$t("locale.huobidw")}}</text>
  33. <text class="yuanjia">155.32{{$t("locale.huobidw")}}</text>
  34. </view>
  35. <image style="width: 50rpx;height: 50rpx;margin-bottom: 6rpx;" src="/static/meishi/BuyS.png" mode=""></image>
  36. </view>
  37. </view>
  38. </view>
  39. </div>
  40. </div>
  41. </div>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import api from "@/pages/api/api.js";
  48. export default {
  49. data() {
  50. return {
  51. newData:[], // 拿到右侧所有的商品列表元素
  52. scrollTop: 0,
  53. currentIndex: 0,
  54. lang:'3',
  55. id:'',
  56. shangpinfenlei:[],
  57. prdList:[],
  58. menuList: [{
  59. "id": 1,
  60. "name": "手机数码",
  61. "children": [{
  62. "id": 101,
  63. "name": "手机"
  64. },
  65. {
  66. "id": 105,
  67. "name": "数码相机"
  68. }
  69. ]
  70. },
  71. {
  72. "id": 2,
  73. "name": "家用电器",
  74. "children": [{
  75. "id": 201,
  76. "name": "电视机"
  77. },
  78. {
  79. "id": 204,
  80. "name": "冰箱"
  81. },
  82. {
  83. "id": 205,
  84. "name": "吸尘器"
  85. }
  86. ]
  87. },
  88. {
  89. "id": 3,
  90. "name": "服饰鞋包",
  91. "children": [{
  92. "id": 301,
  93. "name": "男装"
  94. },
  95. {
  96. "id": 302,
  97. "name": "女装"
  98. },
  99. {
  100. "id": 303,
  101. "name": "运动鞋"
  102. },
  103. {
  104. "id": 304,
  105. "name": "箱包"
  106. },
  107. {
  108. "id": 305,
  109. "name": "配饰"
  110. }
  111. ]
  112. },
  113. {
  114. "id": 4,
  115. "name": "美妆个护",
  116. "children": [{
  117. "id": 401,
  118. "name": "面部护肤"
  119. },
  120. {
  121. "id": 402,
  122. "name": "彩妆"
  123. },
  124. {
  125. "id": 403,
  126. "name": "洗发护发"
  127. },
  128. {
  129. "id": 404,
  130. "name": "身体护理"
  131. },
  132. {
  133. "id": 405,
  134. "name": "香水"
  135. }
  136. ]
  137. },
  138. {
  139. "id": 5,
  140. "name": "母婴玩具",
  141. "children": [{
  142. "id": 501,
  143. "name": "奶粉"
  144. },
  145. {
  146. "id": 502,
  147. "name": "尿不湿"
  148. },
  149. {
  150. "id": 503,
  151. "name": "婴儿用品"
  152. },
  153. {
  154. "id": 504,
  155. "name": "儿童玩具"
  156. },
  157. {
  158. "id": 505,
  159. "name": "孕妇用品"
  160. }
  161. ]
  162. },
  163. {
  164. "id": 6,
  165. "name": "食品饮料",
  166. "children": [{
  167. "id": 601,
  168. "name": "休闲零食"
  169. },
  170. {
  171. "id": 602,
  172. "name": "粮油调味"
  173. },
  174. {
  175. "id": 603,
  176. "name": "饮料酒水"
  177. },
  178. {
  179. "id": 604,
  180. "name": "冲调速食"
  181. },
  182. {
  183. "id": 605,
  184. "name": "生鲜水果"
  185. }
  186. ]
  187. },
  188. {
  189. "id": 7,
  190. "name": "家居家装",
  191. "children": [{
  192. "id": 701,
  193. "name": "家具"
  194. },
  195. {
  196. "id": 702,
  197. "name": "灯具"
  198. },
  199. {
  200. "id": 703,
  201. "name": "床上用品"
  202. },
  203. {
  204. "id": 704,
  205. "name": "厨房用品"
  206. },
  207. {
  208. "id": 705,
  209. "name": "装饰摆件"
  210. }
  211. ]
  212. },
  213. {
  214. "id": 8,
  215. "name": "运动户外",
  216. "children": [{
  217. "id": 801,
  218. "name": "跑步装备"
  219. },
  220. {
  221. "id": 802,
  222. "name": "健身器材"
  223. },
  224. {
  225. "id": 803,
  226. "name": "户外鞋服"
  227. },
  228. {
  229. "id": 804,
  230. "name": "骑行装备"
  231. },
  232. {
  233. "id": 805,
  234. "name": "垂钓用品"
  235. }
  236. ]
  237. },
  238. {
  239. "id": 9,
  240. "name": "汽车用品",
  241. "children": [{
  242. "id": 901,
  243. "name": "机油"
  244. },
  245. {
  246. "id": 902,
  247. "name": "轮胎"
  248. },
  249. {
  250. "id": 903,
  251. "name": "车载电器"
  252. },
  253. {
  254. "id": 904,
  255. "name": "清洁用品"
  256. },
  257. {
  258. "id": 905,
  259. "name": "维修配件"
  260. }
  261. ]
  262. },
  263. {
  264. "id": 10,
  265. "name": "图书文娱",
  266. "children": [{
  267. "id": 1001,
  268. "name": "文学小说"
  269. },
  270. {
  271. "id": 1002,
  272. "name": "少儿读物"
  273. },
  274. {
  275. "id": 1003,
  276. "name": "教育考试"
  277. },
  278. {
  279. "id": 1004,
  280. "name": "艺术设计"
  281. },
  282. {
  283. "id": 1005,
  284. "name": "音像制品"
  285. }
  286. ]
  287. }
  288. ]
  289. }
  290. },
  291. onLoad(option) {
  292. this.id=option.id;
  293. var language = uni.getStorageSync('language');
  294. if(language=='yuenan'){
  295. this.lang='0';
  296. }
  297. if(language=='zh-Hans'){
  298. this.lang='2';
  299. }
  300. if(language=='zh-Hant'){
  301. this.lang='3';
  302. }
  303. this.getmendianshangpinFL(this.id);
  304. },
  305. onReady() {
  306. uni.setNavigationBarTitle({
  307. title: '你好'
  308. })
  309. },
  310. methods: {
  311. changeCurrent(index) {
  312. this.currentIndex = index
  313. this.scrollTop = this.newData[index-1]?.offsetHeight || 0
  314. },
  315. scrollRight(e) {
  316. // console.log(e.detail.scrollTop,'scrollRight');
  317. const query = uni.createSelectorQuery().in(this);
  318. for (let i = 0; i < this.newData.length; i++) {
  319. let el = this.newData[i]
  320. if (e.detail.scrollTop < el.offsetHeight) {
  321. this.currentIndex = i
  322. return true
  323. }
  324. }
  325. },
  326. getmendianshangpinFL(id){
  327. uni.showLoading({
  328. mask:true
  329. })
  330. api('getmendianshangpinFL',{
  331. id:id,
  332. language:this.lang
  333. },res=>{
  334. uni.hideLoading();
  335. this.shangpinfenlei=res.data.data;
  336. console.log(this.shangpinfenlei)
  337. this.initFenlei();
  338. },failc=>{
  339. uni.hideLoading();
  340. //console.log('getadvertis----',failc)
  341. })
  342. },
  343. initFenlei(){
  344. this.prdList=[];
  345. if(this.shangpinfenlei&&this.shangpinfenlei.length>0){
  346. for (var i = 0; i < this.shangpinfenlei.length; i++) {
  347. var el = this.shangpinfenlei[i];
  348. var temp = {
  349. "id": el.id,
  350. "index": i+1,
  351. "name": el.name,
  352. "children": [
  353. ]
  354. }
  355. this.prdList.push(temp);
  356. }
  357. }
  358. this.initproduct();
  359. },
  360. initproduct(){
  361. if(this.prdList.length==0){
  362. return;
  363. }
  364. this.getmendianshangpinList(0);
  365. },
  366. getmendianshangpinList(index){
  367. var obj = this.prdList[index];
  368. api('getmendianshangpinList',{
  369. id:obj.id,
  370. language:this.lang
  371. },r=>{
  372. console.log(r);
  373. this.prdList[index].children=r.data.data;
  374. if(index+1<this.prdList.length){
  375. this.getmendianshangpinList(index+1);
  376. }
  377. else{
  378. console.log(this.prdList);
  379. this.initNewData();
  380. }
  381. },failc=>{
  382. //console.log('getadvertis----',failc)
  383. })
  384. },
  385. initNewData(){
  386. const query = uni.createSelectorQuery().in(this);
  387. query.selectAll('.menuDetailBox').boundingClientRect(data => {
  388. console.log('所有分类项:', data);
  389. this.newData = data.map((item, index) => {
  390. function fgfg(total) {
  391. let sum = 0
  392. for (var i = 0; i <= total; i++) {
  393. sum += data[i].height
  394. }
  395. return sum
  396. }
  397. item.offsetHeight = fgfg(index)
  398. return item
  399. })
  400. }).exec();
  401. },
  402. },
  403. }
  404. </script>
  405. <style lang="scss" scoped>
  406. .menuBox {
  407. height: calc(100vh);
  408. display: flex;
  409. flex-direction: column;
  410. // border: 1px solid #ccc;
  411. margin: 0 10rpx;
  412. .menuContent {
  413. // height: calc(100vh);
  414. overflow: auto;
  415. position: relative;
  416. display: flex;
  417. position: sticky;
  418. top: 0rpx;
  419. .menuLeft {
  420. float: left;
  421. position: relative;
  422. width: 200rpx;
  423. background-color: #f5f5f5;
  424. .menuType {
  425. transition: all 0.4s;
  426. position: relative;
  427. z-index: 999999999;
  428. height: 100rpx;
  429. display: flex;
  430. align-items: center;
  431. padding-left: 20rpx;
  432. &.currentMenu {
  433. font-weight: 700;
  434. }
  435. }
  436. }
  437. .menuRight {
  438. flex: 1;
  439. background-color:lavender;
  440. .menuDetailBox {
  441. .title {
  442. height: 60rpx;
  443. display: flex;
  444. align-items: center;
  445. }
  446. .menu {
  447. background-color: #fff;
  448. height: 200rpx;
  449. display: flex;
  450. justify-content: center;
  451. &:not(:nth-last-of-type(1)) {
  452. margin-bottom: 20rpx;
  453. }
  454. .d2 {
  455. width: 180rpx;
  456. height: 180rpx;
  457. }
  458. .menuName {
  459. flex: 1;
  460. margin-left: 20rpx;
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. .line {
  468. position: absolute;
  469. left: 0;
  470. top: 0;
  471. height: 100rpx;
  472. width: 100%;
  473. background-color: #fff;
  474. z-index: 999;
  475. transition: all 0.4s;
  476. &::before {
  477. content: '';
  478. position: absolute;
  479. left: 0;
  480. top: 0;
  481. height: 100rpx;
  482. width: 4rpx;
  483. background-color: red;
  484. z-index: 999;
  485. transition: all 0.4s
  486. }
  487. }
  488. .pdName{
  489. font-size: 30rpx;
  490. font-weight: bold;
  491. color: black;
  492. }
  493. .pdDetail{
  494. font-size: 26rpx;
  495. color: darkgray;
  496. }
  497. .redktext{
  498. color: brown;
  499. border-radius: 4rpx;
  500. border: 1px solid brown;
  501. font-size: 26rpx;
  502. }
  503. .greedKtext{
  504. color: darkgreen;
  505. border-radius: 4rpx;
  506. border: 1px solid darkgreen;
  507. font-size: 26rpx;
  508. }
  509. .pricetext{
  510. color: firebrick;
  511. font-size: 28rpx;
  512. font-weight: bold;
  513. }
  514. .pricedw{
  515. font-size: 24rpx;
  516. color: darkgray;
  517. }
  518. .yuanjia{
  519. font-size: 24rpx;
  520. color: darkgray;
  521. text-decoration: line-through;
  522. }
  523. </style>