regularPurchase.vue 9.3 KB

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