buyagain.vue 8.4 KB

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