discountModal.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. this.$emit('confirm', this.formValidate.discountAmount)
  49. },
  50. // 小数点后两位
  51. numberToFixed: function (key, num, max) {
  52. let val = this.formValidate[key]
  53. let ret = numberToFixed(val, num, max)
  54. this.$nextTick(() => {
  55. this.formValidate[key] = ret
  56. })
  57. },
  58. // 折扣金额 获取焦点
  59. amountFocus(){
  60. this.formValidate.discountAmount = this.formValidate.discountAmount == 0 ? '' : this.formValidate.discountAmount
  61. }
  62. },
  63. watch: {
  64. // 父页面传过来的弹框状态
  65. openModal (newValue, oldValue) {
  66. this.isShow = newValue
  67. },
  68. // 重定义的弹框状态
  69. isShow (newValue, oldValue) {
  70. if (!newValue) {
  71. this.$emit('close')
  72. this.formValidate.discountAmount = 0
  73. }else{
  74. this.formValidate.discountAmount = this.amount || ''
  75. }
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .discountModal{
  82. width: 100%;
  83. height: 100%;
  84. .text-c{
  85. text-align: center;
  86. }
  87. .discount-con{
  88. width: 78%;
  89. margin: 45% auto 0;
  90. background-color: #fff;
  91. border-radius: 24upx;
  92. .discount-main{
  93. padding: 20upx 20upx;
  94. .discount-price{
  95. margin: 10upx 0;
  96. .price{
  97. border-bottom: 1upx solid #e4e7ed;
  98. }
  99. }
  100. }
  101. .discount-footer{
  102. font-size: 30upx;
  103. display: flex;
  104. justify-content: space-between;
  105. align-items: center;
  106. text-align: center;
  107. border-top: 1upx solid #E5E5E5;
  108. .button-cancel{
  109. color: #999;
  110. border-right: 1upx solid #E5E5E5;
  111. flex-grow: 1;
  112. padding: 20upx 0;
  113. }
  114. .button-confirm{
  115. color: #2A86F4;
  116. flex-grow: 1;
  117. padding: 20upx 0;
  118. }
  119. }
  120. }
  121. }
  122. </style>