buyagain.vue 9.1 KB

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