goods_cate.vue 17 KB

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