index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <template>
  2. <view class="content">
  3. <view class="top-content">
  4. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  5. <!-- 这里是状态栏 -->
  6. <!-- <view class="top-title">健康商城</view> -->
  7. <!-- 搜索框 -->
  8. <view class="search-cont" :style="{width:`calc(100vw - 80rpx - ${menuRight} - ${menuWidth})`}">
  9. <view class="inner">
  10. <image class="icon-search" src="../../static/images/search.png" mode=""></image>
  11. <input type="text" disabled confirm-type="搜索" @click="toSearch" placeholder="输入药品名称"
  12. placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  13. </view>
  14. </view>
  15. </view>
  16. <view :style="{height: divHeight}" class="medic-box">
  17. <view class="cate-list">
  18. <view v-for="(item,index) in cates" :key="index" :class="cateSelect == item.cateId?'item active':'item'"
  19. @click="choseCate(item)">{{item.cateName }}
  20. </view>
  21. </view>
  22. <view class="medic">
  23. <!-- 轮播图 -->
  24. <view class="banner-box">
  25. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true" :interval="3000"
  26. :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  27. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index"
  28. @click="handleAdvClick(item)">
  29. <image :src="item.imageUrl" mode=""></image>
  30. </swiper-item>
  31. </swiper>
  32. </view>
  33. <view class="inner-list">
  34. <!-- <view class="definite"v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  35. <view class="img-box">
  36. <image :src="subItem.pic" mode="aspectFit"></image>
  37. </view>
  38. <view class="name ellipsis">{{subItem.cateName}}</view>
  39. </view> -->
  40. <view class="definite" v-for="(subItem,index) in subCates"
  41. @click="showProductList(subItem, index)">
  42. <view class="name ellipsis" :class="{ 'select-name': activeIndex === index }">
  43. {{subItem.cateName}}
  44. </view>
  45. </view>
  46. </view>
  47. <view class="line"></view>
  48. <!-- 药品列表 -->
  49. <view class="medic-list">
  50. <!-- <view class="item" v-for="(item,index) in subCates" :key="index">
  51. <view class="title">{{item.cateName}}</view> -->
  52. <!-- <view class="product-list">
  53. <text class="product-title"> {{ activeIndex >= 0 ? subCates[activeIndex].cateName : '' }}</text>
  54. </view> -->
  55. <!-- 数据列表 -->
  56. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  57. <view class="medic-list2">
  58. <text class="product-title"> {{ activeIndex >= 0 && subCates.length>0?subCates[activeIndex].cateName : '' }}</text>
  59. <view v-for="(item,index) in dataList" :key="index" class="item" @click="showDetail(item)">
  60. <view class="img-box">
  61. <image :src="item.image" mode="aspectFit"></image>
  62. <view class="cf-box" v-if="item.productType==2">
  63. <view class="title">处方药</view>
  64. <view class="subTitle">请在医师指导下使用</view>
  65. </view>
  66. </view>
  67. <view class="info-box">
  68. <view class="title ellipsis2">{{item.productName}}</view>
  69. <view class="intro">
  70. <view class="intro-zk"><text>9.5折</text></view>
  71. <view class="intro-zk"><text>限购1份</text></view>
  72. </view>
  73. <view class="price-box">
  74. <view class="now">
  75. <!-- <text class="unit">¥</text> -->
  76. <text class="num">{{item.price.toFixed(2)}}</text>
  77. </view>
  78. <view class="old">¥{{item.otPrice.toFixed(2)}}</view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. <!-- </view> -->
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. getProductCate,getProductCateByPid,getProducts
  93. } from '@/api/product'
  94. import {
  95. getAdv
  96. } from '@/api/adv'
  97. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  98. export default {
  99. mixins: [MescrollMixin],
  100. data() {
  101. return {
  102. activeIndex: 0,
  103. divHeight: '0px',
  104. allCates: [],
  105. cates: [],
  106. subCates: [],
  107. // 右侧的胶囊距离右侧屏幕距离-px
  108. menuRight: uni.getStorageSync('menuInfo').menuRight,
  109. // 右侧的胶囊宽度-px
  110. menuWidth: uni.getStorageSync('menuInfo').menuWidth,
  111. // 状态栏的高度
  112. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  113. // 选中药品分类
  114. cateSelect: 0,
  115. // 轮播图
  116. advs: [],
  117. dataList:[],
  118. cateId:null,
  119. pid:null,
  120. defaultOrder:'desc',
  121. storeId: "",
  122. //上拉加载的配置
  123. upOption: {
  124. onScroll:true,
  125. use: true, // 是否启用上拉加载; 默认true
  126. page: {
  127. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  128. size: 10 // 每页数据的数量,默认10
  129. },
  130. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  131. empty: {
  132. icon:'https://user.test.ylrztop.com/images/empty_icon.png',
  133. tip: '暂无数据',
  134. },
  135. textNoMore:"已经到底了",
  136. }
  137. };
  138. },
  139. onLoad() {
  140. uni.showShareMenu({
  141. withShareTicket: true,
  142. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  143. menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
  144. })
  145. },
  146. onShow() {
  147. this.getProductCate();
  148. var that = this;
  149. setTimeout(function() {
  150. let info = uni.createSelectorQuery().select(".top-content");
  151. info.boundingClientRect(function(data) { //data - 各种参数
  152. console.log(data.height) // 获取元素宽度
  153. // console.log(uni.upx2px(10))
  154. that.divHeight = "calc(100% - " + data.height + "px)"
  155. }).exec()
  156. }, 500);
  157. this.getAdv();
  158. },
  159. methods: {
  160. // divHeight(){
  161. // return 'height:calc(100% - ${this.top}px);'
  162. // },
  163. toSearch() {
  164. uni.navigateTo({
  165. url: '../home/productSearch'
  166. })
  167. },
  168. handleAdvClick(item) {
  169. console.log(item);
  170. if (item.showType == 1) {
  171. uni.setStorageSync('url', item.advUrl);
  172. uni.navigateTo({
  173. url: "../home/web"
  174. })
  175. } else if (item.showType == 2) {
  176. uni.navigateTo({
  177. url: item.advUrl
  178. })
  179. } else if (item.showType == 3) {
  180. uni.setStorageSync('content', item.content);
  181. uni.navigateTo({
  182. url: "../home/content"
  183. })
  184. }
  185. },
  186. getAdv() {
  187. let data = {
  188. advType: 2
  189. };
  190. getAdv(data).then(
  191. res => {
  192. if (res.code == 200) {
  193. this.advs = res.data;
  194. }
  195. },
  196. rej => {}
  197. );
  198. },
  199. getProductCate() {
  200. let data = {};
  201. getProductCate(data).then(
  202. res => {
  203. if (res.code == 200) {
  204. this.allCates = res.data;
  205. this.cates = this.allCates.filter(function(item) {
  206. return item.pid == 0
  207. });
  208. if (this.cates != null && this.cates.length > 0) {
  209. this.cateSelect = this.cates[0].cateId ;
  210. this.getSubCate();
  211. // this.mescroll.resetUpScroll()
  212. }
  213. } else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: "请求失败",
  217. });
  218. }
  219. },
  220. rej => {}
  221. );
  222. },
  223. // 药品分类选择
  224. choseCate(item) {
  225. this.activeIndex = 0
  226. this.dataList=[]
  227. this.cateSelect = item.cateId;
  228. this.getSubCate()
  229. },
  230. getSubCate() {
  231. var that = this;
  232. this.subCates = this.allCates.filter(item=>item.pid == this.cateSelect);
  233. // let subList = that.allCates.filter(child => {
  234. // //返回每一项的子级数组
  235. // return child.pid === item.cateId
  236. // });
  237. // subList.length > 0 ? item.children = subList : [];
  238. if (this.subCates != null && this.subCates.length > 0) {
  239. this.cateId= this.subCates[0].cateId;
  240. this.mescroll.resetUpScroll()
  241. }else{
  242. this.cateId=0
  243. this.mescroll.resetUpScroll()
  244. }
  245. },
  246. // 查看药品详情
  247. showProductList(item, index) {
  248. // console.log("item>>>>>", item)
  249. this.activeIndex = index;
  250. this.cateId = item.cateId;
  251. this.mescroll.resetUpScroll()
  252. // uni.navigateTo({
  253. // url: './productList?cateId='+item.cateId+"&pid="+item.pid
  254. // })
  255. },
  256. mescrollInit(mescroll) {
  257. this.mescroll = mescroll;
  258. },
  259. /*下拉刷新的回调 */
  260. downCallback(mescroll) {
  261. this.mescroll.resetUpScroll()
  262. },
  263. upCallback(page) {
  264. //联网加载数据
  265. var that = this;
  266. var data = {
  267. cateId:this.cateId,
  268. defaultOrder:this.defaultOrder,
  269. page: page.num,
  270. pageSize: page.size,
  271. productName: this.productName || "",
  272. storeId: this.storeId
  273. };
  274. if(this.cateId!=null){
  275. this.getProducts(page,data)
  276. }
  277. },
  278. //查询商品列表
  279. getProducts(page,data) {
  280. var that = this;
  281. getProducts(data).then(res => {
  282. if(res.code==200){
  283. //设置列表数据
  284. if (page.num == 1) {
  285. that.dataList = res.data.list;
  286. } else {
  287. that.dataList = that.dataList.concat(res.data.list);
  288. }
  289. that.mescroll.endBySize(res.data.list.length, res.data.total);
  290. }else{
  291. uni.showToast({
  292. icon:'none',
  293. title: "请求失败",
  294. });
  295. that.dataList = null;
  296. that.mescroll.endErr();
  297. }
  298. });
  299. },
  300. // 查看药品详情
  301. showDetail(item) {
  302. if(this.from == 'company') {
  303. uni.navigateTo({
  304. url: '/pages_company/order/productDetails?productId='+item.productId +`${this.storeId ? '&storeId='+this.storeId : ''}`
  305. })
  306. } else {
  307. uni.navigateTo({
  308. url: './productDetails?productId='+item.productId +`${this.storeId ? '&storeId='+this.storeId : ''}`
  309. })
  310. }
  311. },
  312. goSearch(e) {
  313. if (e.detail.value != null && e.detail.value != "") {
  314. this.utils.addHisSearch(e.detail.value);
  315. }
  316. uni.navigateTo({
  317. url: '../home/productList?searchValue=' + e.detail.value
  318. })
  319. }
  320. }
  321. }
  322. </script>
  323. <style lang="scss">
  324. page {
  325. height: 100%;
  326. background-color: #fff;
  327. }
  328. .mescroll-body{
  329. min-height: calc(100% - 330upx) !important;
  330. }
  331. .content {
  332. height: 100%;
  333. display: flex;
  334. flex-direction: column;
  335. .top-content {
  336. width: 100%;
  337. z-index: 10;
  338. .top-title {
  339. height: 88upx;
  340. line-height: 88upx;
  341. font-size: 42upx;
  342. font-family: Source Han Sans CN;
  343. font-weight: bold;
  344. color: #222222;
  345. padding-left: 41upx;
  346. background-color: #FFFFFF;
  347. }
  348. .search-cont {
  349. padding: 16upx 30upx;
  350. background-color: #FFFFFF;
  351. .inner {
  352. box-sizing: border-box;
  353. width: 100%;
  354. height: 72upx;
  355. background: #F7F7F7;
  356. border-radius: 36upx;
  357. display: flex;
  358. align-items: center;
  359. padding: 0 30upx;
  360. .icon-search {
  361. width: 28upx;
  362. height: 28upx;
  363. margin-right: 20upx;
  364. }
  365. input {
  366. height: 60upx;
  367. line-height: 60upx;
  368. flex: 1;
  369. }
  370. }
  371. }
  372. }
  373. .medic-box {
  374. display: flex;
  375. .cate-list {
  376. box-sizing: border-box;
  377. width: 200upx;
  378. background: #F2F5F9;
  379. display: flex;
  380. flex-direction: column;
  381. // padding: 20upx 0;
  382. overflow-y: scroll;
  383. margin-top: 30rpx;
  384. .item {
  385. height: 100upx;
  386. line-height: 100upx;
  387. padding-left: 30upx;
  388. font-size: 28upx;
  389. font-family: PingFang SC;
  390. font-weight: 500;
  391. color: #333333;
  392. position: relative;
  393. // overflow: hidden;
  394. &.active {
  395. background: #FFFFFF;
  396. font-weight: 600;
  397. // box-shadow: 12px 0 12px 0 #ffffff, -12px 0 12px 0 #ffffff;
  398. // border-radius: 12px 12px 0 0;
  399. &::after {
  400. content: "";
  401. width: 6upx;
  402. height: 28upx;
  403. background: #008FD3;
  404. position: absolute;
  405. top: 50%;
  406. left: 0;
  407. transform: translateY(-50%);
  408. border-radius: 0upx 6upx 6upx 0;
  409. }
  410. }
  411. }
  412. }
  413. .medic {
  414. box-sizing: border-box;
  415. width: calc(100% - 200upx);
  416. height: 100%;
  417. padding: 0 30upx;
  418. .banner-box {
  419. margin-top: 30rpx;
  420. width: 100%;
  421. height: 160upx;
  422. border-radius: 10upx;
  423. overflow: hidden;
  424. .swiper,
  425. .swiper-item,
  426. .swiper-item image {
  427. width: 100%;
  428. height: 100%;
  429. }
  430. }
  431. .inner-list {
  432. display: flex;
  433. flex-wrap: wrap;
  434. padding-top: 30upx;
  435. .definite {
  436. width: calc(33% - 20upx);
  437. margin-right: 30upx;
  438. margin-bottom: 30upx;
  439. .img-box {
  440. width: 100%;
  441. height: 144upx;
  442. background: #F5F5F5;
  443. border-radius: 8upx;
  444. overflow: hidden;
  445. display: flex;
  446. align-items: center;
  447. image {
  448. max-width: 100%;
  449. }
  450. }
  451. .name {
  452. width: 100%;
  453. margin-top: 20upx;
  454. font-size: 24upx;
  455. font-family: PingFang SC;
  456. font-weight: 500;
  457. color: #666666;
  458. text-align: center;
  459. padding: 10rpx 16rpx;
  460. }
  461. .select-name {
  462. background: #EFF3F7;
  463. color: #222426;
  464. border-radius:10upx ;
  465. }
  466. &:nth-child(3n) {
  467. margin-right: 0;
  468. }
  469. }
  470. }
  471. .line {
  472. width: 100%;
  473. height: 0rpx;
  474. border-top: 1rpx solid #ECECEC;
  475. }
  476. .medic-list {
  477. box-sizing: border-box;
  478. padding: 30upx 0;
  479. overflow-y: auto;
  480. height: calc(100% - 330upx);
  481. position: relative;
  482. // .item{
  483. // .title{
  484. // font-size: 28upx;
  485. // font-family: PingFang SC;
  486. // font-weight: bold;
  487. // color: #333333;
  488. // padding-top: 20upx;
  489. // margin-bottom: 30upx;
  490. // }
  491. // }
  492. .product-list {
  493. padding: 32rpx 0 0;
  494. .product-title {
  495. font-weight: 500;
  496. font-size: 28rpx;
  497. color: #222426;
  498. }
  499. }
  500. .medic-list2{
  501. // padding: 20upx;
  502. .product-title{
  503. font-size: 28upx;
  504. display: block;
  505. // padding-top: 30upx;
  506. }
  507. .item{
  508. box-sizing: border-box;
  509. min-height: 200upx;
  510. background: #FFFFFF;
  511. // border: 4upx solid #FFFFFF;
  512. border-radius: 20upx;
  513. // margin-bottom: 20upx;
  514. // padding: 40upx 0upx;
  515. padding-top: 30upx;
  516. display: flex;
  517. .img-box{
  518. width: 200upx;
  519. height: 200upx;
  520. margin-right: 30upx;
  521. position: relative;
  522. border-radius: 20upx;
  523. overflow: hidden;
  524. image{
  525. width: 100%;
  526. height: 100%;
  527. }
  528. }
  529. .info-box{
  530. width: calc(100% - 210upx);
  531. display: grid;
  532. justify-items: left;
  533. .title{
  534. font-size: 28upx;
  535. font-family: PingFang SC;
  536. font-weight: 500;
  537. color: #111111;
  538. line-height: 40upx;
  539. height: 80upx;
  540. }
  541. .intro{
  542. // font-size: 26upx;
  543. // font-family: PingFang SC;
  544. // font-weight: 500;
  545. // color: #999999;
  546. // line-height: 1;
  547. // margin-top: 26upx;
  548. display: flex;
  549. .intro-zk{
  550. border: 1px solid #FF4B33;
  551. padding:0 8rpx ;
  552. border-radius: 8rpx;
  553. margin-right: 10rpx;
  554. line-height: 5rpx;
  555. display: flex;
  556. text{
  557. font-size:24rpx;
  558. color:#FF4B33 ;
  559. display: flex;
  560. align-items: center;
  561. }
  562. }
  563. }
  564. .price-box{
  565. display: flex;
  566. align-items: flex-end;
  567. .now{
  568. display: flex;
  569. align-items: flex-end;
  570. margin-right: 20upx;
  571. .num{
  572. font-size: 36upx;
  573. font-family: PingFang SC;
  574. font-weight: bold;
  575. color: #FF5030;
  576. line-height: 1;
  577. }
  578. }
  579. .old{
  580. font-size: 24upx;
  581. font-family: PingFang SC;
  582. // font-weight: 500;
  583. text-decoration: line-through;
  584. color: #BBBBBB;
  585. line-height: 1.1;
  586. }
  587. }
  588. .prce-num{
  589. display: flex;
  590. align-items: center;
  591. justify-content: space-between;
  592. margin-top: 30upx;
  593. .price{
  594. display: flex;
  595. align-items: flex-end;
  596. .unit{
  597. font-size: 24upx;
  598. font-family: PingFang SC;
  599. font-weight: 500;
  600. color: #FF6633;
  601. line-height: 1.2;
  602. margin-right: 4upx;
  603. }
  604. .num{
  605. font-size: 36upx;
  606. font-family: PingFang SC;
  607. font-weight: bold;
  608. color: #FF6633;
  609. line-height: 1;
  610. }
  611. }
  612. .cart-img{
  613. .sale{
  614. font-size: 20upx;
  615. font-family: PingFang SC;
  616. color: #999999;
  617. }
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. }
  625. }
  626. }
  627. </style>