buyagain.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <view class="container all-type-list-wrapper">
  3. <buyagain-list ref="productList"
  4. @operationConfim="hanldOperationConfim"
  5. @goCartPage="hanldToCartPage">
  6. </buyagain-list>
  7. <!--底部选择模态层弹窗组件 -->
  8. <view class="popup spec" :class="specClass" @touchmove.stop.prevent="discard" @tap="hideSpec">
  9. <!-- 遮罩层 -->
  10. <view class="mask"></view>
  11. <view class="layer" @tap.stop="discard" :style="{paddingBottom :isIphoneX ? '68rpx' : '36rpx',bottom:isIphoneX ?'-352rpx' : '-320rpx'}">
  12. <view class="content">
  13. <view class="layer-smimg">
  14. <image :src="handleData.mainImage" mode=""></image>
  15. </view>
  16. <view class="layer-nunbox">
  17. <view class="layer-nunbox-t">
  18. <view class="layer-nunbox-text">数量:</view>
  19. <view class="number-box">
  20. <view class="iconfont icon-jianhao" :class="[isQuantity==true?'disabled':'']" @click="changeCountSub()"></view>
  21. <input class="btn-input" type="number" v-model="number" maxlength='4' @blur="changeNumber($event)">
  22. <view class="iconfont icon-jiahao" :class="[isStock==true?'disabled':'']" @click="changeCountAdd()"></view>
  23. </view>
  24. </view>
  25. <view class="layer-nunbox-b">
  26. <view class="text">单价:
  27. <text class="p sm">¥</text>
  28. <text class="p bg">{{buyRetailPrice.toFixed(2)}}</text>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="btn">
  34. <view class="button add" @click="getAddProductCart">加入购物车</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import buyagainList from '@/components/cm-module/listTemplate/buyagainList'
  42. import { shoppingAddCart } from "@/api/cart.js"
  43. import { getSellerProductNum,shoppingCartAddCart } from "@/api/seller.js"
  44. export default{
  45. components:{
  46. buyagainList
  47. },
  48. data(){
  49. return{
  50. isIphoneX:this.$store.state.isIphoneX,
  51. clubID:'',//机构ID
  52. serviceProviderId:'',//协销ID
  53. serverUrl: '',
  54. emptyText: '',
  55. lastPageType: '',
  56. lastPageVal: '',
  57. specClass: '',//规格弹窗css类,控制开关动画
  58. handleData:{},
  59. isQuantity:false,
  60. isStock:false,
  61. minBuyNumber:0,
  62. number:0,
  63. buyRetailPrice:0,
  64. buyRetailPriceStep:1,
  65. }
  66. },
  67. onLoad() {
  68. },
  69. methods:{
  70. getClubProductNum(){
  71. getSellerProductNum({clubId:this.clubID,serviceProviderId:this.serviceProviderId}).then(response =>{
  72. this.$refs.productList.cartQuantity = response.data
  73. })
  74. },
  75. hanldOperationConfim(data){//显示选择数量确认弹窗
  76. console.log(data)
  77. this.specClass = 'show';
  78. this.handleData = data
  79. this.minBuyNumber = data.minBuyNumber
  80. this.buyRetailPrice = data.retailPrice;
  81. this.buyRetailPriceStep = data.step
  82. if(this.handleData.ladderPriceFlag == '1'){
  83. this.number = data.maxBuyNumber
  84. }else{
  85. this.number = data.minBuyNumber
  86. }
  87. },
  88. hideSpec() {//关闭选择数量确认弹窗
  89. this.specClass = 'hide';
  90. setTimeout(() => {
  91. this.specClass = 'none';
  92. }, 200);
  93. },
  94. changeCountAdd(){//popup弹窗数量增加按钮
  95. if(this.buyRetailPriceStep == 2){
  96. this.number += this.minBuyNumber
  97. }else{
  98. this.number++
  99. }
  100. this.calculatPerice()
  101. },
  102. changeCountSub(){//popup弹窗数量减按钮
  103. if(this.number<=this.minBuyNumber){
  104. this.number= this.minBuyNumber
  105. this.isQuantity =true
  106. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  107. return
  108. }else{
  109. if(this.buyRetailPriceStep == 2){
  110. this.number-=this.minBuyNumber
  111. }else{
  112. this.number--
  113. }
  114. this.calculatPerice()
  115. this.isQuantity =false
  116. }
  117. },
  118. changeNumber(e){
  119. let _value = e.detail.value;
  120. if(!this.$api.isNumber(_value)){
  121. this.number = this.minBuyNumber
  122. }else if(_value < this.minBuyNumber){
  123. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  124. this.number = this.minBuyNumber
  125. }else if( _value % this.minBuyNumber !=0 ){
  126. this.$util.msg(`购买量必须为起订量的整数倍`,2000);
  127. this.number = this.minBuyNumber
  128. }else{
  129. this.number = e.detail.value
  130. this.calculatPerice()
  131. }
  132. },
  133. calculatPerice(){//判断是否为阶梯价然后做计算价格处理
  134. if(this.handleData.ladderPriceFlag == '1'){
  135. this.handleData.ladderPriceList.forEach((item,index)=>{
  136. if(this.number>=item.buyNum){
  137. this.buyRetailPrice = item.buyPrice
  138. }
  139. })
  140. }else{
  141. this.buyRetailPrice = this.handleData.retailPrice;
  142. }
  143. },
  144. getAddProductCart(){//增加购物车成功和toast弹窗提示成功
  145. let params ={
  146. productId:this.handleData.productID,
  147. clubId:this.clubID,
  148. serviceProviderId:this.serviceProviderId,
  149. num:this.number
  150. }
  151. shoppingCartAddCart(params).then(response => {
  152. this.specClass = 'hide';
  153. this.$util.msg('加入购物车成功',1500,true,'success')
  154. this.getClubProductNum()
  155. setTimeout(() => {this.specClass = 'none'}, 200)
  156. }).catch(error =>{
  157. this.$util.msg(error.msg,2000);
  158. })
  159. },
  160. hanldToCartPage(){
  161. this.$api.navigateTo('/seller/pages/cart/cart')
  162. },
  163. discard(){
  164. //丢弃
  165. }
  166. },
  167. onShow() {
  168. this.$api.getComStorage('orderUserInfo').then((resolve) =>{
  169. this.clubID = resolve.clubID
  170. })
  171. this.$api.getStorage().then((resolve) =>{
  172. this.serviceProviderId = resolve.serviceProviderID
  173. this.getClubProductNum()
  174. })
  175. },
  176. }
  177. </script>
  178. <style lang="scss">
  179. page {
  180. background: $sub-bg-color;
  181. .all-type-list-wrapper {
  182. display: flex;
  183. flex-direction: column;
  184. }
  185. }
  186. /* 加入购物模态层*/
  187. @keyframes showPopup {
  188. 0% {
  189. opacity: 0;
  190. }
  191. 100% {
  192. opacity: 1;
  193. }
  194. }
  195. @keyframes hidePopup {
  196. 0% {
  197. opacity: 1;
  198. }
  199. 100% {
  200. opacity: 0;
  201. }
  202. }
  203. @keyframes showLayer {
  204. 0% {
  205. transform: translateY(0);
  206. }
  207. 100% {
  208. transform: translateY(-100%);
  209. }
  210. }
  211. @keyframes hideLayer {
  212. 0% {
  213. transform: translateY(-100%);
  214. }
  215. 100% {
  216. transform: translateY(0);
  217. }
  218. }
  219. @keyframes showAmnation {
  220. 0% {
  221. top: -12rpx;
  222. opacity: 0;
  223. }
  224. 50% {
  225. top: -60rpx;
  226. opacity: 1;
  227. }
  228. 100% {
  229. top: -100rpx;
  230. opacity: 0;
  231. }
  232. }
  233. @keyframes hideAmnation {
  234. 0% {
  235. top: -100rpx;
  236. opacity: 0;
  237. }
  238. 100% {
  239. top: -12rpx;
  240. opacity: 0;
  241. }
  242. }
  243. .popup {
  244. position: fixed;
  245. top: 0;
  246. width: 100%;
  247. height: 100%;
  248. z-index: 999;
  249. display: none;
  250. .mask{
  251. position: fixed;
  252. top: 0;
  253. width: 100%;
  254. height: 100%;
  255. z-index: 21;
  256. background-color: rgba(0, 0, 0, 0.6);
  257. }
  258. .layer {
  259. position: fixed;
  260. z-index: 22;
  261. bottom: -294rpx;
  262. width: 702rpx;
  263. padding: 24rpx 24rpx 36rpx 24rpx;
  264. height: 260rpx;
  265. border-radius: 20rpx 20rpx 0 0;
  266. background-color: #fff;
  267. display: flex;
  268. flex-wrap: wrap;
  269. align-content: space-between;
  270. .content {
  271. width: 100%;
  272. }
  273. .btn {
  274. width: 100%;
  275. height: 88rpx;
  276. display: flex;
  277. .button {
  278. width: 702rpx;
  279. height: 88rpx;
  280. color: #fff;
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. font-size: $font-size-28;
  285. border-radius: 14rpx;
  286. background: $btn-confirm;
  287. }
  288. }
  289. }
  290. &.show {
  291. display: block;
  292. .mask{
  293. animation: showPopup 0.2s linear both;
  294. }
  295. .layer {
  296. animation: showLayer 0.2s linear both;
  297. }
  298. }
  299. &.hide {
  300. display: block;
  301. .mask{
  302. animation: hidePopup 0.2s linear both;
  303. }
  304. .layer {
  305. animation: hideLayer 0.2s linear both;
  306. }
  307. }
  308. &.none {
  309. display: none;
  310. }
  311. &.service {
  312. .row {
  313. margin: 30upx 0;
  314. .title {
  315. font-size: 30upx;
  316. margin: 10upx 0;
  317. }
  318. .description {
  319. font-size: 28upx;
  320. color: #999;
  321. }
  322. }
  323. }
  324. .layer-smimg{
  325. width: 114rpx;
  326. height: 114rpx;
  327. float: left;
  328. border-radius: 10rpx;
  329. margin-right: 24rpx;
  330. image{
  331. width: 114rpx;
  332. height: 114rpx;
  333. border-radius: 10rpx;
  334. }
  335. }
  336. .layer-nunbox{
  337. justify-content: space-between;
  338. align-items: center;
  339. width: 536rpx;
  340. height: 88rpx;
  341. padding: 13rpx 0 0 0;
  342. float: left;
  343. .layer-nunbox-t{
  344. width: 100%;
  345. height:44rpx;
  346. position:relative;
  347. display: flex;
  348. .layer-nunbox-text{
  349. line-height: 44rpx;
  350. font-size: $font-size-28;
  351. }
  352. .number-box{
  353. display: flex;
  354. justify-content: center;
  355. align-items: center;
  356. .iconfont{
  357. font-size: $font-size-32;
  358. padding:0 20rpx;
  359. font-size: $text-color;
  360. }
  361. .btn-input{
  362. width: 62rpx;
  363. height: 48rpx;
  364. line-height: 48rpx;
  365. background: #F8F8F8;
  366. border-radius: 4rpx;
  367. text-align: center;
  368. font-size: $font-size-28;
  369. }
  370. }
  371. .product-step{
  372. position: absolute;
  373. left: 45rpx;
  374. bottom: 0;
  375. height: 44rpx;
  376. background: #FFFFFF;
  377. }
  378. }
  379. .layer-nunbox-b{
  380. width: 100%;
  381. height:44rpx;
  382. margin-top: 13rpx;
  383. }
  384. .text{
  385. line-height: 44rpx;
  386. font-size: $font-size-28;
  387. .p{
  388. color: #FF2A2A;
  389. }
  390. .p:first-child{
  391. margin-left: 30rpx;
  392. }
  393. .p.sm{
  394. font-size: $font-size-24;
  395. }
  396. }
  397. }
  398. }
  399. </style>