index.vue 18 KB

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