UpdateNotifyTime.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('iam.modify_notify_time') }}</div>
  4. <div slot="body">
  5. <!-- <a-alert class="mb-2" :message="$t('bill.rateset_create_tip')" /> -->
  6. <dialog-selected-tips :count="params.data.length" :name="$t('iam.message_subscription')" :action="$t('iam.modify_notify_time')" />
  7. <dialog-table v-if="params.columns && params.columns.length" :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form-model
  9. ref="form"
  10. v-bind="formItemLayout"
  11. :model="form"
  12. :rules="rules">
  13. <a-form-model-item prop="advance_days" class="mb-3">
  14. <div class="d-flex align-items-cneter" v-for="(item,index) in form.advance_days" :key="index">
  15. <span class="mr-5">{{$t('iam.notify_time') + (index + 1)}}:</span>
  16. <span>{{$t('iam.before_expiration')}}<a-input-number v-model="form.advance_days[index]" class="ml-2 mr-2" :min="1" :step="1" :precision="0" @change="validateForm" />{{$t('iam.day')}}</span>
  17. <a-button v-if="form.advance_days.length > 1" style="margin-left:10px;transform:translateY(8px)" shape="circle" icon="minus" size="small" @click="deleteDay(index)" />
  18. </div>
  19. </a-form-model-item>
  20. <a-button type="link" @click="addDay"><a-icon type="plus" style="padding: 0" /> {{$t('iam.add_notify_time')}}</a-button>
  21. </a-form-model>
  22. </div>
  23. <div slot="footer">
  24. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  25. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  26. </div>
  27. </base-dialog>
  28. </template>
  29. <script>
  30. import DialogMixin from '@/mixins/dialog'
  31. import WindowsMixin from '@/mixins/windows'
  32. import { validateModelForm } from '@/utils/validate'
  33. export default {
  34. name: 'NotifyTopicUpdateTimeDialog',
  35. mixins: [DialogMixin, WindowsMixin],
  36. data () {
  37. const { advance_days = [1] } = this.params.data[0]
  38. return {
  39. loading: false,
  40. form: {
  41. advance_days,
  42. },
  43. rules: {
  44. advance_days: { required: true, validator: this.validatorDays },
  45. },
  46. formItemLayout: {
  47. wrapperCol: {
  48. span: 20,
  49. },
  50. labelCol: {
  51. span: 4,
  52. },
  53. },
  54. }
  55. },
  56. created () {
  57. },
  58. methods: {
  59. validatorDays (rule, value, callback) {
  60. const left = Array.from(new Set(value))
  61. if (left.length !== value.length) {
  62. callback(new Error(this.$t('iam.notify_time_not_repeat')))
  63. }
  64. callback()
  65. },
  66. addDay () {
  67. this.form.advance_days.push(this.form.advance_days[this.form.advance_days.length - 1] + 1)
  68. },
  69. deleteDay (idx) {
  70. this.form.advance_days = this.form.advance_days.filter((item, index) => index !== idx)
  71. },
  72. async doUpdate () {
  73. return this.params.onManager('update', {
  74. id: this.params.data[0].id,
  75. managerArgs: {
  76. data: this.form,
  77. },
  78. })
  79. },
  80. validateForm () {
  81. validateModelForm(this.$refs.form)
  82. },
  83. async handleConfirm () {
  84. this.loading = true
  85. try {
  86. await validateModelForm(this.$refs.form)
  87. this.loading = true
  88. await this.doUpdate()
  89. this.loading = false
  90. // this.params.refresh()
  91. this.cancelDialog()
  92. } catch (error) {
  93. this.loading = false
  94. }
  95. },
  96. },
  97. }
  98. </script>