regularPurchase.vue 9.4 KB

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