index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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://cqtyt-2025.oss-cn-beijing.aliyuncs.com/shop/images/search.png" mode=""></image>
  11. <input type="text" 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="medic-list">
  27. <!-- <view class="item" v-for="(item,index) in subCates" :key="index">
  28. <view class="title">{{item.cateName}}</view> -->
  29. <view class="inner-list">
  30. <view class="definite"v-for="(subItem,index) in subCates" @click="showProductList(subItem)">
  31. <view class="img-box">
  32. <image :src="subItem.pic" mode="aspectFit"></image>
  33. </view>
  34. <view class="name ellipsis">{{subItem.cateName}}</view>
  35. </view>
  36. </view>
  37. <!-- </view> -->
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {getProductCate} from '@/api/product'
  45. export default {
  46. data() {
  47. return {
  48. divHeight:'0px',
  49. allCates:[],
  50. cates:[],
  51. subCates:[],
  52. // 状态栏的高度
  53. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  54. // 选中药品分类
  55. cateSelect: 0,
  56. // 轮播图
  57. advs: [],
  58. isshow:false
  59. };
  60. },
  61. onLoad() {
  62. uni.showShareMenu({
  63. withShareTicket:true,
  64. //小程序的原生菜单中显示分享按钮,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  65. menus:["shareAppMessage","shareTimeline"] //不设置默认发送给朋友
  66. })
  67. this.getProductCate();
  68. },
  69. onShow() {
  70. var that=this;
  71. setTimeout(function(){
  72. let info = uni.createSelectorQuery().select(".top-content");
  73.     info.boundingClientRect(function(data) { //data - 各种参数
  74. //       console.log(data.height) // 获取元素宽度
  75. // console.log(uni.upx2px(10))
  76. that.divHeight="calc(100% - "+data.height+"px)"
  77.    }).exec()
  78. },500);
  79. },
  80. methods:{
  81. divHeight1(){
  82. return 'height:calc(100% - ${this.top}px);'
  83. },
  84. toSearch() {
  85. uni.navigateTo({
  86. url: '/pages_shopping/productSearch'
  87. })
  88. },
  89. getProductCate(){
  90. let data = {};
  91. getProductCate(data).then(
  92. res => {
  93. if(res.code==200){
  94. this.allCates=res.data;
  95. this.cates = this.allCates.filter(function (item) {
  96. return item.pid==0
  97. });
  98. if(this.cates!=null&&this.cates.length>0){
  99. this.cateSelect=this.cates[0].cateId;
  100. this.getSubCate()
  101. }
  102. }else{
  103. uni.showToast({
  104. icon:'none',
  105. title: "请求失败",
  106. });
  107. }
  108. },
  109. rej => {}
  110. );
  111. },
  112. // 药品分类选择
  113. choseCate(item) {
  114. this.cateSelect = item.cateId;
  115. this.getSubCate()
  116. },
  117. getSubCate(){
  118. var that=this;
  119. this.subCates = this.allCates.filter(function (item) {
  120. // let subList = that.allCates.filter(child => {
  121. // //返回每一项的子级数组
  122. // return child.pid === item.cateId
  123. // });
  124. // subList.length > 0 ? item.children = subList : [];
  125. return item.pid==that.cateSelect
  126. });
  127. console.log(this.subCates);
  128. },
  129. // 查看药品详情
  130. showProductList(item) {
  131. uni.navigateTo({
  132. url: '/pages_shopping/productList?cateId='+item.cateId+"&pid="+item.pid
  133. })
  134. },
  135. goSearch(e) {
  136. if(e.detail.value!=null&&e.detail.value!=""){
  137. this.utils.addHisSearch(e.detail.value);
  138. }
  139. uni.navigateTo({
  140. url: '/pages_shopping/productListAll?searchValue=' + e.detail.value
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss">
  147. page{
  148. height: 100%;
  149. background-color: #fff;
  150. }
  151. .content{
  152. height: 100%;
  153. display: flex;
  154. flex-direction: column;
  155. .top-content{
  156. width: 100%;
  157. z-index: 10;
  158. .top-title{
  159. height: 88upx;
  160. line-height: 88upx;
  161. font-size: 42upx;
  162. font-family: Source Han Sans CN;
  163. font-weight: bold;
  164. color: #222222;
  165. padding-left: 41upx;
  166. background-color: #FFFFFF;
  167. }
  168. .search-cont{
  169. padding: 16upx 30upx;
  170. background-color: #FFFFFF;
  171. .inner{
  172. box-sizing: border-box;
  173. width: 100%;
  174. height: 72upx;
  175. background: #F7F7F7;
  176. border-radius: 36upx;
  177. display: flex;
  178. align-items: center;
  179. padding: 0 30upx;
  180. .icon-search{
  181. width: 28upx;
  182. height: 28upx;
  183. margin-right: 20upx;
  184. }
  185. input{
  186. height: 60upx;
  187. line-height: 60upx;
  188. flex: 1;
  189. }
  190. }
  191. }
  192. }
  193. .medic-box{
  194. display: flex;
  195. .cate-list{
  196. box-sizing: border-box;
  197. width: 200upx;
  198. background: #F2F5F9;
  199. display: flex;
  200. flex-direction: column;
  201. padding: 20upx 0;
  202. overflow-y: scroll;
  203. .item{
  204. height: 100upx;
  205. // line-height: 100upx;
  206. padding-left: 30upx;
  207. font-size: 28upx;
  208. font-family: PingFang SC;
  209. font-weight: 500;
  210. color: #333333;
  211. position: relative;
  212. display: flex;
  213. align-items: center;
  214. &.active{
  215. color: #2BC7B9;
  216. &::after{
  217. content: "";
  218. width: 8upx;
  219. height: 50upx;
  220. background: #2BC7B9;
  221. position: absolute;
  222. top: 25upx;
  223. left: 0;
  224. }
  225. }
  226. }
  227. }
  228. .medic{
  229. box-sizing: border-box;
  230. width: calc(100% - 200upx);
  231. height: 100%;
  232. padding: 0 30upx;
  233. .medic-list{
  234. box-sizing: border-box;
  235. padding: 30upx 0;
  236. overflow-y: auto;
  237. height: calc(100% - 220upx);
  238. position: relative;
  239. .inner-list{
  240. display: flex;
  241. flex-wrap: wrap;
  242. .definite{
  243. width: calc(33% - 20upx);
  244. margin-right: 30upx;
  245. margin-bottom: 30upx;
  246. .img-box{
  247. width: 100%;
  248. height: 144upx;
  249. background: #F5F5F5;
  250. border-radius: 8upx;
  251. overflow: hidden;
  252. display: flex;
  253. align-items: center;
  254. image{
  255. max-width: 100%;
  256. }
  257. }
  258. .name{
  259. width: 100%;
  260. margin-top: 20upx;
  261. font-size: 24upx;
  262. font-family: PingFang SC;
  263. font-weight: 500;
  264. color: #666666;
  265. text-align: center;
  266. }
  267. &:nth-child(3n) {
  268. margin-right: 0;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. }
  276. </style>