discountModal.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <u-mask class="discountModal" :show="isShow" :mask-click-able="false">
  3. <view class="discount-con">
  4. <view class="discount-main">
  5. <view class="text-c">请输入折扣金额</view>
  6. <view class="discount-price text-c">
  7. <u-input class="price" v-model="formValidate.discountAmount" @input="numberToFixed('discountAmount',2,999999)" @focus="amountFocus" placeholder="请输入折扣金额" :clearable="false" type="digit" style="display: inline-block;vertical-align: middle;" />元
  8. </view>
  9. </view>
  10. <view class="discount-footer">
  11. <view class="button-cancel" @click="isShow=false">取消</view>
  12. <view class="button-confirm" @click="handleConfirm">确定</view>
  13. </view>
  14. </view>
  15. </u-mask>
  16. </template>
  17. <script>
  18. import { numberToFixed } from '@/libs/tools'
  19. export default {
  20. props: {
  21. openModal: { // 弹框显示状态
  22. type: Boolean,
  23. default: false
  24. },
  25. infoData: {
  26. tyoe: Object,
  27. default: ()=>{
  28. return null
  29. }
  30. },
  31. amount: {
  32. type: [Number, String],
  33. default: ''
  34. }
  35. },
  36. data() {
  37. return {
  38. isShow: this.openModal, // 是否打开弹框
  39. discountAmount: '',
  40. formValidate: {
  41. discountAmount: 0
  42. }
  43. }
  44. },
  45. methods: {
  46. // 确认
  47. handleConfirm(){
  48. if(this.formValidate.discountAmount){
  49. this.$emit('confirm', this.formValidate.discountAmount)
  50. }else{
  51. this.toashMsg('请输入折扣金额')
  52. }
  53. },
  54. // 小数点后两位
  55. numberToFixed: function (key, num, max) {
  56. let val = this.formValidate[key]
  57. let ret = numberToFixed(val, num, max)
  58. this.$nextTick(() => {
  59. this.formValidate[key] = ret
  60. })
  61. },
  62. // 折扣金额 获取焦点
  63. amountFocus(){
  64. this.formValidate.discountAmount = this.formValidate.discountAmount == 0 ? '' : this.formValidate.discountAmount
  65. }
  66. },
  67. watch: {
  68. // 父页面传过来的弹框状态
  69. openModal (newValue, oldValue) {
  70. this.isShow = newValue
  71. },
  72. // 重定义的弹框状态
  73. isShow (newValue, oldValue) {
  74. if (!newValue) {
  75. this.$emit('close')
  76. this.formValidate.discountAmount = 0
  77. }else{
  78. this.formValidate.discountAmount = this.amount || ''
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .discountModal{
  86. width: 100%;
  87. height: 100%;
  88. .text-c{
  89. text-align: center;
  90. }
  91. .discount-con{
  92. width: 78%;
  93. margin: 55% auto 0;
  94. background-color: #fff;
  95. border-radius: 24upx;
  96. .discount-main{
  97. padding: 60upx 20upx 50upx;
  98. .discount-price{
  99. margin: 10upx 0;
  100. .price{
  101. border-bottom: 1upx solid #e4e7ed;
  102. }
  103. }
  104. }
  105. .discount-footer{
  106. font-size: 30upx;
  107. display: flex;
  108. justify-content: space-between;
  109. align-items: center;
  110. text-align: center;
  111. border-top: 1upx solid #E5E5E5;
  112. .button-cancel{
  113. color: #999;
  114. border-right: 1upx solid #E5E5E5;
  115. flex-grow: 1;
  116. padding: 20upx 0;
  117. }
  118. .button-confirm{
  119. color: #2A86F4;
  120. flex-grow: 1;
  121. padding: 20upx 0;
  122. }
  123. }
  124. }
  125. }
  126. </style>