index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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">
  9. <view class="inner">
  10. <image class="icon-search" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/icon_search.png" mode=""></image>
  11. <input type="text" disabled confirm-type="搜索" @click="toSearch" placeholder="输入药品名称" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  12. </view>
  13. </view>
  14. </view>
  15. <view :style="{height: divHeight}" class="medic-box">
  16. <view class="cate-list">
  17. <view
  18. v-for="(item,index) in cates"
  19. :key="index"
  20. :class="cateSelect == item.cateId?'item active':'item'"
  21. @click="choseCate(item)"
  22. >{{item.cateName }}</view>
  23. </view>
  24. <view class="medic">
  25. <!-- 轮播图 -->
  26. <!-- <view class="banner-box">
  27. <swiper
  28. class="swiper"
  29. :indicator-dots="true"
  30. :circular="true"
  31. :autoplay="true"
  32. :interval="3000"
  33. :duration="1000"
  34. indicator-color="rgba(255, 255, 255, 0.6)"
  35. indicator-active-color="#ffffff"
  36. >
  37. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index" @click="handleAdvClick(item)">
  38. <image :src="item.imageUrl" mode=""></image>
  39. </swiper-item>
  40. </swiper>
  41. </view> -->
  42. <!-- 药品列表 -->
  43. <!-- <view class="medic-list">
  44. <view class="item" v-for="(item,index) in subCates" :key="index">
  45. <view class="title">{{item.cateName}}</view>
  46. <view class="inner-list">
  47. <view class="definite"v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  48. <view class="img-box">
  49. <image :src="subItem.pic" mode="aspectFit"></image>
  50. </view>
  51. <view class="name ellipsis">{{subItem.cateName}}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view> -->
  56. <mescroll-body top="190rpx" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  57. <view style="display: flex;flex-wrap: wrap;">
  58. <medicineVerticalItem v-for="(item, index) in dataList" :key="index" :item="item"></medicineVerticalItem>
  59. </view>
  60. </mescroll-body>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import {getProductCate,getProducts} from '@/api/index.js'
  67. import {getAdv} from '@/api/adv'
  68. import medicineVerticalItem from "@/components/medicineVerticalItem";
  69. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  70. export default {
  71. mixins: [MescrollMixin], // 使用mixin
  72. components: {
  73. medicineVerticalItem
  74. },
  75. data() {
  76. return {
  77. divHeight:'0px',
  78. allCates:[],
  79. cates:[],
  80. subCates:[],
  81. // 状态栏的高度
  82. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  83. // 选中药品分类
  84. cateSelect: 0,
  85. // 轮播图
  86. advs: [],
  87. mescroll:null,
  88. downOption: { //下拉刷新
  89. use:true,
  90. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  91. },
  92. // 上拉加载的配置
  93. upOption: {
  94. onScroll:true,
  95. use: true, // 是否启用上拉加载; 默认true
  96. page: {
  97. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  98. size: 10 // 每页数据的数量,默认10
  99. },
  100. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  101. empty: {
  102. icon:'https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/empty_icon.png',
  103. tip: '暂无数据'
  104. },
  105. textNoMore:"已经到底了",
  106. },
  107. // 列表数据
  108. dataList: [],
  109. form:{
  110. defaultOrder:'desc',
  111. newOrder:null,
  112. priceOrder:null,
  113. salesOrder:null,
  114. productName:"",
  115. storeId: "",
  116. cateId:'',
  117. pid:''
  118. },
  119. };
  120. },
  121. onLoad() {
  122. uni.showShareMenu({
  123. withShareTicket:true,
  124. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  125. menus:["shareAppMessage","shareTimeline"] //不设置默认发送给朋友
  126. })
  127. this.getProductCate();
  128. },
  129. onShow() {
  130. var that=this;
  131. setTimeout(function(){
  132. let info = uni.createSelectorQuery().select(".top-content");
  133.     info.boundingClientRect(function(data) { //data - 各种参数
  134.       console.log(data.height) // 获取元素宽度
  135. // console.log(uni.upx2px(10))
  136. that.divHeight="calc(100% - "+data.height+"px)"
  137.    }).exec()
  138. },500);
  139. this.getAdv();
  140. },
  141. methods:{
  142. // divHeight(){
  143. // return 'height:calc(100% - ${this.top}px);'
  144. // },
  145. splitPrice(num) {
  146. const [intPart = '0', decPart = '00'] = String(num||0).split('.');
  147. return { intPart, decPart: decPart.padEnd(2, '0').slice(0, 2) };
  148. },
  149. toSearch() {
  150. uni.navigateTo({
  151. url: '/pages_shopping/home/productSearch'
  152. })
  153. },
  154. handleAdvClick(item){
  155. console.log(item);
  156. if(item.showType==1){
  157. uni.setStorageSync('url',item.advUrl);
  158. uni.navigateTo({
  159. url:"/pages_shopping/home/h5"
  160. })
  161. }
  162. else if(item.showType==2){
  163. uni.navigateTo({
  164. url:item.advUrl
  165. })
  166. }
  167. else if(item.showType==3){
  168. uni.setStorageSync('content',item.content);
  169. uni.navigateTo({
  170. url:"/pages_shopping/home/content"
  171. })
  172. }
  173. },
  174. getAdv(){
  175. let data = {advType:2};
  176. getAdv(data).then(
  177. res => {
  178. if(res.code==200){
  179. this.advs=res.data;
  180. }
  181. },
  182. rej => {}
  183. );
  184. },
  185. getProductCate(){
  186. let data = {};
  187. getProductCate(data).then(
  188. res => {
  189. if(res.code==200){
  190. this.allCates=res.data;
  191. this.cates = this.allCates.filter(function (item) {
  192. return item.pid==0
  193. });
  194. if(this.cates!=null&&this.cates.length>0){
  195. this.cateSelect=this.cates[0].cateId;
  196. // this.getSubCate()
  197. this.form.cateId = this.cates[0].cateId;
  198. // this.form.pid = this.cates[0].pid;
  199. this.mescroll.resetUpScroll()
  200. console.log("this.mescroll",this.mescroll)
  201. }
  202. }else{
  203. uni.showToast({
  204. icon:'none',
  205. title: "请求失败",
  206. });
  207. }
  208. },
  209. rej => {}
  210. );
  211. },
  212. // 药品分类选择
  213. choseCate(item) {
  214. this.cateSelect = item.cateId;
  215. // this.getSubCate()
  216. this.form.cateId = item.cateId;
  217. // this.form.pid = item.pid;
  218. this.mescroll.resetUpScroll()
  219. },
  220. getSubCate(){
  221. var that=this;
  222. this.subCates = this.allCates.filter(function (item) {
  223. // let subList = that.allCates.filter(child => {
  224. // //返回每一项的子级数组
  225. // return child.pid === item.cateId
  226. // });
  227. // subList.length > 0 ? item.children = subList : [];
  228. return item.pid==that.cateSelect
  229. });
  230. console.log(this.subCates);
  231. },
  232. // 查看药品详情
  233. showProductList(item) {
  234. uni.navigateTo({
  235. url: '/pages_shopping/productList?cateId='+item.cateId+"&pid="+item.pid
  236. })
  237. },
  238. goSearch(e) {
  239. if(e.detail.value!=null&&e.detail.value!=""){
  240. this.$addHisSearch(e.detail.value);
  241. }
  242. uni.navigateTo({
  243. url: '/pages_shopping/home/productList?searchValue=' + e.detail.value
  244. })
  245. },
  246. mescrollInit(mescroll) {
  247. this.mescroll = mescroll;
  248. },
  249. /*下拉刷新的回调 */
  250. downCallback(mescroll) {
  251. mescroll.resetUpScroll()
  252. },
  253. upCallback(page) {
  254. //联网加载数据
  255. var that = this;
  256. this.form.page=page.num;
  257. this.form.pageSize=page.size;
  258. getProducts(this.form).then(res => {
  259. if(res.code==200){
  260. //设置列表数据
  261. if (page.num == 1) {
  262. that.dataList = res.data.list;
  263. } else {
  264. that.dataList = that.dataList.concat(res.data.list);
  265. }
  266. that.mescroll.endBySize(res.data.list.length, res.data.total);
  267. }else{
  268. uni.showToast({
  269. icon:'none',
  270. title: "请求失败",
  271. });
  272. that.dataList = null;
  273. that.mescroll.endErr();
  274. }
  275. });
  276. },
  277. }
  278. }
  279. </script>
  280. <style lang="scss">
  281. page{
  282. height: 100%;
  283. background-color: #fff;
  284. }
  285. .content{
  286. height: 100%;
  287. display: flex;
  288. flex-direction: column;
  289. .top-content{
  290. width: 100%;
  291. z-index: 10;
  292. .top-title{
  293. height: 88upx;
  294. line-height: 88upx;
  295. font-size: 42upx;
  296. font-family: Source Han Sans CN;
  297. font-weight: bold;
  298. color: #222222;
  299. padding-left: 41upx;
  300. background-color: #FFFFFF;
  301. }
  302. .search-cont{
  303. padding: 16upx 30upx;
  304. background-color: #FFFFFF;
  305. .inner{
  306. box-sizing: border-box;
  307. width: 100%;
  308. height: 72upx;
  309. background: #F7F7F7;
  310. border-radius: 36upx;
  311. display: flex;
  312. align-items: center;
  313. padding: 0 30upx;
  314. .icon-search{
  315. width: 28upx;
  316. height: 28upx;
  317. margin-right: 20upx;
  318. }
  319. input{
  320. height: 60upx;
  321. line-height: 60upx;
  322. flex: 1;
  323. }
  324. }
  325. }
  326. }
  327. .medic-box{
  328. display: flex;
  329. .cate-list{
  330. box-sizing: border-box;
  331. width: 200upx;
  332. background: #F2F5F9;
  333. display: flex;
  334. flex-direction: column;
  335. padding: 20upx 0;
  336. overflow-y: scroll;
  337. .item{
  338. height: 100upx;
  339. line-height: 100upx;
  340. padding-left: 30upx;
  341. font-size: 28upx;
  342. font-family: PingFang SC;
  343. font-weight: 500;
  344. color: #333333;
  345. position: relative;
  346. &.active{
  347. color: #2583EB;
  348. &::after{
  349. content: "";
  350. width: 8upx;
  351. height: 50upx;
  352. background: #2583EB;
  353. position: absolute;
  354. top: 25upx;
  355. left: 0;
  356. }
  357. }
  358. }
  359. }
  360. .medic{
  361. box-sizing: border-box;
  362. width: calc(100% - 200upx);
  363. height: 100%;
  364. margin: 0 24upx;
  365. .banner-box{
  366. margin-top: 30rpx;
  367. width: 100%;
  368. height: 160upx;
  369. border-radius: 10upx;
  370. overflow: hidden;
  371. .swiper,
  372. .swiper-item,
  373. .swiper-item image{
  374. width: 100%;
  375. height: 100%;
  376. }
  377. }
  378. .medic-list{
  379. box-sizing: border-box;
  380. padding: 30upx 0;
  381. overflow-y: auto;
  382. height: calc(100% - 220upx);
  383. position: relative;
  384. // .item{
  385. // .title{
  386. // font-size: 28upx;
  387. // font-family: PingFang SC;
  388. // font-weight: bold;
  389. // color: #333333;
  390. // padding-top: 20upx;
  391. // margin-bottom: 30upx;
  392. // }
  393. // }
  394. .inner-list{
  395. display: flex;
  396. flex-wrap: wrap;
  397. .definite{
  398. width: calc(33% - 20upx);
  399. margin-right: 30upx;
  400. margin-bottom: 30upx;
  401. .img-box{
  402. width: 100%;
  403. height: 144upx;
  404. background: #F5F5F5;
  405. border-radius: 8upx;
  406. overflow: hidden;
  407. display: flex;
  408. align-items: center;
  409. image{
  410. max-width: 100%;
  411. }
  412. }
  413. .name{
  414. width: 100%;
  415. margin-top: 20upx;
  416. font-size: 24upx;
  417. font-family: PingFang SC;
  418. font-weight: 500;
  419. color: #666666;
  420. text-align: center;
  421. }
  422. &:nth-child(3n) {
  423. margin-right: 0;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. </style>