regularPurchase.vue 9.1 KB

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