SetDiscount.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudaccount.table.action.set_discount')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('res.cloudaccount')" :count="params.data.length" :action="$t('cloudaccount.table.action.set_discount')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form-model
  8. ref="form"
  9. :model="fd"
  10. :rules="rules"
  11. v-bind="formItemLayout">
  12. <a-form-model-item :label="$t('cloudaccount.table.title.discount')" prop="discount" :extra="$t('cloudenv.text_571')">
  13. <a-input-number
  14. :value="fd.discount"
  15. :min="0"
  16. :max="100"
  17. :step="0.01"
  18. :precision="2"
  19. :formatter="value => `${value}%`"
  20. :parser="value => value.replace('%', '')"
  21. @change="discountChange" />
  22. </a-form-model-item>
  23. </a-form-model>
  24. </div>
  25. <div slot="footer">
  26. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  27. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  28. </div>
  29. </base-dialog>
  30. </template>
  31. <script>
  32. import DialogMixin from '@/mixins/dialog'
  33. import WindowsMixin from '@/mixins/windows'
  34. export default {
  35. name: 'CloudaccountSetDiscountDialog',
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. loading: false,
  40. discountLoaded: false,
  41. fd: {
  42. discount: 100,
  43. },
  44. rules: {
  45. discount: [
  46. { required: true, message: this.$t('cloudaccount.validate.discount') },
  47. ],
  48. },
  49. formItemLayout: {
  50. wrapperCol: {
  51. span: 21,
  52. },
  53. labelCol: {
  54. span: 3,
  55. },
  56. },
  57. }
  58. },
  59. created () {
  60. this.fetchDiscount()
  61. },
  62. methods: {
  63. discountChange (value) {
  64. this.fd.discount = value
  65. },
  66. async fetchDiscount () {
  67. try {
  68. const response = await this.$http({
  69. method: 'GET',
  70. url: `/v1/prices/discount/${this.params.data[0].id}`,
  71. })
  72. this.fd.discount = (response.data.discount * 100).toFixed(2)
  73. } finally {
  74. this.discountLoaded = true
  75. }
  76. },
  77. async handleConfirm () {
  78. this.loading = true
  79. try {
  80. await this.$refs.form.validate()
  81. await this.$http({
  82. method: 'PUT',
  83. url: `/v1/prices/discount/${this.params.data[0].id}`,
  84. data: {
  85. discount: this.fd.discount * 100 / 10000,
  86. },
  87. })
  88. this.cancelDialog()
  89. } finally {
  90. this.loading = false
  91. }
  92. },
  93. },
  94. }
  95. </script>