list.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. <!-- :style="{paddingBottom :isIphoneX ? '68rpx' : '36rpx',bottom:isIphoneX ?'-460rpx' : '-400rpx'}" -->
  9. <view class="layer" @tap.stop="discard">
  10. <view class="content">
  11. <view class="layer-smimg">
  12. <image :src="handleData.mainImage" mode=""></image>
  13. </view>
  14. <view class="layer-nunbox">
  15. <view class="layer-nunbox-b">
  16. <view class="text">
  17. <text class="p sm">¥</text>
  18. <text class="p bg">{{buyRetailPrice.toFixed(2)}}</text>
  19. </view>
  20. </view>
  21. <view class="layer-nunbox-t">
  22. <view class="layer-nunbox-text">数量:</view>
  23. <view class="number-box">
  24. <view class="iconfont icon-jianhao" :class="[isQuantity==true?'disabled':'']" @click="changeCountSub()"></view>
  25. <input class="btn-input" type="number" v-model="number" maxlength='4' @blur="changeNumber($event)">
  26. <view class="iconfont icon-jiahao" :class="[isStock==true?'disabled':'']" @click="changeCountAdd()"></view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="btn">
  32. <!-- <view class="button buy" @click="toConfirmation">立即购买</view> -->
  33. <view class="button add" @click="getAddProductCart">加入购物车</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import productList from '@/components/cm-module/listTemplate/productList'
  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. buyRetailPriceStep:1,
  61. }
  62. },
  63. onLoad() {
  64. },
  65. methods:{
  66. //显示选择数量确认弹窗
  67. hanldOperationConfim(data){
  68. this.specClass = 'show'
  69. this.handleData = data
  70. this.minBuyNumber = data.minBuyNumber
  71. this.buyRetailPrice = data.retailPrice
  72. this.buyRetailPriceStep = data.step
  73. if(this.handleData.ladderPriceFlag == '1'){
  74. this.number = data.maxBuyNumber
  75. }else{
  76. this.number = data.minBuyNumber
  77. }
  78. },
  79. //关闭选择数量确认弹窗
  80. hideSpec() {
  81. this.specClass = 'hide';
  82. setTimeout(() => {
  83. this.specClass = 'none';
  84. }, 200);
  85. },
  86. changeCountAdd(){//popup弹窗数量增加按钮
  87. if(this.buyRetailPriceStep == 2){
  88. this.number += this.minBuyNumber
  89. }else{
  90. this.number++
  91. }
  92. this.calculatPerice()
  93. },
  94. changeCountSub(){//popup弹窗数量减按钮
  95. if(this.number<=this.minBuyNumber){
  96. this.number= this.minBuyNumber
  97. this.isQuantity =true
  98. this.$util.msg(`该商品最小起订量为${this.minBuyNumber}`,2000);
  99. return
  100. }else{
  101. if(this.buyRetailPriceStep == 2){
  102. this.number-=this.minBuyNumber
  103. }else{
  104. this.number--
  105. }
  106. this.calculatPerice()
  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 if( _value % this.minBuyNumber !=0 ){
  118. this.$util.msg(`购买量必须为起订量的整数倍`,2000);
  119. this.number = this.minBuyNumber
  120. }else{
  121. this.number = e.detail.value
  122. this.calculatPerice()
  123. }
  124. },
  125. //判断是否为阶梯价然后做计算价格处理
  126. calculatPerice(){
  127. if(this.handleData.ladderPriceFlag == '1'){
  128. this.handleData.ladderPriceList.forEach((item,index)=>{
  129. if(this.number>=item.buyNum){
  130. this.buyRetailPrice = item.buyPrice
  131. }
  132. })
  133. }
  134. },
  135. //跳转确认订单页面
  136. toConfirmation(){
  137. this.specClass = 'hide';
  138. let productStp ={
  139. allPrice:this.number*this.buyRetailPrice,
  140. allCount:this.number,
  141. productID:this.handleData.productID,
  142. productCount:this.number
  143. }
  144. this.$api.navigateTo(`/pages/user/order/create-order?type=prodcut&data=${JSON.stringify({data:productStp})}`)
  145. setTimeout(() => {
  146. this.specClass = 'none';
  147. }, 200);
  148. },
  149. //增加购物车成功和toast弹窗提示成功
  150. getAddProductCart(){
  151. this.ProductService.shoppingAddCart({productID:this.handleData.productID,userID:this.userID,productCount:this.number}).then(response => {
  152. this.specClass = 'hide';
  153. this.$util.msg(response.msg,1500,true,'success')
  154. setTimeout(() => {this.specClass = 'none'}, 200)
  155. this.$refs.productList.cartQuantity = response.data
  156. }).catch(error =>{
  157. this.$util.msg(error.msg,2000);
  158. })
  159. },
  160. discard(){
  161. //丢弃
  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: -420rpx;
  250. width: 702rpx;
  251. padding: 24rpx 24rpx 36rpx 24rpx;
  252. height: 360rpx;
  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. margin-top: 40rpx;
  261. }
  262. .btn {
  263. width: 100%;
  264. height: 88rpx;
  265. display: flex;
  266. justify-content: center;
  267. .button {
  268. width: 600rpx;
  269. height: 90rpx;
  270. color: #fff;
  271. display: flex;
  272. align-items: center;
  273. justify-content: center;
  274. font-size: $font-size-28;
  275. border-radius: 45rpx;
  276. &.buy{
  277. background: $btn-confirm;
  278. }
  279. &.add{
  280. background: rgba(0, 0, 0, 1.0);
  281. }
  282. }
  283. }
  284. }
  285. &.show {
  286. display: block;
  287. .mask{
  288. animation: showPopup 0.2s linear both;
  289. }
  290. .layer {
  291. animation: showLayer 0.2s linear both;
  292. }
  293. }
  294. &.hide {
  295. display: block;
  296. .mask{
  297. animation: hidePopup 0.2s linear both;
  298. }
  299. .layer {
  300. animation: hideLayer 0.2s linear both;
  301. }
  302. }
  303. &.none {
  304. display: none;
  305. }
  306. &.service {
  307. .row {
  308. margin: 30upx 0;
  309. .title {
  310. font-size: 30upx;
  311. margin: 10upx 0;
  312. }
  313. .description {
  314. font-size: 28upx;
  315. color: #999;
  316. }
  317. }
  318. }
  319. .layer-smimg{
  320. border: 1px solid #eee;
  321. width: 136rpx;
  322. height: 136rpx;
  323. float: left;
  324. border-radius: 10rpx;
  325. margin-right: 24rpx;
  326. image{
  327. width: 136rpx;
  328. height: 136rpx;
  329. border-radius: 10rpx;
  330. }
  331. }
  332. .layer-nunbox{
  333. justify-content: space-between;
  334. align-items: center;
  335. width: 536rpx;
  336. height: 88rpx;
  337. padding: 13rpx 0 0 0;
  338. float: left;
  339. .layer-nunbox-t{
  340. width: 100%;
  341. height:44rpx;
  342. position:relative;
  343. display: flex;
  344. .layer-nunbox-text{
  345. line-height: 44rpx;
  346. font-size: $font-size-28;
  347. }
  348. .number-box{
  349. display: flex;
  350. justify-content: center;
  351. align-items: center;
  352. border: 2rpx solid #e1e1e1;
  353. border-radius: 30rpx;
  354. height: 48rpx;
  355. margin-left: 20rpx;
  356. .iconfont{
  357. font-size: $font-size-24;
  358. padding:0 18rpx;
  359. color: #333333;
  360. text-align: center;
  361. line-height: 48rpx;
  362. font-weight: bold;
  363. background: #FFFFFF;
  364. &.icon-jianhao{
  365. border-radius: 30rpx 0 0 30rpx;
  366. }
  367. &.icon-jiahao{
  368. border-radius: 0 30rpx 30rpx 0;
  369. }
  370. }
  371. .btn-input{
  372. width: 62rpx;
  373. height: 44rpx;
  374. line-height: 44rpx;
  375. border-radius: 4rpx;
  376. text-align: center;
  377. font-size: $font-size-24;
  378. border-bottom: 2rpx solid #e1e1e1;
  379. border-top: 2rpx solid #e1e1e1;
  380. color: #333333;
  381. background-color: #f7f7f7;
  382. }
  383. }
  384. .product-step{
  385. position: absolute;
  386. left: 45rpx;
  387. bottom: 0;
  388. height: 44rpx;
  389. background: #FFFFFF;
  390. }
  391. }
  392. .layer-nunbox-b{
  393. width: 100%;
  394. height:44rpx;
  395. padding: 8rpx 0 16rpx;
  396. .text{
  397. font-weight: bold;
  398. }
  399. }
  400. .text{
  401. line-height: 44rpx;
  402. font-size: $font-size-32;
  403. .p{
  404. color: #FF2A2A;
  405. }
  406. // .p:first-child{
  407. // margin-left: 30rpx;
  408. // }
  409. .p.sm{
  410. font-size: $font-size-24;
  411. }
  412. }
  413. }
  414. }
  415. </style>