buyagain.vue 8.3 KB

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