index.vue 10 KB

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