goods_cate.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template>
  2. <view class='productSort'>
  3. <!-- #ifdef APP-PLUS -->
  4. <!-- 状态栏占位 -->
  5. <view class="status_bar"></view>
  6. <!-- #endif -->
  7. <!-- 商品搜索 -->
  8. <view class='header acea-row row-center-wrapper' style="margin-top: var(--status-bar-height)">
  9. <view class='acea-row row-between-wrapper input'>
  10. <text class='iconfont icon-sousuo'></text>
  11. <input type='text' placeholder='点击搜索商品信息' @confirm="searchSubmitValue" confirm-type='search'
  12. name="search" placeholder-class='placeholder' />
  13. </view>
  14. </view>
  15. <!-- 商品分类(左) -->
  16. <view class='aside' :style="{bottom: tabbarH + 'px',height: height + 'rpx'}">
  17. <scroll-view scroll-y="true" scroll-with-animation='true' style="height: 100%;">
  18. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
  19. v-for="(item,index) in productList" :key="index" @click='tap(item.id,index,"b"+index)'>
  20. <text>{{item.name}}</text>
  21. </view>
  22. </scroll-view>
  23. </view>
  24. <!-- 商品分类(右) -->
  25. <view class='conter'>
  26. <scroll-view scroll-y="true" :style='"height:"+height+"rpx;margin-top: 96rpx;"'
  27. scroll-with-animation='true'>
  28. <view class='listw'>
  29. <view class='list acea-row'>
  30. <view class='list acea-row row-between-wrapper' :class='is_switch?"":"on"'>
  31. <view class='item' :class='is_switch?"":"on"' hover-class='none'
  32. v-for="(item,index) in goodsRightList" :key="index" @click="godDetail(item)">
  33. <view class='pictrue' :class='is_switch?"":"on"'>
  34. <image :src='item.picUrl' :class='is_switch?"":"on"'></image>
  35. </view>
  36. <view class='text' :class='is_switch?"":"on"'>
  37. <view class='name line1'>{{item.name}}</view>
  38. <view class='money font-color' :class='is_switch?"":"on"'> <text
  39. class='num'>¥{{ fen2yuan(item.price) }}</text>
  40. <view class="carnum num-dis row-left" v-if="item.selected_goods_num>0">
  41. <view class="item reduce"
  42. :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
  43. @click.stop="CartNumDes(item.id)">
  44. -
  45. </view>
  46. <view class='item num'>
  47. <input type="number" v-model="item.selected_goods_num"
  48. data-name="productSelect.cart_num"
  49. @input="bindCode(attr.productSelect.cart_num)" />
  50. </view>
  51. <view v-if="iSplus" class="item plus"
  52. :class="attr.productSelect.cart_num >= attr.productSelect.stock ? 'on' : ''"
  53. @click.stop="CartNumAdd(item.id)">
  54. +
  55. </view>
  56. <view v-else class='item plus' :class='(attr.productSelect.cart_num >= attr.productSelect.stock)
  57. || (attr.productSelect.cart_num >= attr.productSelect.limitCount)
  58. ? "on":""' @click.stop='CartNumAdd(item.id)'>+</view>
  59. </view>
  60. <view class="circle" v-else @click.stop="addGoods(item.skus[0].id,index)">+
  61. </view>
  62. </view>
  63. <view class='vip acea-row row-between-wrapper' :class='is_switch?"":"on"'>
  64. <view class='vip-money' v-if="item.vipPrice > 0">
  65. ¥{{ fen2yuan(item.price - item.vipPrice) }}
  66. <image src='../../static/images/vip.png'></image>
  67. </view>
  68. <view>已售 {{ item.salesCount || 0}} 库存{{item.stock}}</view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view :style='"height:"+(height-300)+"rpx;"' v-if="number < 15" />
  76. </scroll-view>
  77. </view>
  78. <!-- 购物车 -->
  79. <!-- <view class='footer acea-row row-between-wrapper' >
  80. <view class="zz" @click="hideShoppingCar"></view>
  81. <view class='money acea-row row-middle' @click="showShoppingCar">
  82. <view>费用:¥{{ fen2yuan(0) }}</view>
  83. <form @submit="subOrder" report-submit='true'>
  84. <button class='placeOrder bg-color' formType="submit">立即下单</button>
  85. </form>
  86. </view>
  87. </view> -->
  88. <!-- 购物车列表 -->
  89. <!-- :style="{display: showCar ? 'flex' : 'none'}" -->
  90. <view class="cart-box" v-if="goodsRightList.length>0">
  91. <orderAddcart ref='orderAddcart' @showMask='isShowMask' @cartList="handleCartList"></orderAddcart>
  92. </view>
  93. <view class="zz" @click="hideShoppingCar" v-if="showMask"></view>
  94. </view>
  95. </template>
  96. <script>
  97. import * as CategoryApi from '@/api/product/category.js';
  98. import * as ProductSpuApi from '@/api/product/spu.js';
  99. import * as Util from '@/utils/util.js';
  100. import {
  101. toLogin
  102. } from '@/libs/login.js';
  103. import * as TradeCartApi from '@/api/trade/cart.js';
  104. import {
  105. mapGetters
  106. } from "vuex";
  107. import {
  108. goShopDetail
  109. } from '@/libs/order.js'
  110. import orderAddcart from '@/components/order_addcart';
  111. export default {
  112. data() {
  113. return {
  114. navlist: [],
  115. productList: [], // 商品分类,树形结构
  116. navActive: 0,
  117. number: "",
  118. height: 0,
  119. hightArr: [],
  120. toView: "",
  121. tabbarH: 0,
  122. limit: 10,
  123. page: 1,
  124. goodsRightList: [],
  125. cartList:[],
  126. //显示购物车
  127. showCar: false,
  128. showMask:false,
  129. is_switch:false,
  130. }
  131. },
  132. components: {
  133. orderAddcart
  134. },
  135. computed: mapGetters(['isLogin']),
  136. onLoad(options) {
  137. this.getAllCategory();
  138. },
  139. methods: {
  140. infoScroll: function() {
  141. let len = this.productList.length;
  142. let child = this.productList[len - 1] && this.productList[len - 1].child ? this.productList[len - 1]
  143. .child : [];
  144. this.number = child ? child.length : 0;
  145. // 设置商品列表高度
  146. let that = this;
  147. uni.getSystemInfo({
  148. success: function(res) {
  149. that.height = (res.windowHeight) * (750 / res.windowWidth) - 98;
  150. },
  151. });
  152. let hightArr = [];
  153. // for (let i = 0; i < len; i++) {
  154. // // 获取元素所在位置
  155. // let query = uni.createSelectorQuery().in(this);
  156. // let idView = "#b" + i;
  157. // query.select(idView).boundingClientRect();
  158. // query.exec(function(res) {
  159. // let top = res[0].top;
  160. // hightArr.push(top);
  161. // that.hightArr = hightArr
  162. // });
  163. // }
  164. },
  165. handleCartList(data){
  166. console.log(data,'datadtaa',this.goodsRightList)
  167. this.cartList=data
  168. this.goodsRightList.forEach(goodsItem => {
  169. data.forEach(item => {
  170. if (goodsItem.id === item.spu.id) {
  171. // 找到了匹配的数据,将 selected_goods_num 赋值为 data 中的 count
  172. goodsItem.selected_goods_num = item.count;
  173. // 在这里可以对找到的数据进行其他操作
  174. console.log('Matched item:', goodsItem);
  175. }
  176. });
  177. });
  178. },
  179. isShowMask(){
  180. this.showMask=true
  181. },
  182. tap: function(itemId, index, id) {
  183. console.log('点击了', itemId, id, index)
  184. this.toView = id;
  185. this.navActive = index;
  186. this.getGoodsList(itemId)
  187. },
  188. getGoodsList(id) {
  189. ProductSpuApi.getSpuPage({
  190. categoryId: id,
  191. pageNo: this.page,
  192. pageSize: this.limit
  193. }).then(res => {
  194. console.log(res, 77788999)
  195. this.goodsRightList = res.data.list.map(item => {
  196. return {
  197. ...item,
  198. selected_goods_num: 0
  199. }
  200. })
  201. })
  202. },
  203. getAllCategory: function() {
  204. console.log('这里执行了')
  205. CategoryApi.getCategoryList().then(res => {
  206. this.productList = Util.handleTree(res.data);
  207. console.log(this.productList, 'this.productList')
  208. this.getGoodsList(this.productList[0].id)
  209. setTimeout(() => {
  210. this.infoScroll();
  211. }, 500)
  212. })
  213. },
  214. scroll: function(e) {
  215. let scrollTop = e.detail.scrollTop;
  216. let scrollArr = this.hightArr;
  217. for (let i = 0; i < scrollArr.length; i++) {
  218. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  219. this.navActive = 0
  220. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[
  221. 0]) {
  222. this.navActive = i
  223. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  224. this.navActive = scrollArr.length - 1
  225. }
  226. }
  227. },
  228. searchSubmitValue: function(e) {
  229. if (this.$util.trim(e.detail.value).length > 0) {
  230. uni.navigateTo({
  231. url: '/pages/goods_list/index?searchValue=' + e.detail.value
  232. })
  233. } else {
  234. return this.$util.Tips({
  235. title: '请填写要搜索的产品信息'
  236. });
  237. }
  238. },
  239. fen2yuan(price) {
  240. return Util.fen2yuan(price)
  241. },
  242. // 去详情页
  243. godDetail(item) {
  244. goShopDetail(item, this.uid).then(res => {
  245. uni.navigateTo({
  246. url: `/pages/goods_details/index?id=${item.id}`
  247. })
  248. })
  249. },
  250. addGoods(id, index) {
  251. // 未登录,需要跳转
  252. if (!this.isLogin) {
  253. toLogin();
  254. return;
  255. }
  256. // // 库存不足
  257. // let sku = this.attr.productSelect;
  258. // if (sku.stock === 0) {
  259. // return that.$util.Tips({
  260. // title: "产品库存不足,请选择其它"
  261. // });
  262. // }
  263. // 添加购物车
  264. TradeCartApi.addCart({
  265. count: 1,
  266. skuId: id,
  267. }).then(res => {
  268. console.log('我进拉了', index, this.goodsRightList, )
  269. console.log(this.goodsRightList[index].selected_goods_num, 888)
  270. // this.$set(this.goodsRightList[index],'selected_goods_num')
  271. this.goodsRightList[index].selected_goods_num++
  272. // // 关闭 attr 组件
  273. // this.attr.cartAttr = false;
  274. // 提示成功
  275. this.$util.Tips({
  276. title: "添加购物车成功",
  277. success: () => {
  278. this.$refs.orderAddcart.getCartList()
  279. }
  280. });
  281. }).catch(res => {
  282. this.$util.Tips({
  283. title: res
  284. });
  285. });
  286. },
  287. CartNumDes: function(id) {
  288. console.log('我减少了',id,this.cartList)
  289. const index = this.cartList.findIndex(item => item.spu.id === id);
  290. this.$refs.orderAddcart.subCart(index)
  291. },
  292. CartNumAdd: function(id) {
  293. console.log('我增加了',id,this.cartList)
  294. const index = this.cartList.findIndex(item => item.spu.id === id);
  295. this.$refs.orderAddcart.addCart(index)
  296. },
  297. //显示购物车
  298. showShoppingCar(){
  299. // if(this.goodsTotalNumber == 0){
  300. // return;
  301. // }
  302. // this.footHeight = '100%';
  303. this.showCar = true;
  304. // this.carGoodsScrollTop = 0;
  305. },
  306. //隐藏购物车
  307. hideShoppingCar(){
  308. // this.footHeight = '0';
  309. this.$refs.orderAddcart.showCartList = false;
  310. this.showMask=false
  311. },
  312. }
  313. }
  314. </script>
  315. <style scoped lang="scss">
  316. .cart-box{
  317. display: flex;
  318. justify-content: flex-start;
  319. flex-flow: column;
  320. background: #ffffff;
  321. position: absolute;
  322. bottom: 0;
  323. z-index: 8;
  324. max-height: 66%;
  325. padding-bottom: 48px;
  326. border-top-left-radius: 16px;
  327. border-top-right-radius: 16px;
  328. overflow: hidden;
  329. width: 100%;
  330. border: 1rpx solid red;
  331. }
  332. .zz{
  333. position: absolute;
  334. top: 0;
  335. left: 0;
  336. right: 0;
  337. bottom: 0;
  338. background-color: rgba(0,0,0,.7);
  339. z-index: 1;
  340. }
  341. .productSort .header {
  342. width: 100%;
  343. height: 96rpx;
  344. background-color: #fff;
  345. position: fixed;
  346. left: 0;
  347. right: 0;
  348. top: 0;
  349. z-index: 9;
  350. border-bottom: 1rpx solid #f5f5f5;
  351. }
  352. .productSort .header .input {
  353. width: 700rpx;
  354. height: 60rpx;
  355. background-color: #f5f5f5;
  356. border-radius: 50rpx;
  357. box-sizing: border-box;
  358. padding: 0 25rpx;
  359. }
  360. .productSort .header .input .iconfont {
  361. font-size: 26rpx;
  362. color: #555;
  363. }
  364. .productSort .header .input .placeholder {
  365. color: #999;
  366. }
  367. .productSort .header .input input {
  368. font-size: 26rpx;
  369. height: 100%;
  370. width: 597rpx;
  371. }
  372. .productSort .aside {
  373. position: fixed;
  374. width: 180rpx;
  375. left: 0;
  376. top: 0;
  377. background-color: #f7f7f7;
  378. overflow-y: scroll;
  379. overflow-x: hidden;
  380. height: auto;
  381. margin-top: 96rpx;
  382. }
  383. .productSort .aside .item {
  384. height: 100rpx;
  385. width: 100%;
  386. font-size: 26rpx;
  387. color: #424242;
  388. }
  389. .productSort .aside .item.on {
  390. background-color: #fff;
  391. border-left: 4rpx solid #fc4141;
  392. width: 100%;
  393. text-align: center;
  394. color: #fc4141;
  395. font-weight: bold;
  396. }
  397. .productSort .conter {
  398. margin: 96rpx 0 0 180rpx;
  399. padding: 0 14rpx;
  400. background-color: #fff;
  401. }
  402. .productSort .conter .listw {
  403. // padding-top: 20rpx;
  404. }
  405. .productSort .conter .listw .title {
  406. height: 90rpx;
  407. }
  408. .productSort .conter .listw .title .line {
  409. width: 100rpx;
  410. height: 2rpx;
  411. background-color: #f0f0f0;
  412. }
  413. .productSort .conter .listw .title .name {
  414. font-size: 28rpx;
  415. color: #333;
  416. margin: 0 30rpx;
  417. font-weight: bold;
  418. }
  419. .productSort .conter .list {
  420. flex-wrap: wrap;
  421. }
  422. .productSort .conter .list .item {
  423. // width: 177rpx;
  424. // margin-top: 26rpx;
  425. }
  426. .productSort .conter .list .item .picture {
  427. width: 120rpx;
  428. height: 120rpx;
  429. border-radius: 50%;
  430. }
  431. .productSort .conter .list .item .picture image {
  432. width: 100%;
  433. height: 100%;
  434. border-radius: 50%;
  435. div {
  436. background-color: #f7f7f7;
  437. }
  438. }
  439. .productSort .conter .list .item .name {
  440. font-size: 24rpx;
  441. color: #333;
  442. height: 56rpx;
  443. line-height: 56rpx;
  444. width: 120rpx;
  445. text-align: center;
  446. }
  447. .productSort .conter .listw .list {
  448. padding: 0 30rpx;
  449. }
  450. .productSort .conter .listw .list.on {
  451. border-radius: 14rpx;
  452. margin-top: 0 !important;
  453. background-color: #fff;
  454. padding: 40rpx 0 0 0;
  455. // margin: 20rpx 0;
  456. // background-color: #fff;
  457. }
  458. .productSort .conter .listw .list .item {
  459. // width: 335rpx;
  460. background-color: #fff;
  461. border-radius: 14rpx;
  462. margin-bottom: 20rpx;
  463. }
  464. .productSort .conter .listw .list .item.on {
  465. width: 100%;
  466. display: flex;
  467. padding: 0 0 50rpx 24rpx;
  468. margin: 0;
  469. border-radius: 14rpx;
  470. }
  471. .productSort .conter .listw .list .item .pictrue {
  472. position: relative;
  473. width: 100%;
  474. height: 335rpx;
  475. }
  476. .productSort .conter .listw .list .item .pictrue.on {
  477. width: 180rpx;
  478. height: 180rpx;
  479. }
  480. .productSort .conter .listw .list .item .pictrue image {
  481. width: 100%;
  482. height: 100%;
  483. border-radius: 20rpx 20rpx 0 0;
  484. }
  485. .productSort .conter .listw .list .item .pictrue image.on {
  486. border-radius: 6rpx;
  487. }
  488. .productSort .conter .listw .list .item .text {
  489. padding: 18rpx 20rpx;
  490. font-size: 30rpx;
  491. color: #222;
  492. }
  493. .productSort .conter .listw .list .item .text.on {
  494. // width: 456rpx;
  495. flex: 1;
  496. padding: 0 0 0 20rpx;
  497. }
  498. .productSort .conter .listw .list .item .text .money {
  499. width: 100%;
  500. font-size: 26rpx;
  501. font-weight: bold;
  502. margin-top: 8rpx;
  503. display: flex;
  504. align-items: center;
  505. justify-content: space-between;
  506. }
  507. .productSort .conter .listw .list .item .text .money.on {
  508. margin-top: 50rpx;
  509. }
  510. .productSort .conter .listw .list .item .text .money .num {
  511. font-size: 28rpx;
  512. }
  513. .productSort .conter .listw .list .item .text .money .carnum {
  514. // height: 54rpx;
  515. margin-top: 24rpx;
  516. display: flex;
  517. }
  518. .productSort .conter .listw .list .item .text .money .carnum view {
  519. // border: 1px solid #a4a4a4;
  520. // width: 84rpx;
  521. text-align: center;
  522. height: 100%;
  523. line-height: 54rpx;
  524. color: #282828;
  525. font-size: 45rpx;
  526. margin-left: 10rpx;
  527. }
  528. .productSort .conter .listw .list .item .text .money .carnum .reduce {
  529. border-right: 0;
  530. border-radius: 6rpx 0 0 6rpx;
  531. line-height: 48rpx;
  532. }
  533. .productSort .conter .listw .list .item .text .money .carnum .reduce.on {
  534. // border-color: #e3e3e3;
  535. color: #DEDEDE;
  536. font-size: 44rpx;
  537. }
  538. .productSort .conter .listw .list .item .text .money .carnum .plus {
  539. border-left: 0;
  540. border-radius: 0 6rpx 6rpx 0;
  541. line-height: 46rpx;
  542. }
  543. .productSort .conter .listw .list .item .text .money .carnum .plus.on {
  544. border-color: #e3e3e3;
  545. color: #dedede;
  546. }
  547. .productSort .conter .listw .list .item .text .money .carnum .num {
  548. background: rgba(242, 242, 242, 1);
  549. color: #282828;
  550. font-size: 28rpx;
  551. border-radius: 12rpx;
  552. line-height: 29px;
  553. height: 54rpx;
  554. input {
  555. display: -webkit-inline-box;
  556. }
  557. }
  558. .productSort .conter .listw .list .item .text .money .circle {
  559. width: 40rpx;
  560. height: 40rpx;
  561. background-color: #E93323;
  562. border-radius: 50%;
  563. display: flex;
  564. justify-content: center;
  565. // align-items: center;
  566. color: white;
  567. font-size: 14px;
  568. }
  569. .productSort .conter .listw .list .item .text .vip {
  570. font-size: 22rpx;
  571. color: #aaa;
  572. margin-top: 7rpx;
  573. }
  574. .productSort .conter .listw .list .item .text .vip.on {
  575. margin-top: 12rpx;
  576. }
  577. .productSort .conter .listw .list .item .text .vip .vip-money {
  578. font-size: 24rpx;
  579. color: #282828;
  580. font-weight: bold;
  581. }
  582. .productSort .conter .listw .list .item .text .vip .vip-money image {
  583. width: 46rpx;
  584. height: 21rpx;
  585. margin-left: 4rpx;
  586. }
  587. .footer {
  588. z-index: 9;
  589. width: 100%;
  590. // height: 100rpx;
  591. // background-color: red;
  592. height: 100rpx;
  593. color: #fff;
  594. background-color: #313131;
  595. border-radius: 49rpx;
  596. position: fixed;
  597. padding: 0 24rpx;
  598. box-sizing: border-box;
  599. border-top: 1rpx solid #eee;
  600. // border-bottom: 1px solid #EEEEEE;
  601. /* #ifdef H5 */
  602. bottom: 98rpx;
  603. /* #endif */
  604. /* #ifdef MP */
  605. bottom: 0;
  606. /* #endif */
  607. /* #ifndef MP */
  608. // bottom: 98rpx;
  609. // bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  610. // bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  611. /* #endif */
  612. }
  613. .footer .checkAll {
  614. font-size: 28rpx;
  615. color: #282828;
  616. margin-left: 14rpx;
  617. }
  618. .footer .money {
  619. font-size: 30rpx;
  620. color: #fff;
  621. width: 100%;
  622. display: flex;
  623. justify-content: space-between;
  624. }
  625. .footer .zz{
  626. position: absolute;
  627. top: 0;
  628. left: 0;
  629. right: 0;
  630. bottom: 0;
  631. background-color: rgba(0,0,0,.7);
  632. z-index: 1;
  633. }
  634. .footer .placeOrder {
  635. color: #fff;
  636. font-size: 30rpx;
  637. width: 226rpx;
  638. height: 70rpx;
  639. border-radius: 50rpx;
  640. text-align: center;
  641. line-height: 70rpx;
  642. margin-left: 22rpx;
  643. background-color: #EC3534;
  644. }
  645. .footer .button .bnt {
  646. font-size: 28rpx;
  647. color: #999;
  648. border-radius: 50rpx;
  649. border: 1px solid #999;
  650. width: 160rpx;
  651. height: 60rpx;
  652. text-align: center;
  653. line-height: 60rpx;
  654. }
  655. .footer .button form~form {
  656. margin-left: 17rpx;
  657. }
  658. </style>