index.vue 9.5 KB

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