耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
13 KiB

  1. <template>
  2. <view class="u-wrap">
  3. <!-- <view class="u-search-box">
  4. <view class="u-search-inner">
  5. <u-icon name="search" color="#909399" :size="28"></u-icon>
  6. <text class="u-search-text">搜索uView</text>
  7. </view>
  8. </view> -->
  9. <view class="sort-search">
  10. <!-- <u-search
  11. v-model="keyword"
  12. bg-color="#fff"
  13. height="80"
  14. placeholder="请输入要搜索的商品"
  15. :action-style="{color: '#fff'}"
  16. /> -->
  17. <u-search disabled placeholder="请输入要搜索的商品" height="70" :show-action="false" @click="handleSearch" />
  18. </view>
  19. <view class="u-menu-wrap">
  20. <scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view" :scroll-top="scrollTop">
  21. <view v-for="(item,index) in leftList" :key="index"
  22. class="u-tab-item"
  23. :class="[current==index ? 'u-tab-item-active' : '']"
  24. :data-current="index" @tap.stop="swichMenu(index,item.id)"
  25. >
  26. <!-- u-line-1 单行打点无法知道整行的内容 -->
  27. <text class=".p-l-27">{{item.name}}</text>
  28. </view>
  29. </scroll-view>
  30. <view class="position-relative flex-1 right_box_width">
  31. <view class="right-tabs flex align-center flex-1" v-if="rightTopList.length > 0 && !openShow">
  32. <scroll-view scroll-with-animation scroll-x class="right-tabs-scroll tab-scroll-view" :scroll-left="scrollLeft">
  33. <view class="flex align-center">
  34. <com-view
  35. v-for="(item, index) in rightTopList"
  36. :key="index"
  37. class="right-tabs-item flex align-center justify-center"
  38. :class="[{'right-tabs-item-active': currentTab === index}, `tabs-item-${index}`]"
  39. @click="handleRightTab(item, index)"
  40. >
  41. <!-- v-show="index < 2" 只展示两个就好 其他的去点击展开 -->
  42. {{item.name}}
  43. </com-view>
  44. </view>
  45. </scroll-view>
  46. <u-icon name="arrow-right"></u-icon>
  47. <!-- <view class="open flex align-center justify-center" @click="open">
  48. <text class="font-28 text-black m-r-10">展开</text>
  49. <u-icon name="arrow-down" size="28"></u-icon>
  50. </view> -->
  51. </view>
  52. <scroll-view
  53. scroll-y
  54. @scrolltolower="goodsToLower()"
  55. class="right-box flex flex-column"
  56. >
  57. <!-- v-if="current==index"
  58. v-for="(item,index) in tabbar" :key="index" -->
  59. <view class="page-view" v-if="rightListGoods.length">
  60. <view class="class-item">
  61. <view class="item-container">
  62. <view class="thumb-box" v-for="(item1, index1) in rightListGoods" :key="index1">
  63. <!-- <goods-item></goods-item> -->
  64. <goods-item :goods="item1" thereTo='sort'></goods-item>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="h-100 flex align-center justify-center" v-else-if="!loading">
  70. <u-empty text="暂无商品 " mode="list"></u-empty>
  71. </view>
  72. </scroll-view>
  73. <view class="position-absolute left-0 top-0 h-100 zIndex-1" v-show="openShow" style="width: 550rpx;">
  74. <view class="open-popup" @click="openShow = false"></view>
  75. <view class="open-box" :style="[openStyle]">
  76. <view class="flex align-center flex-wrap">
  77. <com-view
  78. v-for="(item, index) in rightTopList"
  79. :key="index"
  80. class="right-tabs-item flex align-center justify-center m-t-20"
  81. :class="[{'right-tabs-item-active': currentTab === index}, `tabs-item-${index}`]"
  82. @click="handleRightTab(item, index)"
  83. >
  84. {{item.name}}
  85. </com-view>
  86. </view>
  87. <view class="flex align-center justify-end m-t-4" @click="openShow = false">
  88. <text class="font-28 text-black">收起</text>
  89. <u-icon name="arrow-up" size="28"></u-icon>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. scrollTop: 0, //tab标题的滚动条位置
  103. current: 0, // 预设当前项的值
  104. menuHeight: 0, // 左边菜单的高度
  105. menuItemHeight: 0, // 左边菜单item的高度
  106. keyword: '',
  107. currentTab: 0,
  108. scrollLeft: 0,
  109. tabWidth: 0, // 左边菜单的高度
  110. tabItemWidth: 0, // 左边菜单item的高度
  111. tabItemLeft: 0,
  112. openShow: false,
  113. openStyle: {},
  114. leftList: [],
  115. rightTopList: [], // 右上展示的值
  116. rightListGoods: [], // 右边展示商品
  117. classId: '',
  118. hasChild: null, //是否还有下级 -> 有没有右上角标签
  119. pageNo: 1,
  120. pageSize: 10,
  121. total: null,
  122. isLock: true,
  123. loading: true
  124. }
  125. },
  126. watch: {
  127. openShow () {
  128. this.$nextTick(() => {
  129. this.openStyle = this.openShow ? {transform: 'translateY(0)'} : {transform: 'translateY(-100%)'}
  130. })
  131. }
  132. },
  133. onLoad() {
  134. this.loading = true
  135. this.getGoodsClassList();
  136. this.getRightListGoods();
  137. },
  138. onPullDownRefresh() {
  139. this.leftList = []
  140. this.rightTopList = [] // 右上展示的值
  141. this.rightListGoods = []
  142. this.pageNo = 1
  143. this.pageSize = 10
  144. this.total = null,
  145. this.getGoodsClassList();
  146. this.getRightListGoods();
  147. this.loading = true
  148. },
  149. methods: {
  150. open () {
  151. this.openShow = true
  152. },
  153. async handleRightTab (item, index) {
  154. if(index == this.currentTab) return ;
  155. this.currentTab = index
  156. // 点击调用商品 hasChild = 0
  157. //
  158. this.hasChild = 0;
  159. this.classId = item.id
  160. this.rightListGoods = []
  161. this.loading = true
  162. this.getRightListGoods();
  163. // this.tabScrollView = `tabs-item-${index}`
  164. // // 如果为0,意味着尚未初始化
  165. if(this.tabWidth == 0 || this.tabItemWidth == 0) {
  166. await this.getElRect('tab-scroll-view', 'tabWidth', 'width');
  167. }
  168. await this.getElRect(`tabs-item-${index}`, 'tabItemWidth', 'width')
  169. await this.getscrollLeft(`tabs-item-${index}`, 'tabItemLeft')
  170. this.scrollLeft = this.tabItemLeft - this.tabWidth / 2 - this.tabItemWidth / 2;
  171. // this.scrollLeft = index * this.tabItemWidth - this.tabWidth / 2 - this.tabItemWidth / 2;
  172. },
  173. getImg() {
  174. return Math.floor(Math.random() * 35);
  175. },
  176. // 点击左边的栏目切换
  177. async swichMenu(index,id) {
  178. if(index == this.current) return ;
  179. this.current = index;
  180. // 如果为0,意味着尚未初始化
  181. if(this.menuHeight == 0 || this.menuItemHeight == 0) {
  182. await this.getElRect('menu-scroll-view', 'menuHeight');
  183. await this.getElRect('u-tab-item', 'menuItemHeight');
  184. }
  185. // 将菜单菜单活动item垂直居中
  186. this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
  187. this.classId = id;
  188. // 切换菜单重置 商品信息
  189. this.pageNo = 1;
  190. this.total = null;
  191. this.rightTopList = [];
  192. this.rightListGoods = [];
  193. this.loading = true
  194. this.getGoodsClassList();
  195. this.getRightListGoods();
  196. },
  197. // 获取一个目标元素的高度
  198. getElRect(elClass, dataVal, attribute = 'height') {
  199. return new Promise((resolve, reject) => {
  200. const query = uni.createSelectorQuery().in(this);
  201. query.select('.' + elClass).fields({size: true}, res => {
  202. console.log(elClass, res)
  203. // 如果节点尚未生成,res值为null,循环调用执行
  204. if(!res) {
  205. setTimeout(() => {
  206. this.getElRect(elClass);
  207. }, 10);
  208. return ;
  209. }
  210. // this[dataVal] = !other ? res[attribute] : res[other]
  211. this[dataVal] = res[attribute]
  212. resolve()
  213. }).exec();
  214. })
  215. },
  216. handleSearch () {
  217. this.$tools.navigateTo({
  218. url: '/pagesC/search/search'
  219. })
  220. },
  221. getscrollLeft(elClass, dataVal) {
  222. return new Promise((resolve, reject) => {
  223. const query = uni.createSelectorQuery().in(this);
  224. query.select('.' + elClass).fields({size: true, scrollOffset: true}, res => {
  225. console.log(res)
  226. if(!res) {
  227. setTimeout(() => {
  228. this.getscrollLeft(elClass);
  229. }, 10);
  230. return ;
  231. }
  232. this[dataVal] = res.scrollLeft
  233. resolve()
  234. }).exec();
  235. })
  236. },
  237. getGoodsClassList() {
  238. let params = {}
  239. if(this.leftList.length == 0) {
  240. }else{
  241. params = {
  242. classId: this.classId
  243. }
  244. }
  245. if (this.current == 0) {
  246. params = {
  247. classId: '',
  248. hasChild: ''
  249. }
  250. }
  251. this.$api('getGoodsClassList',params).then(res => {
  252. let { code, result, message } = res;
  253. if(code == 200) {
  254. console.log(result);
  255. if(this.classId == ''){
  256. this.classId = result[0].id;
  257. this.hasChild = result[0].hasChild;
  258. this.leftList = [{name: '全部',id: ''},...result]
  259. // this.getGoodsClassList(); // 获取
  260. }else{
  261. this.rightTopList = result; // 得到的是右上的值
  262. }
  263. }else {
  264. this.$Toast(message);
  265. }
  266. }).catch(err => {
  267. this.$Toast(err.message)
  268. })
  269. },
  270. goodsToLower() {
  271. if(this.isLock) {
  272. if(this.total !== null && this.pageNo * this.pageSize >= this.total){
  273. this.isLock = false;
  274. this.$Toast('没有更多数据了哦!');
  275. setTimeout(()=>{
  276. this.isLock = true;
  277. },3000)
  278. return
  279. }
  280. this.pageNo+=1;
  281. this.getRightListGoods();
  282. }
  283. },
  284. getRightListGoods() {
  285. const params = {
  286. pageNo: this.pageNo,
  287. pageSize: this.pageSize,
  288. }
  289. if(this.current == 0) {
  290. }else{
  291. params.classId = this.classId
  292. params.hasChild = this.hasChild
  293. }
  294. uni.showLoading();
  295. this.$api('getGoodsList',params).then(res => {
  296. let { code, result, message} = res;
  297. uni.hideLoading();
  298. console.log(result)
  299. this.loading = false
  300. if(code == 200){
  301. if(this.total == null) {
  302. this.total = result.total;
  303. }
  304. result.records.forEach(item => {
  305. // const picArray= item.pic.split(',')
  306. // item.pic= picArray[0]
  307. if(item.pic!==null){
  308. const picArray=item.pic.split(',')
  309. item.pic= picArray[0]
  310. }else{
  311. item.pic= []
  312. }
  313. })
  314. this.rightListGoods = this.rightListGoods.concat(result.records);
  315. }else{
  316. this.$Toast(message);
  317. }
  318. this.isLock = true;
  319. }).catch( err => {
  320. this.loading = false
  321. this.isLock = true;
  322. uni.hideLoading();
  323. this.$Toast(err.message);
  324. })
  325. }
  326. }
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. // 穿透图片 设置大小
  331. // /deep/.goods-items-image{
  332. // width: 522rpx !important;
  333. // }
  334. .u-wrap {
  335. height: calc(100vh);
  336. /* #ifdef H5 */
  337. height: calc(100vh - var(--window-top));
  338. /* #endif */
  339. display: flex;
  340. flex-direction: column;
  341. }
  342. .sort-search {
  343. padding: 0 20rpx 20rpx;
  344. background: $u-type-primary;
  345. }
  346. .u-search-box {
  347. padding: 18rpx 30rpx;
  348. }
  349. .u-menu-wrap {
  350. flex: 1;
  351. display: flex;
  352. overflow: hidden;
  353. }
  354. .right_box_width{
  355. // width: 550rpx;
  356. }
  357. .u-search-inner {
  358. background-color: rgb(234, 234, 234);
  359. border-radius: 100rpx;
  360. display: flex;
  361. align-items: center;
  362. padding: 10rpx 16rpx;
  363. }
  364. .u-search-text {
  365. font-size: 26rpx;
  366. color: $u-tips-color;
  367. margin-left: 10rpx;
  368. }
  369. .u-tab-view {
  370. width: 200rpx;
  371. height: 100%;
  372. }
  373. .u-tab-item {
  374. width: 200rpx;
  375. height: 110rpx;
  376. background: #f6f6f6;
  377. box-sizing: border-box;
  378. display: flex;
  379. align-items: center;
  380. justify-content: center;
  381. font-size: 26rpx;
  382. color: #444;
  383. font-weight: 400;
  384. line-height: 1;
  385. }
  386. .u-tab-item-active {
  387. position: relative;
  388. color: #000;
  389. font-size: 30rpx;
  390. font-weight: 600;
  391. background: #fff;
  392. }
  393. .u-tab-item-active::before {
  394. content: "";
  395. position: absolute;
  396. border-left: 4px solid $u-type-primary;
  397. height: 32rpx;
  398. left: 0;
  399. top: 39rpx;
  400. }
  401. .u-tab-view {
  402. height: 100%;
  403. }
  404. .open {
  405. width: 140rpx;
  406. height: 80rpx;
  407. }
  408. .right-tabs-scroll {
  409. width: calc(100vw - 240rpx);
  410. white-space: nowrap;
  411. }
  412. .right-tabs {
  413. height: 80rpx;
  414. &-item {
  415. height: 50rpx;
  416. padding: 0 20rpx;
  417. background: #eeeeee;
  418. border-radius: 18px;
  419. margin-left: 30rpx;
  420. font-size: 24rpx;
  421. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  422. color: #000000;
  423. &-active {
  424. background: #baebfc;
  425. color: $u-type-primary;
  426. }
  427. }
  428. }
  429. .right-box {
  430. height: calc(100vh - 180rpx);
  431. background-color: rgb(250, 250, 250);
  432. }
  433. .page-view {
  434. padding: 16rpx;
  435. }
  436. .class-item {
  437. margin-bottom: 30rpx;
  438. background-color: #fff;
  439. padding: 16rpx;
  440. border-radius: 8rpx;
  441. }
  442. .item-title {
  443. font-size: 26rpx;
  444. color: $u-main-color;
  445. font-weight: bold;
  446. }
  447. .item-menu-name {
  448. font-weight: normal;
  449. font-size: 24rpx;
  450. color: $u-main-color;
  451. }
  452. .item-container {
  453. display: flex;
  454. flex-wrap: wrap;
  455. }
  456. .thumb-box {
  457. margin-top: 20rpx;
  458. width: 100%;
  459. }
  460. .item-menu-image {
  461. width: 120rpx;
  462. height: 120rpx;
  463. }
  464. .open {
  465. width: 100%;
  466. &-popup{
  467. position: absolute;
  468. width: 100%;
  469. height: 100%;
  470. background-color: rgba(0, 0, 0, .6);
  471. z-index: 0;
  472. }
  473. &-box {
  474. position: relative;
  475. background-color: #fff;
  476. padding: 0 20rpx 10rpx 0;
  477. z-index: 1;
  478. transition: all .4s linear;
  479. transform: translateY(-100%);
  480. }
  481. }
  482. </style>