index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <template>
  2. <view class='productSort copy-data'>
  3. <view class="scroll-box">
  4. <view class='aside'>
  5. <scroll-view scroll-y="true" scroll-with-animation='true' style="height: calc(100% - 100rpx)">
  6. <view class='item acea-row row-center-wrapper' :class='index == navActive ? "on" : ""'
  7. v-for="(item, index) in productList" :key="index" @click='tap(item, index, "b" + index)'>
  8. <text>{{ $t(item.title) }}</text>
  9. </view>
  10. </scroll-view>
  11. </view>
  12. <view class='conter'>
  13. <scroll-view scroll-y="true" :scroll-into-view="toView" @scroll="scroll" scroll-with-animation='true'
  14. style="height: 100%;" class="conterScroll">
  15. <block>
  16. <view class='listw' :id="'b' + index">
  17. <view class="all-products-body" v-for="(itemn, indexn) in goodsList" :key="indexn">
  18. <view class="all-products-item" @click="choice(itemn)">
  19. <image :src='itemn.goodsCover' v-if="itemn.goodsCover"></image>
  20. <image src="/static/images/sort-img.png" v-else></image>
  21. <view class="all-products-item-content">
  22. <view class="all-products-item-content-t">
  23. {{ itemn.goodsName }}
  24. </view>
  25. <view class="all-products-item-content-b">
  26. <view style="display:flex; flex-grow: 1;">
  27. <text class="red"> ¥{{ itemn.discountPrice }}</text>
  28. </view>
  29. <view @click="delItem(indexn)" class="count">
  30. <image v-if="itemn.selected" src="http://www.gzzzyd.com/groupon/home_slices/添加@2x.png" mode="scaleToFill" />
  31. <image v-else src="http://www.gzzzyd.com/groupon/home_slices/添加@2x(1).png" mode="scaleToFill" />
  32. </view>
  33. <view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </block>
  41. <view :style='"height:" + (height - 300) + "rpx;"' v-if="number < 15"></view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. <view class="foot" v-if="is_diy && newData.status && newData.status.status">
  46. <view class="page-footer" id="target" :style="{ 'background-color': newData.bgColor.color[0].item }">
  47. <view class="foot-item" v-for="(item, index) in newData.menuList" :key="index" @click="goRouter(item)">
  48. <block v-if="item.link == activeRouter">
  49. <image :src="item.imgList[0]"></image>
  50. <view class="txt" :style="{ color: newData.activeTxtColor.color[0].item }">
  51. {{ $t(item.name) }}</view>
  52. </block>
  53. <block v-else>
  54. <image :src="item.imgList[1]"></image>
  55. <view class="txt" :style="{ color: newData.txtColor.color[0].item }">
  56. {{ $t(item.name) }}</view>
  57. </block>
  58. <div class="count-num" v-if="item.link === '/pages/order_addcart/order_addcart' && cartNum > 0">
  59. {{ cartNum }}
  60. </div>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import { getCategoryOne, getCategoryTwo, getGoodsList } from '@/api/home.js'
  68. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  69. import {
  70. getCategoryList
  71. } from '@/api/store.js';
  72. import {
  73. mapState,
  74. mapGetters
  75. } from "vuex"
  76. import pageFooter from '@/components/pageFooter/index.vue'
  77. import {
  78. getNavigation
  79. } from '@/api/public.js'
  80. const app = getApp();
  81. export default {
  82. components: {
  83. pageFooter
  84. },
  85. data () {
  86. return {
  87. vGoodsIdList:[],
  88. goodsList: [],
  89. selectItem: [],
  90. src: 'http://www.gzzhsckj.com:9000/bladex/upload/20221026/5956cfd37ebc31cd2e00797909987482.jpg',
  91. navlist: [],
  92. productList: [],
  93. productList2: [],
  94. navActive: 0,
  95. number: "",
  96. is_diy: uni.getStorageSync('is_diy'),
  97. height: 0,
  98. hightArr: [],
  99. toView: "",
  100. tabbarH: 0,
  101. footH: 0,
  102. windowHeight: 0,
  103. newData: {},
  104. activeRouter: '',
  105. pageHeight: '80%',
  106. sysHeight: sysHeight,
  107. // #ifdef APP-PLUS
  108. pageHeight: app.globalData.windowHeight,
  109. // #endif
  110. footerStatus: false,
  111. lock: false,
  112. selectId: []
  113. }
  114. },
  115. computed: {
  116. ...mapState({
  117. cartNum: state => state.indexData.cartNum
  118. })
  119. },
  120. created () {
  121. this.getCategoryOne()
  122. },
  123. mounted () {
  124. let that = this
  125. let routes = getCurrentPages();
  126. let curRoute = routes[routes.length - 1].route
  127. this.activeRouter = '/' + curRoute
  128. // this.getAllCategory();
  129. // #ifdef H5
  130. uni.getSystemInfo({
  131. success: function (res) {
  132. that.pageHeight = res.windowHeight + 'px'
  133. }
  134. });
  135. // #endif
  136. },
  137. methods: {
  138. /**
  139. * 父组件调用这个方法,返回选中的商品id数组
  140. * @returns {[]}
  141. */
  142. returnVGoodIds(){
  143. return this.vGoodsIdList
  144. },
  145. choice (item) {
  146. item.selected = !item.selected
  147. if (this.vGoodsIdList.indexOf(item.id) ===-1){
  148. this.vGoodsIdList.push(item.id)
  149. }else {
  150. this.vGoodsIdList = this.vGoodsIdList.filter(iter => iter !== item.id)
  151. }
  152. console.log(this.vGoodsIdList)
  153. },
  154. getCategoryOne () {
  155. getCategoryOne({
  156. parentId: 0
  157. }).then(res => {
  158. if (res.data.length > 0) {
  159. this.productList = res.data
  160. this.selectItem = res.data[0]
  161. // this.getCategoryTwo(res.data[0].id)
  162. this.getGoodsList(res.data[0].id);
  163. }
  164. })
  165. },
  166. getGoodsList(cid) {
  167. this.goodsList = [];
  168. getGoodsList({
  169. goodsCategoryId: cid,
  170. current: 1,
  171. size: 5
  172. }).then(res => {
  173. this.goodsList = res.data;
  174. })
  175. console.log(this.goodsList)
  176. },
  177. getCategoryTwo (id) {
  178. getCategoryTwo({
  179. parentId: id
  180. }).then(res => {
  181. this.productList2 = res.data
  182. this.productList2.forEach(e => {
  183. e.selected = false
  184. })
  185. })
  186. },
  187. getNav () {
  188. // uni.request({
  189. // url:'api/mock/navigation',
  190. // success:res=>{
  191. // this.newData = res.data
  192. // if (this.newData.status && this.newData.status.status) {
  193. // uni.hideTabBar()
  194. // } else {
  195. // uni.showTabBar()
  196. // }
  197. // }
  198. // })
  199. // getNavigation().then(res => {
  200. // this.newData = res
  201. // if (this.newData.status && this.newData.status.status) {
  202. // uni.hideTabBar()
  203. // } else {
  204. // uni.showTabBar()
  205. // }
  206. // })
  207. },
  208. goRouter (item) {
  209. var pages = getCurrentPages();
  210. var page = (pages[pages.length - 1]).$page.fullPath;
  211. if (item.link == page) return
  212. uni.switchTab({
  213. url: item.link,
  214. fail (err) {
  215. uni.redirectTo({
  216. url: item.link
  217. })
  218. }
  219. })
  220. },
  221. footHeight (data) {
  222. this.footH = data
  223. },
  224. infoScroll: function () {
  225. let that = this;
  226. let len = that.productList.length;
  227. this.number = that.productList[len - 1].children.length;
  228. //设置商品列表高度
  229. uni.getSystemInfo({
  230. success: function (res) {
  231. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  232. },
  233. });
  234. let height = 0;
  235. let hightArr = [];
  236. for (let i = 0; i < len; i++) {
  237. //获取元素所在位置
  238. let query = uni.createSelectorQuery().in(this);
  239. let idView = "#b" + i;
  240. query.select(idView).boundingClientRect();
  241. query.exec(function (res) {
  242. let top = res[0].top;
  243. hightArr.push(top);
  244. that.hightArr = hightArr
  245. });
  246. };
  247. },
  248. tap: function (item, index, id) {
  249. this.selectItem = item
  250. this.getGoodsList(item.id)
  251. this.toView = id;
  252. this.navActive = index;
  253. this.$set(this, 'lock', true);
  254. },
  255. getAllCategory: function () {
  256. let that = this;
  257. uni.request({
  258. url: 'api/mock/getCategoryList',
  259. success: res => {
  260. that.productList = res.data;
  261. that.$nextTick(res => {
  262. that.infoScroll();
  263. })
  264. }
  265. })
  266. // getCategoryList().then(res => {
  267. // that.productList = res.data;
  268. // that.$nextTick(res => {
  269. // that.infoScroll();
  270. // })
  271. // })
  272. },
  273. scroll: function (e) {
  274. let scrollTop = e.detail.scrollTop;
  275. let scrollArr = this.hightArr;
  276. if (this.lock) {
  277. this.$set(this, 'lock', false);
  278. return;
  279. }
  280. for (let i = 0; i < scrollArr.length; i++) {
  281. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  282. this.navActive = 0
  283. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  284. 0]) {
  285. this.navActive = i
  286. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  287. this.navActive = scrollArr.length - 1
  288. }
  289. }
  290. },
  291. searchSubmitValue: function (e) {
  292. if (this.$util.trim(e.detail.value).length > 0)
  293. uni.navigateTo({
  294. url: '/pages/goods/goods_list/index?searchValue=' + e.detail.value
  295. })
  296. else
  297. return this.$util.Tips({
  298. title: this.$t(`搜索商品名称`)
  299. });
  300. },
  301. }
  302. }
  303. </script>
  304. <style>
  305. page {
  306. height: 100%;
  307. }
  308. </style>
  309. <style scoped lang="scss">
  310. /deep/uni-scroll-view {
  311. padding-bottom: 0 !important;
  312. }
  313. .sys-title {
  314. z-index: 10;
  315. position: relative;
  316. height: 40px;
  317. line-height: 40px;
  318. font-size: 30rpx;
  319. color: #333;
  320. background-color: #fff;
  321. // #ifdef APP-PLUS
  322. text-align: center;
  323. // #endif
  324. // #ifdef MP
  325. text-align: left;
  326. padding-left: 30rpx;
  327. // #endif
  328. }
  329. .sys-head {
  330. background-color: #fff;
  331. }
  332. .productSort {
  333. display: flex;
  334. flex-direction: column;
  335. height: 80vh
  336. }
  337. .productSort .header {
  338. width: 100%;
  339. height: 96rpx;
  340. background-color: #fff;
  341. border-bottom: 1rpx solid #f5f5f5;
  342. }
  343. .productSort .header .input {
  344. width: 700rpx;
  345. height: 60rpx;
  346. background-color: #f5f5f5;
  347. border-radius: 50rpx;
  348. box-sizing: border-box;
  349. padding: 0 25rpx;
  350. }
  351. .productSort .header .input .iconfont {
  352. font-size: 35rpx;
  353. color: #555;
  354. }
  355. .productSort .header .input .placeholder {
  356. color: #999;
  357. }
  358. .productSort .header .input input {
  359. font-size: 26rpx;
  360. height: 100%;
  361. width: 597rpx;
  362. }
  363. .productSort .scroll-box {
  364. flex: 1;
  365. overflow: hidden;
  366. display: flex;
  367. }
  368. // #ifndef MP
  369. uni-scroll-view {
  370. padding-bottom: 100rpx;
  371. }
  372. // #endif
  373. .productSort .aside {
  374. width: 180rpx;
  375. height: 100%;
  376. overflow: hidden;
  377. background-color: #f7f7f7;
  378. }
  379. .productSort .aside .item {
  380. height: 100rpx;
  381. width: 100%;
  382. font-size: 26rpx;
  383. color: #424242;
  384. text-align: center;
  385. }
  386. .productSort .aside .item.on {
  387. background-color: #fff;
  388. border-left: 4rpx solid var(--view-theme);
  389. width: 100%;
  390. color: var(--view-theme);
  391. font-weight: bold;
  392. }
  393. .productSort .conter {
  394. flex: 1;
  395. height: 100%;
  396. overflow: hidden;
  397. padding: 0 14rpx;
  398. background-color: #fff;
  399. position: relative;
  400. }
  401. .productSort .conter .listw {
  402. padding-top: 20rpx;
  403. }
  404. .productSort .conter .listw .title {
  405. height: 90rpx;
  406. }
  407. .productSort .conter .listw .title .line {
  408. width: 100rpx;
  409. height: 2rpx;
  410. background-color: #f0f0f0;
  411. }
  412. .productSort .conter .listw .title .name {
  413. font-size: 28rpx;
  414. color: #333;
  415. margin: 0 30rpx;
  416. font-weight: bold;
  417. }
  418. .productSort .conter .list {
  419. flex-wrap: wrap;
  420. }
  421. .productSort .conter .list .item {
  422. width: 177rpx;
  423. margin-top: 26rpx;
  424. }
  425. .productSort .conter .list .item .picture {
  426. width: 120rpx;
  427. height: 120rpx;
  428. border-radius: 50%;
  429. }
  430. .productSort .conter .list .item .picture image {
  431. width: 100%;
  432. height: 100%;
  433. border-radius: 50%;
  434. }
  435. .productSort .conter .list .item .name {
  436. font-size: 24rpx;
  437. color: #333;
  438. height: 56rpx;
  439. line-height: 56rpx;
  440. width: 120rpx;
  441. text-align: center;
  442. }
  443. .page-footer {
  444. position: fixed;
  445. bottom: 0;
  446. z-index: 30;
  447. display: flex;
  448. align-items: center;
  449. justify-content: space-around;
  450. width: 100%;
  451. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  452. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  453. box-sizing: border-box;
  454. border-top: solid 1rpx #F3F3F3;
  455. background-color: #fff;
  456. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  457. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  458. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  459. .foot-item {
  460. display: flex;
  461. width: max-content;
  462. align-items: center;
  463. justify-content: center;
  464. flex-direction: column;
  465. position: relative;
  466. .count-num {
  467. position: absolute;
  468. display: flex;
  469. justify-content: center;
  470. align-items: center;
  471. width: 40rpx;
  472. height: 40rpx;
  473. top: 0rpx;
  474. right: -15rpx;
  475. color: #fff;
  476. font-size: 20rpx;
  477. background-color: #FD502F;
  478. border-radius: 50%;
  479. padding: 4rpx;
  480. }
  481. }
  482. .foot-item image {
  483. height: 50rpx;
  484. width: 50rpx;
  485. text-align: center;
  486. margin: 0 auto;
  487. }
  488. .foot-item .txt {
  489. font-size: 24rpx;
  490. &.active {}
  491. }
  492. .fixed-image {
  493. position: fixed !important;
  494. width: 74%;
  495. }
  496. }
  497. .acea-row {
  498. display: flex;
  499. flex-direction: column;
  500. /* 已选择 */
  501. .selde {
  502. border: 1px solid red;
  503. background: red;
  504. color: #FFFFFF;
  505. border-radius: 20upx;
  506. display: flex;
  507. flex-direction: row;
  508. justify-content: center;
  509. align-items: center;
  510. font-size: 20upx;
  511. padding: 0 10upx;
  512. }
  513. .selde-q {
  514. width: 18upx;
  515. height: 18upx;
  516. border-radius: 50%;
  517. background: #FFFFFF;
  518. margin-left: 6upx;
  519. }
  520. /* 未选择 */
  521. .noselde {
  522. border: 1px solid #959595;
  523. background: #FFFFFF;
  524. color: #959595;
  525. border-radius: 20upx;
  526. display: flex;
  527. flex-direction: row;
  528. justify-content: center;
  529. align-items: center;
  530. font-size: 20upx;
  531. padding: 0 10upx;
  532. }
  533. .noselde-q {
  534. border: 1px solid #959595;
  535. width: 16upx;
  536. height: 16upx;
  537. border-radius: 50%;
  538. background: #FFFFFF;
  539. margin-left: 6upx;
  540. }
  541. .acea-row-item {
  542. display: flex;
  543. width: 100% !important;
  544. flex-direction: row;
  545. .picture {}
  546. .p-r {
  547. flex-direction: column;
  548. width: 100%;
  549. display: flex;
  550. justify-content: space-between;
  551. .name {}
  552. .acea-row-item-bArea {
  553. display: flex;
  554. justify-content: space-between;
  555. }
  556. }
  557. }
  558. }
  559. .all-products-body {
  560. background: white;
  561. .all-products-item {
  562. display: flex;
  563. margin-bottom: 20rpx;
  564. image {
  565. margin: auto;
  566. width: 128rpx;
  567. height: 128rpx;
  568. margin-right: 20rpx;
  569. border: 2rpx solid #FFFFFF;
  570. }
  571. .all-products-item-content {
  572. display: flex;
  573. flex-direction: column;
  574. width: calc(100% - 128rpx);
  575. .all-products-item-content-t {
  576. flex: 1;
  577. font-size: 24rpx;
  578. font-weight: 400;
  579. margin-right: 30rpx;
  580. color: #333333;
  581. line-height: 40rpx;
  582. }
  583. .all-products-item-content-b {
  584. flex: 1;
  585. font-size: 28rpx;
  586. font-weight: 500;
  587. line-height: 80rpx;
  588. display: flex;
  589. justify-content: space-between;
  590. image {
  591. margin: 0;
  592. width: 36rpx;
  593. height: 36rpx;
  594. }
  595. .red {
  596. display: block;
  597. font-size: 28rpx;
  598. font-weight: 500;
  599. color: #B22338 !important;
  600. margin-right: 10rpx;
  601. }
  602. .line-thr {
  603. display: block;
  604. font-size: 28rpx;
  605. font-weight: 400;
  606. color: #999999;
  607. text-decoration: line-through;
  608. }
  609. .count {
  610. font-size: 24rpx;
  611. font-weight: 400;
  612. color: #999999;
  613. margin-right: 30rpx;
  614. }
  615. }
  616. }
  617. }
  618. }
  619. </style>