index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <view class="content">
  3. <view class="top-content">
  4. <image class="bg" src="/static/images/classification-bg.png"></image>
  5. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  6. <!-- 这里是状态栏 -->
  7. <!-- <view class="top-title">健康商城</view> -->
  8. <!-- 搜索框 -->
  9. <view class="search-cont">
  10. <image class="back" src="../../static/images/back_black.png" mode=""></image>
  11. <view class="inner">
  12. <image class="icon-search" src="../../static/images/search.png" mode=""></image>
  13. <input type="text" disabled confirm-type="搜索" @click="toSearch" placeholder="搜索您喜欢的商品"
  14. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  15. </view>
  16. </view>
  17. <!-- 栏目 -->
  18. <view class="column-box" :class="isExpand?'column-box2':''">
  19. <!-- <view class="column-list" :class="isExpand?'column-list2':''">
  20. <view class="item" v-for="(item,index) in columnList" :key="index" @click="selectColumn(item)">
  21. <view class="img-item" :class="index===activeIndex?'active':''">
  22. <image class="img" src="../../static/images/img.png" mode=""></image>
  23. </view>
  24. <view class="name" :class="index===activeIndex?'active':''">{{item.name}}</view>
  25. </view>
  26. </view> -->
  27. <scroll-view
  28. class="column-list-scroll"
  29. :class="isExpand?'column-list2':''"
  30. scroll-x="true"
  31. :scroll-with-animation="true"
  32. :show-scrollbar="false"
  33. :enable-flex="true"
  34. >
  35. <view class="column-list" :class="isExpand?'column-list2':''">
  36. <view class="item" v-for="(item,index) in columnList" :key="index" @click="selectColumn(item)">
  37. <view class="img-item" :class="index===activeIndex?'active':''">
  38. <image class="img" src="../../static/images/img.png" mode=""></image>
  39. </view>
  40. <view class="name" :class="index===activeIndex?'active':''">{{item.name}}</view>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. <view class="expand" @click="expand" :class="{'expand2': isExpand}">
  45. <view>{{isExpand ? '收起' : '展开'}}</view>
  46. <image class="expand-icon"
  47. :src="isExpand ? '../../static/images/retract.png' : '../../static/images/expand.png'" mode="">
  48. </image>
  49. </view>
  50. </view>
  51. </view>
  52. <view :style="{height: divHeight}" class="medic-box">
  53. <view class="cate-list">
  54. <view v-for="(item,index) in cates" :key="index" :class="cateSelect == item.cateId?'item active':'item'"
  55. @click="choseCate(item)">
  56. <image class="line" v-if="cateSelect == item.cateId" src="/static/images/select_hover_line.png"
  57. mode=""></image>
  58. {{item.cateName }}
  59. </view>
  60. </view>
  61. <view class="medic">
  62. <view class="medic-list">
  63. <view v-for="(item,index) in dataList" :key="index" class="item" @click="showDetail(item)">
  64. <view class="img-box">
  65. <image :src="item.image" mode="aspectFit"></image>
  66. </view>
  67. <view class="info-box">
  68. <view class="title ellipsis2">{{item.productName}}</view>
  69. <view class="intro ellipsis">{{item.productInfo}}</view>
  70. <view class="sale">已售 {{item.sales}} {{item.unitName}} | 惊艳度98%</view>
  71. <view class="lable-group">
  72. <view class="lable-item">9.5折</view>
  73. <view class="lable-item">限购1份</view>
  74. </view>
  75. <view class="prce-num">
  76. <view class="price">
  77. <text class="unit">¥</text><text
  78. class="bold">{{splitPrice(item.price).integer}}</text>.{{splitPrice(item.price).decimal}}
  79. </view>
  80. <view class="cart-img" @click="navgetTo('../shopping/cart')">
  81. <image class="w40 h40" src="/static/images/add_car.png"></image>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 轮播图 -->
  88. <!-- <view class="banner-box">
  89. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000"
  90. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  91. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index"
  92. @click="handleAdvClick(item)">
  93. <image :src="item.imageUrl" mode=""></image>
  94. </swiper-item>
  95. </swiper>
  96. </view> -->
  97. <!-- 药品列表 -->
  98. <!-- <view class="medic-list">
  99. <view class="inner-list">
  100. <view class="definite" v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  101. <view class="img-box">
  102. <image :src="subItem.pic" mode="aspectFit"></image>
  103. </view>
  104. <view class="name ellipsis">{{subItem.cateName}}</view>
  105. </view>
  106. </view>
  107. </view> -->
  108. </view>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. import {
  114. getProductCate
  115. } from '@/api/product'
  116. import {
  117. getAdv
  118. } from '@/api/adv'
  119. export default {
  120. data() {
  121. return {
  122. isExpand: false, //是否展开
  123. activeIndex: 0,
  124. columnList: [{
  125. name: "中秋佳礼",
  126. img: "/static/images/img.png",
  127. value: 0
  128. }, {
  129. name: "中秋佳礼",
  130. img: "/static/images/img.png",
  131. value: 1
  132. }, {
  133. name: "中秋佳礼",
  134. img: "/static/images/img.png",
  135. value: 2
  136. }, {
  137. name: "中秋佳礼",
  138. img: "/static/images/img.png",
  139. value: 3
  140. }, {
  141. name: "中秋佳礼",
  142. img: "/static/images/img.png",
  143. value: 4
  144. }, {
  145. name: "中秋佳礼",
  146. img: "/static/images/img.png",
  147. value: 5
  148. }, {
  149. name: "中秋佳礼",
  150. img: "/static/images/img.png",
  151. value: 6
  152. }, {
  153. name: "中秋佳礼",
  154. img: "/static/images/img.png",
  155. value: 7
  156. }],
  157. dataList: [{
  158. cateId: 364,
  159. image: "https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20251216/6a3c96bd3fc44b15b760871670302e9a.jpg",
  160. otPrice: 268,
  161. price: 98,
  162. productId: 66050,
  163. productInfo: "电肌肉刺激(EMS),又称神经肌肉电刺激,是利用电脉冲诱发多发性肌肉收缩;中枢神经系统使肌肉收缩;EMS被证明是一种积极的肌肉强化工具。↵EMS的用途:肌肉强化,预防废肌萎缩,肌肉松弛,缓解酸痛,放松肌肉,美容肌肉调理。",
  164. productName: "佟络宝®健步器",
  165. sales: 1026,
  166. unitName: "个",
  167. warehouseCode: "JST001",
  168. warehouseId: 3,
  169. }, {
  170. cateId: 364,
  171. image: "https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20251204/c53bb29cf794468ba59ee2d60983b92f.jpg",
  172. otPrice: 298,
  173. price: 138,
  174. productId: 65920,
  175. productInfo: "1、取本品1包放入脚盆,倒入适量沸水浸泡搅拌,约5-10分钟,再加入适量温水或冷水调至适宜水温即可足浴,泡脚15- 25分钟。↵2、取本品1包放入锅内煮约5分钟,将煮好的水倒入脚盆,再加入适量温水或冷水调至适宜温度即可足浴,泡脚15-25分钟。",
  176. productName: "[九仙汤]除痹通络汤 30克x30包",
  177. sales: 6042,
  178. unitName: "盒",
  179. warehouseCode: "JST001",
  180. warehouseId: 3,
  181. }],
  182. divHeight: '0px',
  183. allCates: [],
  184. cates: [],
  185. subCates: [],
  186. // 状态栏的高度
  187. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  188. // 选中药品分类
  189. cateSelect: 0,
  190. // 轮播图
  191. advs: [],
  192. };
  193. },
  194. onLoad() {
  195. uni.showShareMenu({
  196. withShareTicket: true,
  197. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  198. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  199. })
  200. this.getProductCate();
  201. },
  202. onShow() {
  203. var that = this;
  204. setTimeout(function() {
  205. let info = uni.createSelectorQuery().select(".top-content");
  206. info.boundingClientRect(function(data) { //data - 各种参数
  207. console.log(data.height) // 获取元素宽度
  208. // console.log(uni.rpx2px(10))
  209. that.divHeight = "calc(100% - " + data.height + "px)"
  210. }).exec()
  211. }, 500);
  212. this.getAdv();
  213. },
  214. methods: {
  215. splitPrice(price) {
  216. const priceStr = parseFloat(price).toFixed(2).toString();
  217. return {
  218. integer: priceStr.split('.')[0],
  219. decimal: priceStr.split('.')[1]
  220. };
  221. },
  222. // 展开
  223. expand() {
  224. this.isExpand = !this.isExpand;
  225. },
  226. // 选择栏目
  227. selectColumn(item) {
  228. console.log("打印item", item.value);
  229. this.activeIndex = item.value;
  230. },
  231. // divHeight() {
  232. // return 'height:calc(100% - ${this.top}px);'
  233. // },
  234. toSearch() {
  235. uni.navigateTo({
  236. url: '../home/productSearch'
  237. })
  238. },
  239. handleAdvClick(item) {
  240. console.log(item);
  241. if (item.showType == 1) {
  242. uni.setStorageSync('url', item.advUrl);
  243. uni.navigateTo({
  244. url: "../home/h5"
  245. })
  246. } else if (item.showType == 2) {
  247. uni.navigateTo({
  248. url: item.advUrl
  249. })
  250. } else if (item.showType == 3) {
  251. uni.setStorageSync('content', item.content);
  252. uni.navigateTo({
  253. url: "../home/content"
  254. })
  255. }
  256. },
  257. getAdv() {
  258. let data = {
  259. advType: 2
  260. };
  261. getAdv(data).then(
  262. res => {
  263. if (res.code == 200) {
  264. this.advs = res.data;
  265. }
  266. },
  267. rej => {}
  268. );
  269. },
  270. getProductCate() {
  271. let data = {};
  272. getProductCate(data).then(
  273. res => {
  274. if (res.code == 200) {
  275. this.allCates = res.data;
  276. this.cates = this.allCates.filter(function(item) {
  277. return item.pid == 0
  278. });
  279. if (this.cates != null && this.cates.length > 0) {
  280. this.cateSelect = this.cates[0].cateId;
  281. this.getSubCate()
  282. }
  283. } else {
  284. uni.showToast({
  285. icon: 'none',
  286. title: "请求失败",
  287. });
  288. }
  289. },
  290. rej => {}
  291. );
  292. },
  293. // 药品分类选择
  294. choseCate(item) {
  295. this.cateSelect = item.cateId;
  296. this.getSubCate()
  297. },
  298. getSubCate() {
  299. var that = this;
  300. this.subCates = this.allCates.filter(function(item) {
  301. // let subList = that.allCates.filter(child => {
  302. // //返回每一项的子级数组
  303. // return child.pid === item.cateId
  304. // });
  305. // subList.length > 0 ? item.children = subList : [];
  306. return item.pid == that.cateSelect
  307. });
  308. console.log(this.subCates);
  309. },
  310. // 查看药品详情
  311. showProductList(item) {
  312. uni.navigateTo({
  313. url: '/pages_shopping/shopping/productList?cateId=' + item.cateId + "&pid=" + item.pid
  314. })
  315. },
  316. goSearch(e) {
  317. if (e.detail.value != null && e.detail.value != "") {
  318. this.utils.addHisSearch(e.detail.value);
  319. }
  320. uni.navigateTo({
  321. url: '../home/productList?searchValue=' + e.detail.value
  322. })
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss">
  328. page {
  329. height: 100%;
  330. background-color: #fff;
  331. }
  332. .content {
  333. height: 100%;
  334. display: flex;
  335. flex-direction: column;
  336. .top-content {
  337. background: linear-gradient(180deg, #E1FAEF 0%, #FFFFFF 100%);
  338. box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(187, 187, 187, 0.15);
  339. width: 100%;
  340. z-index: 10;
  341. position: relative;
  342. .bg {
  343. position: absolute;
  344. top: 0;
  345. z-index: -1;
  346. width: 100%;
  347. height: 372rpx;
  348. }
  349. .top-title {
  350. height: 88rpx;
  351. line-height: 88rpx;
  352. font-size: 42rpx;
  353. font-family: Source Han Sans CN;
  354. font-weight: bold;
  355. color: #222222;
  356. padding-left: 41rpx;
  357. background-color: #FFFFFF;
  358. }
  359. .search-cont {
  360. display: flex;
  361. padding: 6rpx 30rpx;
  362. .back {
  363. width: 64rpx;
  364. height: 64rpx;
  365. }
  366. .inner {
  367. box-sizing: border-box;
  368. width: 436rpx;
  369. height: 64rpx;
  370. background: #ffffff;
  371. border-radius: 32rpx;
  372. display: flex;
  373. align-items: center;
  374. padding: 0 24rpx;
  375. .icon-search {
  376. width: 28rpx;
  377. height: 28rpx;
  378. margin-right: 20rpx;
  379. }
  380. input {
  381. height: 60rpx;
  382. line-height: 60rpx;
  383. flex: 1;
  384. }
  385. }
  386. }
  387. .column-box {
  388. display: flex;
  389. padding-left: 16rpx;
  390. margin: 16rpx 0 24rpx;
  391. &.column-box2 {
  392. display: flex;
  393. flex-direction: column;
  394. }
  395. .column-list-scroll {
  396. flex: 1;
  397. overflow: hidden;
  398. white-space: nowrap;
  399. &.column-list2 {
  400. flex-wrap: wrap;
  401. height: auto;
  402. }
  403. .column-list {
  404. display: inline-flex; // 改为行内flex
  405. align-items: center;
  406. padding-bottom: 10rpx; // 增加底部padding,防止滚动条遮挡
  407. &.column-list2 {
  408. display: flex;
  409. flex-wrap: wrap;
  410. width: 100%;
  411. }
  412. .item {
  413. display: inline-flex; // 改为行内flex
  414. flex-direction: column;
  415. align-items: center;
  416. margin-right: 16rpx;
  417. margin-bottom: 20rpx;
  418. flex-shrink: 0; // 防止收缩
  419. .img-item {
  420. width: 88rpx;
  421. height: 88rpx;
  422. flex-shrink: 0;
  423. &.active {
  424. border: 3rpx solid #02B176;
  425. box-sizing: border-box;
  426. border-radius: 44rpx;
  427. }
  428. .img {
  429. width: 100%;
  430. height: 100%;
  431. border-radius: 44rpx;
  432. }
  433. }
  434. .name {
  435. width: 128rpx;
  436. height: 44rpx;
  437. font-size: 24rpx;
  438. color: #333333;
  439. text-align: center;
  440. line-height: 44rpx;
  441. margin-top: 16rpx;
  442. white-space: nowrap;
  443. overflow: hidden;
  444. text-overflow: ellipsis;
  445. &.active {
  446. font-weight: 500;
  447. color: #FFFFFF;
  448. background: #02B176;
  449. border-radius: 22rpx;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. .expand {
  456. margin: 0 20rpx;
  457. font-size: 24rpx;
  458. color: #000000;
  459. width: 24rpx;
  460. display: flex;
  461. flex-direction: column;
  462. align-items: center;
  463. flex-shrink: 0; // 防止收缩
  464. .expand-icon {
  465. width: 24rpx;
  466. height: 24rpx;
  467. margin-top: 6rpx;
  468. }
  469. }
  470. .expand2 {
  471. margin-top: 8rpx;
  472. width: 100%;
  473. justify-content: center;
  474. flex-direction: row;
  475. align-items: center;
  476. .expand-icon {
  477. margin-left: 12rpx;
  478. }
  479. }
  480. }
  481. }
  482. .medic-box {
  483. display: flex;
  484. .cate-list {
  485. box-sizing: border-box;
  486. width: 200rpx;
  487. background: #F5F7FA;
  488. display: flex;
  489. flex-direction: column;
  490. padding: 20rpx 0;
  491. overflow-y: scroll;
  492. position: relative;
  493. .line {
  494. position: absolute;
  495. left: 0;
  496. top: 50%;
  497. transform: translateY(-50%);
  498. width: 6rpx;
  499. height: 28rpx;
  500. }
  501. .item {
  502. height: 112rpx;
  503. line-height: 112rpx;
  504. padding-left: 28rpx;
  505. font-size: 28rpx;
  506. font-family: PingFang SC;
  507. color: #666666;
  508. position: relative;
  509. &.active {
  510. color: #02B176;
  511. background: #FFFFFF;
  512. font-weight: 500;
  513. }
  514. }
  515. }
  516. .medic {
  517. box-sizing: border-box;
  518. width: calc(100% - 200rpx);
  519. height: 100%;
  520. .medic-list {
  521. .item {
  522. box-sizing: border-box;
  523. min-height: 296upx;
  524. background: #FFFFFF;
  525. border: 4upx solid #FFFFFF;
  526. border-radius: 16upx;
  527. margin-bottom: 18upx;
  528. padding: 24rpx;
  529. display: flex;
  530. .img-box {
  531. flex-shrink: 0;
  532. width: 188rpx;
  533. height: 188rpx;
  534. margin-right: 20upx;
  535. border-radius: 16upx;
  536. overflow: hidden;
  537. image {
  538. width: 100%;
  539. height: 100%;
  540. }
  541. }
  542. .info-box {
  543. flex: 1;
  544. min-width: 0;
  545. .title {
  546. font-size: 28upx;
  547. font-family: PingFang SC;
  548. font-weight: 500;
  549. color: #333333;
  550. margin-bottom: 4rpx;
  551. }
  552. .intro {
  553. font-weight: 400;
  554. font-size: 22rpx;
  555. color: #D46C0D;
  556. margin-bottom: 8upx;
  557. }
  558. .sale {
  559. font-size: 21rpx;
  560. color: #999999;
  561. }
  562. .lable-group {
  563. display: flex;
  564. margin-top: 8rpx;
  565. .lable-item {
  566. margin-right: 8rpx;
  567. height: 30rpx;
  568. padding: 0 8rpx;
  569. border-radius: 4rpx 4rpx 4rpx 4rpx;
  570. border: 1rpx solid #FFA599;
  571. font-size: 21rpx;
  572. color: #FF4B33;
  573. }
  574. }
  575. .prce-num {
  576. display: flex;
  577. align-items: center;
  578. justify-content: space-between;
  579. margin-top: 8upx;
  580. .price {
  581. font-weight: 600;
  582. font-size: 26rpx;
  583. color: #FA341E;
  584. font-size: 26rpx;
  585. .unit {
  586. font-size: 20upx;
  587. }
  588. .bold {
  589. font-size: 36upx;
  590. }
  591. }
  592. }
  593. }
  594. }
  595. }
  596. }
  597. }
  598. }
  599. </style>