regularPurchase.vue 8.5 KB

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