regularPurchase.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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.mainImage" 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. import { shoppingAddCart } from "@/api/cart.js"
  41. export default{
  42. components:{
  43. productList
  44. },
  45. data(){
  46. return{
  47. userID: '',
  48. serverUrl: '',
  49. emptyText: '',
  50. lastPageType: '',
  51. lastPageVal: '',
  52. isIphoneX:this.$store.state.isIphoneX,
  53. specClass: '',//规格弹窗css类,控制开关动画
  54. handleData:{},
  55. isQuantity:false,
  56. isStock:false,
  57. minBuyNumber:0,
  58. number:0,
  59. buyRetailPrice:0,
  60. buyRetailPriceStep:1,
  61. }
  62. },
  63. onLoad() {
  64. },
  65. methods:{
  66. hanldOperationConfim(data){//显示选择数量确认弹窗
  67. this.specClass = 'show'
  68. this.handleData = data
  69. this.minBuyNumber = data.minBuyNumber
  70. this.buyRetailPrice = data.retailPrice
  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. 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.$refs.productList.cartQuantity = response.data
  151. }).catch(error =>{
  152. this.$util.msg(error.msg,2000);
  153. })
  154. },
  155. discard(){
  156. //丢弃
  157. }
  158. },
  159. onShow() {
  160. let pages = getCurrentPages(),thisPage = pages[pages.length - 1];
  161. this.$api.getStorage().then((resolve) =>{
  162. this.userID = resolve.userID
  163. })
  164. },
  165. }
  166. </script>
  167. <style lang="scss">
  168. page {
  169. background: $sub-bg-color;
  170. .all-type-list-wrapper {
  171. display: flex;
  172. flex-direction: column;
  173. }
  174. }
  175. /* 加入购物模态层*/
  176. @keyframes showPopup {
  177. 0% {
  178. opacity: 0;
  179. }
  180. 100% {
  181. opacity: 1;
  182. }
  183. }
  184. @keyframes hidePopup {
  185. 0% {
  186. opacity: 1;
  187. }
  188. 100% {
  189. opacity: 0;
  190. }
  191. }
  192. @keyframes showLayer {
  193. 0% {
  194. transform: translateY(0);
  195. }
  196. 100% {
  197. transform: translateY(-100%);
  198. }
  199. }
  200. @keyframes hideLayer {
  201. 0% {
  202. transform: translateY(-100%);
  203. }
  204. 100% {
  205. transform: translateY(0);
  206. }
  207. }
  208. @keyframes showAmnation {
  209. 0% {
  210. top: -12rpx;
  211. opacity: 0;
  212. }
  213. 50% {
  214. top: -60rpx;
  215. opacity: 1;
  216. }
  217. 100% {
  218. top: -100rpx;
  219. opacity: 0;
  220. }
  221. }
  222. @keyframes hideAmnation {
  223. 0% {
  224. top: -100rpx;
  225. opacity: 0;
  226. }
  227. 100% {
  228. top: -12rpx;
  229. opacity: 0;
  230. }
  231. }
  232. .popup {
  233. position: fixed;
  234. top: 0;
  235. width: 100%;
  236. height: 100%;
  237. z-index: 999;
  238. display: none;
  239. .mask{
  240. position: fixed;
  241. top: 0;
  242. width: 100%;
  243. height: 100%;
  244. z-index: 21;
  245. background-color: rgba(0, 0, 0, 0.6);
  246. }
  247. .layer {
  248. position: fixed;
  249. z-index: 22;
  250. bottom: -294rpx;
  251. width: 702rpx;
  252. padding: 24rpx 24rpx 36rpx 24rpx;
  253. height: 236rpx;
  254. border-radius: 30rpx 30rpx 0 0;
  255. background-color: #fff;
  256. display: flex;
  257. flex-wrap: wrap;
  258. align-content: space-between;
  259. .content {
  260. width: 100%;
  261. }
  262. .btn {
  263. width: 100%;
  264. height: 88rpx;
  265. display: flex;
  266. .button {
  267. width: 340rpx;
  268. height: 88rpx;
  269. color: #fff;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. font-size: $font-size-28;
  274. border-radius: 14rpx;
  275. &.buy{
  276. background: $btn-confirm;
  277. }
  278. &.add{
  279. background: rgba(239, 175, 0, 1);
  280. margin-left: 20rpx;
  281. }
  282. }
  283. }
  284. }
  285. &.show {
  286. display: block;
  287. .mask{
  288. animation: showPopup 0.2s linear both;
  289. }
  290. .layer {
  291. animation: showLayer 0.2s linear both;
  292. }
  293. }
  294. &.hide {
  295. display: block;
  296. .mask{
  297. animation: hidePopup 0.2s linear both;
  298. }
  299. .layer {
  300. animation: hideLayer 0.2s linear both;
  301. }
  302. }
  303. &.none {
  304. display: none;
  305. }
  306. &.service {
  307. .row {
  308. margin: 30upx 0;
  309. .title {
  310. font-size: 30upx;
  311. margin: 10upx 0;
  312. }
  313. .description {
  314. font-size: 28upx;
  315. color: #999;
  316. }
  317. }
  318. }
  319. .layer-smimg{
  320. width: 114rpx;
  321. height: 114rpx;
  322. float: left;
  323. border-radius: 10rpx;
  324. margin-right: 24rpx;
  325. image{
  326. width: 114rpx;
  327. height: 114rpx;
  328. border-radius: 10rpx;
  329. }
  330. }
  331. .layer-nunbox{
  332. justify-content: space-between;
  333. align-items: center;
  334. width: 536rpx;
  335. height: 88rpx;
  336. padding: 13rpx 0 0 0;
  337. float: left;
  338. .layer-nunbox-t{
  339. width: 100%;
  340. height:44rpx;
  341. position:relative;
  342. display: flex;
  343. .layer-nunbox-text{
  344. line-height: 44rpx;
  345. font-size: $font-size-28;
  346. }
  347. .number-box{
  348. display: flex;
  349. justify-content: center;
  350. align-items: center;
  351. .iconfont{
  352. font-size: $font-size-32;
  353. padding:0 20rpx;
  354. font-size: $text-color;
  355. }
  356. .btn-input{
  357. width: 62rpx;
  358. height: 48rpx;
  359. line-height: 48rpx;
  360. background: #F8F8F8;
  361. border-radius: 4rpx;
  362. text-align: center;
  363. font-size: $font-size-28;
  364. }
  365. }
  366. .product-step{
  367. position: absolute;
  368. left: 45rpx;
  369. bottom: 0;
  370. height: 44rpx;
  371. background: #FFFFFF;
  372. }
  373. }
  374. .layer-nunbox-b{
  375. width: 100%;
  376. height:44rpx;
  377. margin-top: 13rpx;
  378. }
  379. .text{
  380. line-height: 44rpx;
  381. font-size: $font-size-28;
  382. .p{
  383. color: #FF2A2A;
  384. }
  385. .p:first-child{
  386. margin-left: 30rpx;
  387. }
  388. .p.sm{
  389. font-size: $font-size-24;
  390. }
  391. }
  392. }
  393. }
  394. </style>