quickBuy.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <uni-popup ref="randomPop" type="bottom" class="randomPop">
  3. <view class="popup-content">
  4. <view class="product">
  5. <view class="product-img-wrap">
  6. <image :src="pData.product.pic" class="product-img" mode="widthFix"></image>
  7. </view>
  8. <view class="product-info">
  9. <view class="product-info-name">
  10. {{pData.product.name}}
  11. </view>
  12. <view class="product-info-price-wrap">
  13. ¥<text class="product-info-price">{{pData.product.price}}</text>
  14. <text class="product-info-unit" v-if="pData.product.unit">/{{pData.product.unit}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="nums">
  19. <view class="nums-til">数量</view>
  20. <view class="countNum">
  21. <view class="countNum-action reduce" @click="calcValue('reduce',total)">-</view>
  22. <view class="countNum-input">
  23. <input class="uni-input" v-model="total" type="number" @blur="onInput(total)"/>
  24. </view>
  25. <view class="countNum-action add" @click="calcValue('add',total)">+</view>
  26. </view>
  27. </view>
  28. <view class="buy-btn" @click="submit">立即购买</view>
  29. </view>
  30. </uni-popup>
  31. </template>
  32. <script>
  33. // import { mapMutations } from 'vuex';
  34. import { debounce } from '@/utils/util.js'
  35. // import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
  36. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  37. import { bus } from '../../../utils/bus.js';
  38. export default{
  39. name:'quickBuy',
  40. components:{
  41. uniPopup,
  42. },
  43. created(){
  44. console.log(this.pData);
  45. },
  46. props:{
  47. visible: {
  48. type: Boolean,
  49. default: false
  50. },
  51. pData: {
  52. type: Object,
  53. default: []
  54. }
  55. },
  56. data(){
  57. return{
  58. loading:false,
  59. loadStatus:'loading',
  60. min:1,
  61. total:1,
  62. }
  63. },
  64. methods:{
  65. openPop(){
  66. this.$refs.randomPop.open();
  67. },
  68. closePop(){
  69. Object.assign(this.$data, this.$options.data.call(this))
  70. this.$refs.randomPop.close()
  71. this.$emit('closeModal',true)
  72. },
  73. onInput(total){
  74. console.log(this.total)
  75. if(!(/(^[1-9]\d*$)/.test(this.total))){
  76. this.total = 1
  77. if(this.total < this.min){
  78. this.total = 1
  79. }
  80. }
  81. },
  82. //数量计算
  83. calcValue(type,total){
  84. if (type === "reduce") {
  85. this.total--
  86. if (total <= this.min) {
  87. this.total = 1
  88. }
  89. } else if (type === "add") {
  90. this.total++;
  91. }
  92. },
  93. submit(){
  94. this.$emit('closeModal',true)
  95. bus.$emit('toDetailPage', {
  96. data: {
  97. productId:this.pData.product.id,
  98. bayNum:this.total,
  99. productName:this.pData.product.name,
  100. productPrice:this.pData.product.price,
  101. productImg:this.pData.product.pic,
  102. productUnit:this.pData.product.unit,
  103. }
  104. });
  105. uni.navigateTo({
  106. url: '/pages/confirmorder/confirmorder',
  107. });
  108. }
  109. },
  110. }
  111. </script>
  112. <style scoped>
  113. @import url("./quickBuy.css");
  114. </style>