immediately.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <view class="container all-type-list-wrapper">
  3. <immediately-list ref="productList"
  4. :search-status="true"
  5. @operationConfim="hanldOperationConfim"
  6. @alertjietiConfim ="hanldalertjietiConfim"
  7. @goCartPage="hanldToCartPage"
  8. :tabBars="tabBars"
  9. :tabIndex="tabIndex"
  10. @changetab="hanldChangeTab"
  11. >
  12. </immediately-list>
  13. <!--底部选择模态层弹窗组件 -->
  14. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="discard" @tap="hideSpec" >
  15. <!-- 遮罩层 -->
  16. <view class="mask"></view>
  17. <view class="layer" @tap.stop="discard" :style="{paddingBottom :isIphoneX ? '68rpx' : '36rpx',bottom:isIphoneX ?'-370rpx' : '-360rpx'}">
  18. <view class="content">
  19. <view class="layer-smimg">
  20. <image :src="handleData.p_image" mode=""></image>
  21. </view>
  22. <view class="layer-nunbox">
  23. <view class="layer-nunbox-m" v-if="handleData.p_code!=''&& handleData.p_code!=null">商品编码:{{handleData.p_code}}</view>
  24. <view class="layer-nunbox-t">
  25. <view class="layer-nunbox-text">数量:</view>
  26. <view class="number-box">
  27. <view class="iconfont icon-jianhao" :class="[isQuantity==true?'disabled':'']" @click="changeCountSub()"></view>
  28. <input class="btn-input" type="number" v-model="number" maxlength='6' @blur="changeNumber($event)">
  29. <view class="iconfont icon-jiahao" :class="[isStock==true?'disabled':'']" @click="changeCountAdd()"></view>
  30. </view>
  31. </view>
  32. <view class="layer-nunbox-b">
  33. <view class="text">单价:
  34. <text class="p sm">¥</text>
  35. <text class="p bg">{{buyRetailPrice.toFixed(2)}}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="btn">
  41. <view class="button add" @click="getAddProductCart">加入购物车</view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 组合加入购物车 -->
  46. <view class="popup spec zuhe" :class="specClasszuhe" @touchmove.stop.prevent="discard" @tap="hideSpecs">
  47. <!-- 遮罩层 -->
  48. <view class="mask"></view>
  49. <view class="layer" @tap.stop="discard" :style="{paddingBottom :isIphoneX ? '68rpx' : '36rpx',bottom:isIphoneX ?'-290rpx' : '-270rpx'}">
  50. <view class="content zuhe-content">
  51. <view class="number-left">
  52. <text>种类:{{productKind}}</text>
  53. <text>数量:{{productTotalNum}}</text>
  54. </view>
  55. <view class="number-right">
  56. <view class="text">
  57. 总额:<text class="number-right-text">¥{{productTotalAmount.toFixed(2)}}</text>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="btn">
  62. <view class="button add" @click="getzuheCart">确定</view>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- -->
  67. <view class="popup spec zuhe" :class="specClassjieti" @touchmove.stop.prevent="discard" >
  68. <view class="mask"></view>
  69. <view class="jieti_box " @tap.stop="discard">
  70. <view class="jieti_box_one">
  71. <view class="jieti_left" >
  72. <view>起订量</view>
  73. <view class="ladder-a" v-for="(item,index) in ladderPriceList" :key="index">
  74. {{item.buyNumRangeShow}}
  75. </view>
  76. </view>
  77. <view class="jieti_right" >
  78. <view>价格</view>
  79. <view class="" v-for="(item,index) in ladderPriceList" :key="index">¥ {{item.buyPrice.toFixed(2)}}</view>
  80. </view>
  81. </view>
  82. <view class="addbtn" @tap="hideSpecjieti">知道了</view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import immediatelyList from '@/components/cm-module/listTemplate/immediatelyList'
  89. import { getSellerProductNum ,shoppingCartAddCart,getCartAddCart} from "@/api/seller.js"
  90. import { querySearchProductLadderPrice } from "@/api/product.js"
  91. export default{
  92. components:{
  93. immediatelyList
  94. },
  95. data(){
  96. return{
  97. clubID:'', //机构ID
  98. serviceProviderId:'',//协销ID
  99. serverUrl: '',
  100. emptyText: '',
  101. lastPageType: '',
  102. lastPageVal: '',
  103. isIphoneX:this.$store.state.isIphoneX,
  104. specClass: '',//规格弹窗css类,控制开关动画
  105. specClasszuhe:'',//组合加购物车弹窗
  106. specClassjieti:'',//阶梯展示弹窗
  107. ladderPriceList:{},
  108. handleData:{},
  109. isQuantity:false,
  110. isStock:false,
  111. minBuyNumber:0,
  112. number:0,
  113. buyRetailPrice:0,
  114. hanldChangeTabIndex:0,
  115. handleDataLadderPriceList:[],
  116. productKind:0,
  117. productTotalNum:0,
  118. productTotalAmount:0,
  119. buyNumRangeShow:'',//起订量范围
  120. buyPrice:'',//起订量范围价格
  121. buyRetailPriceStep:1,
  122. }
  123. },
  124. onLoad() {
  125. },
  126. methods:{
  127. getClubProductNum(){
  128. getSellerProductNum({clubId:this.clubID,serviceProviderId:this.serviceProviderId}).then(response =>{
  129. this.$refs.productList.cartQuantity = response.data
  130. })
  131. },
  132. hanldChangeTab(index){
  133. if(index == 1){
  134. this.$refs.productList.getcombinationProduct()
  135. }
  136. },
  137. hanldalertjietiConfim(data){
  138. this.ladderPriceList = data.ladderPriceList
  139. this.specClassjieti='show';
  140. },
  141. hanldOperationConfim(data){//显示选择数量确认弹窗
  142. this.handleData = data
  143. console.log(this.handleData)
  144. if(this.$refs.productList.tabIndex == 1){
  145. if(data.productKind ==0){
  146. this.$util.msg(`请至少选购一种商品`,2000);
  147. }else{
  148. this.specClasszuhe = 'show';
  149. this.productKind= data.productKind;
  150. this.productTotalNum = data.productTotalNum;
  151. this.productTotalAmount = data.productTotalAmount;
  152. }
  153. }else{
  154. this.number = data.minBuyNumber
  155. this.minBuyNumber = data.minBuyNumber
  156. this.buyRetailPrice = Number(data.price);
  157. this.buyRetailPriceStep = data.step
  158. this.specClass = 'show';
  159. if(this.handleData.ladderPriceFlag == '1'){
  160. querySearchProductLadderPrice({productId:this.handleData.p_id}).then(response=>{
  161. this.handleDataLadderPriceList = response.data
  162. this.handleDataLadderPriceList.forEach((item,index)=>{
  163. if(this.number>=item.buyNum){
  164. this.buyRetailPrice = item.buyPrice
  165. }
  166. })
  167. }).catch(error =>{
  168. console.log('获取阶梯价格异常')
  169. })
  170. }
  171. }
  172. },
  173. hideSpec() {//关闭选择数量确认弹窗
  174. this.specClass = 'hide';
  175. setTimeout(() => {
  176. this.specClass = 'none';
  177. }, 200);
  178. },
  179. hideSpecs(){
  180. this.specClasszuhe='hide';
  181. setTimeout(() => {
  182. this.specClasszuhe='none';
  183. }, 200);
  184. },
  185. hideSpecjieti(){
  186. this.specClassjieti='hide';
  187. setTimeout(() => {
  188. this.specClassjieti='none';
  189. }, 200);
  190. },
  191. changeCountAdd(){//popup弹窗数量增加按钮
  192. if(this.buyRetailPriceStep == 2){
  193. this.number += this.minBuyNumber
  194. }else{
  195. this.number++
  196. }
  197. this.calculatPerice()
  198. },
  199. changeCountSub(){//popup弹窗数量减按钮
  200. if(this.number<=this.minBuyNumber){
  201. this.number= this.minBuyNumber
  202. this.isQuantity =true
  203. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  204. return
  205. }else{
  206. if(this.buyRetailPriceStep == 2){
  207. this.number-=this.minBuyNumber
  208. }else{
  209. this.number--
  210. }
  211. this.calculatPerice()
  212. this.isQuantity =false
  213. }
  214. },
  215. changeNumber(e){
  216. let _value = e.detail.value;
  217. if(!this.$api.isNumber(_value)){
  218. this.number = this.minBuyNumber
  219. }else if(_value < this.minBuyNumber){
  220. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  221. this.number = this.minBuyNumber
  222. }else if( _value % this.minBuyNumber !=0 ){
  223. this.$util.msg(`购买量必须为起订量的整数倍`,2000);
  224. this.number = this.minBuyNumber
  225. }else{
  226. this.number = e.detail.value
  227. this.calculatPerice()
  228. }
  229. },
  230. calculatPerice(){//判断是否为阶梯价然后做计算价格处理
  231. if(this.handleData.ladderPriceFlag == '1'){
  232. this.handleDataLadderPriceList.forEach((item,index)=>{
  233. if(this.number>=item.buyNum){
  234. this.buyRetailPrice = item.buyPrice
  235. }
  236. })
  237. }else{
  238. this.buyRetailPrice = this.handleData.retailPrice;
  239. }
  240. },
  241. getzuheCart(){//组合商品加入购物车
  242. let productInfo=[];
  243. let setGoodsList ={};
  244. let productID = '';
  245. let productNum ='';
  246. this.handleData.combinationProductList.forEach(item =>{
  247. if(item.initProductNum >0){
  248. setGoodsList.productId = item.productID
  249. setGoodsList.productNum =item.initProductNum
  250. productInfo.push(JSON.parse(JSON.stringify(setGoodsList)))
  251. }
  252. })
  253. let params ={
  254. clubId:this.clubID,
  255. serviceProviderId:this.serviceProviderId,
  256. productInfo:productInfo
  257. }
  258. getCartAddCart({'params':JSON.stringify(params)}).then(response => {
  259. this.specClasszuhe = 'hide';
  260. this.$util.msg('加入购物车成功',1500,true,'success');
  261. this.getClubProductNum();
  262. this.clearProduct();//清空
  263. setTimeout(() => {this.specClasszuhe = 'none'}, 200)
  264. }).catch(error =>{
  265. this.$util.msg(error.msg,2000);
  266. })
  267. },
  268. clearProduct(){//成功加入购物车后清空所选值
  269. this.handleData.productKind= 0;
  270. this.handleData.productTotalNum = 0;
  271. this.handleData.productTotalAmount = 0;
  272. this.handleData.combinationProductList.forEach(item =>{
  273. item.initProductNum = 0;
  274. })
  275. },
  276. getAddProductCart(){//增加购物车成功和toast弹窗提示成功
  277. let params ={
  278. productId:this.handleData.p_id,
  279. clubId:this.clubID,
  280. serviceProviderId:this.serviceProviderId,
  281. num:this.number
  282. }
  283. shoppingCartAddCart(params).then(response => {
  284. this.specClass = 'hide';
  285. this.$util.msg('加入购物车成功',1500,true,'success')
  286. this.getClubProductNum();
  287. setTimeout(() => {this.specClass = 'none'}, 200)
  288. }).catch(error =>{
  289. this.$util.msg(error.msg,2000);
  290. })
  291. },
  292. hanldToCartPage(){
  293. this.$api.navigateTo('/seller/pages/cart/cart')
  294. },
  295. discard(){
  296. //丢弃
  297. }
  298. },
  299. onShow() {
  300. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  301. this.clubID = resolve.clubID
  302. })
  303. this.$api.getStorage().then((resolve) =>{
  304. this.serviceProviderId = resolve.serviceProviderID
  305. this.getClubProductNum()
  306. })
  307. },
  308. }
  309. </script>
  310. <style lang="scss">
  311. // 阶梯价格弹窗
  312. .jieti_box{
  313. width: 596rpx;
  314. // height: 496rpx;
  315. top: 10%;
  316. right: 50%;
  317. transform: translate(50%,50%);
  318. position: absolute;
  319. background:#FFFFFF;
  320. color: #000;
  321. font-size: 28rpx;
  322. border-radius: 10rpx;
  323. text-align: center;
  324. line-height: 84rpx;
  325. padding: 20rpx;
  326. z-index: 99999;
  327. }
  328. .jieti_box_one{
  329. // width: 548rpx;
  330. overflow: hidden;
  331. border: 2rpx solid #F5F5F5;
  332. border-bottom: 0;
  333. margin: auto;
  334. }
  335. .jieti_left{
  336. width: 298rpx;
  337. float: left;
  338. }
  339. .jieti_left view{
  340. height: 84rpx;
  341. border-bottom:2rpx solid #F5F5F5 ;
  342. border-right:2rpx solid #F5F5F5 ;
  343. }
  344. .ladder-a{
  345. letter-spacing: 4rpx;
  346. }
  347. .jieti_right{
  348. width: 294rpx;
  349. float: right;
  350. }
  351. .jieti_right view{
  352. height: 84rpx;
  353. border-bottom:2rpx solid #F5F5F5;
  354. }
  355. .addbtn{
  356. height: 84rpx;
  357. background: linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  358. text-align: center;
  359. font-size: 28rpx;
  360. color: #fff;
  361. line-height: 84rpx;
  362. border-radius: 10rpx;
  363. margin: 20rpx auto
  364. }
  365. .zuhe-content{
  366. display: inline-block;
  367. }
  368. .number-left{
  369. float: left;
  370. }
  371. .number-right{
  372. margin-left: 30rpx;
  373. float: left;
  374. }
  375. .number-left text{
  376. margin-left: 30rpx;
  377. }
  378. .number-right-text{
  379. color: #FF2A2A;
  380. }
  381. page {
  382. background: $sub-bg-color;
  383. .all-type-list-wrapper {
  384. display: flex;
  385. flex-direction: column;
  386. }
  387. }
  388. /* 加入购物模态层*/
  389. @keyframes showPopup {
  390. 0% {
  391. opacity: 0;
  392. }
  393. 100% {
  394. opacity: 1;
  395. }
  396. }
  397. @keyframes hidePopup {
  398. 0% {
  399. opacity: 1;
  400. }
  401. 100% {
  402. opacity: 0;
  403. }
  404. }
  405. @keyframes showLayer {
  406. 0% {
  407. transform: translateY(0);
  408. }
  409. 100% {
  410. transform: translateY(-100%);
  411. }
  412. }
  413. @keyframes hideLayer {
  414. 0% {
  415. transform: translateY(-100%);
  416. }
  417. 100% {
  418. transform: translateY(0);
  419. }
  420. }
  421. @keyframes showAmnation {
  422. 0% {
  423. top: -12rpx;
  424. opacity: 0;
  425. }
  426. 50% {
  427. top: -60rpx;
  428. opacity: 1;
  429. }
  430. 100% {
  431. top: -100rpx;
  432. opacity: 0;
  433. }
  434. }
  435. @keyframes hideAmnation {
  436. 0% {
  437. top: -100rpx;
  438. opacity: 0;
  439. }
  440. 100% {
  441. top: -12rpx;
  442. opacity: 0;
  443. }
  444. }
  445. .popup {
  446. position: fixed;
  447. top: 0;
  448. width: 100%;
  449. height: 100%;
  450. z-index: 999;
  451. display: none;
  452. .mask{
  453. position: fixed;
  454. top: 0;
  455. width: 100%;
  456. height: 100%;
  457. z-index: 21;
  458. background-color: rgba(0, 0, 0, 0.6);
  459. }
  460. .layer {
  461. position: fixed;
  462. z-index: 22;
  463. bottom: -360rpx;
  464. width: 702rpx;
  465. padding: 24rpx 24rpx 36rpx 24rpx;
  466. // height: 236rpx;
  467. border-radius: 20rpx 20rpx 0 0;
  468. background-color: #fff;
  469. display: flex;
  470. flex-wrap: wrap;
  471. align-content: space-between;
  472. .content {
  473. width: 100%;
  474. margin-top: 20rpx;
  475. }
  476. .btn {
  477. width: 100%;
  478. // height: 88rpx;
  479. display: flex;
  480. .button {
  481. width: 702rpx;
  482. height: 88rpx;
  483. color: #fff;
  484. display: flex;
  485. align-items: center;
  486. justify-content: center;
  487. font-size: $font-size-28;
  488. border-radius: 14rpx;
  489. background: $btn-confirm;
  490. margin-top: 20rpx;
  491. }
  492. }
  493. }
  494. .layer-nunbox-m{
  495. font-size: 28rpx;
  496. }
  497. &.show {
  498. display: block;
  499. .mask{
  500. animation: showPopup 0.2s linear both;
  501. }
  502. .layer {
  503. animation: showLayer 0.2s linear both;
  504. }
  505. }
  506. &.hide {
  507. display: block;
  508. .mask{
  509. animation: hidePopup 0.2s linear both;
  510. }
  511. .layer {
  512. animation: hideLayer 0.2s linear both;
  513. }
  514. }
  515. &.none {
  516. display: none;
  517. }
  518. &.service {
  519. .row {
  520. margin: 30upx 0;
  521. .title {
  522. font-size: 30upx;
  523. margin: 10upx 0;
  524. }
  525. .description {
  526. font-size: 28upx;
  527. color: #999;
  528. }
  529. }
  530. }
  531. .layer-smimg{
  532. width: 158rpx;
  533. height: 158rpx;
  534. float: left;
  535. border-radius: 10rpx;
  536. margin-right: 24rpx;
  537. image{
  538. width: 158rpx;
  539. height: 158rpx;
  540. border-radius: 10rpx;
  541. }
  542. }
  543. .layer-nunbox{
  544. justify-content: space-between;
  545. align-items: center;
  546. width: 510rpx;
  547. height: 88rpx;
  548. padding: 10rpx 0 0 0;
  549. float: left;
  550. .layer-nunbox-t{
  551. width: 100%;
  552. height:44rpx;
  553. position:relative;
  554. display: flex;
  555. margin-top: 10rpx;
  556. .layer-nunbox-text{
  557. line-height: 44rpx;
  558. font-size: $font-size-28;
  559. }
  560. .number-box{
  561. display: flex;
  562. justify-content: center;
  563. align-items: center;
  564. .iconfont{
  565. font-size: $font-size-32;
  566. padding:0 20rpx;
  567. font-size: $text-color;
  568. }
  569. .btn-input{
  570. width: 100rpx;
  571. height: 48rpx;
  572. line-height: 48rpx;
  573. background: #F8F8F8;
  574. border-radius: 4rpx;
  575. text-align: center;
  576. font-size: $font-size-28;
  577. }
  578. }
  579. .product-step{
  580. position: absolute;
  581. left: 45rpx;
  582. bottom: 0;
  583. height: 44rpx;
  584. background: #FFFFFF;
  585. }
  586. }
  587. .layer-nunbox-b{
  588. width: 100%;
  589. height:44rpx;
  590. margin-top: 13rpx;
  591. }
  592. .text{
  593. line-height: 44rpx;
  594. font-size: $font-size-28;
  595. .p{
  596. color: #FF2A2A;
  597. }
  598. .p:first-child{
  599. margin-left: 30rpx;
  600. }
  601. .p.sm{
  602. font-size: $font-size-24;
  603. }
  604. }
  605. }
  606. }
  607. .zuhe .layer{
  608. bottom: -270rpx;
  609. height: 200rpx;
  610. }
  611. </style>