list.vue 9.3 KB

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