regularPurchase.vue 8.3 KB

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