regularPurchase.vue 8.3 KB

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