regularPurchase.vue 8.2 KB

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