ReRunBill.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.action.update_credential')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.cloudaccount')" :count="params.data.length" :action="$t('cloudenv.action.update_credential')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form class="mt-3" :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('cloudenv.text_212')">
  9. <span slot="extra">
  10. <span>{{$t('cloudenv.text_213')}}</span>
  11. </span>
  12. <a-form-item style="display:inline-block">
  13. <a-month-picker :disabled-date="dateDisabledStart" v-decorator="decorators.start_day" @change="startChange" />
  14. </a-form-item>
  15. <span class="ml-2 mr-2">~</span>
  16. <a-form-item style="display:inline-block">
  17. <a-month-picker :disabled-date="dateDisabledEnd" v-decorator="decorators.end_day" />
  18. </a-form-item>
  19. </a-form-item>
  20. </a-form>
  21. </div>
  22. <div slot="footer">
  23. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  24. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  25. </div>
  26. </base-dialog>
  27. </template>
  28. <script>
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. export default {
  32. name: 'CloudaccountRerunBillDialog',
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. form: {
  37. fc: this.$form.createForm(this, {
  38. onValuesChange: (props, values) => {
  39. Object.keys(values).forEach((key) => {
  40. this.form.fd[key] = values[key]
  41. })
  42. },
  43. }),
  44. fd: {
  45. start_day: this.$moment().startOf('month').subtract('month', 1),
  46. end_day: this.$moment().subtract('month', 1),
  47. },
  48. },
  49. decorators: {
  50. start_day: ['start_day', {
  51. initialValue: this.$moment().startOf('month').subtract('month', 1),
  52. rules: [{ required: true, message: this.$t('common.tips.select', [this.$t('bill.text_40')]) }],
  53. }],
  54. end_day: ['end_day', {
  55. initialValue: this.$moment().subtract('month', 1),
  56. rules: [{ required: true, message: this.$t('common.tips.select', [this.$t('bill.text_41')]) }],
  57. }],
  58. },
  59. formItemLayout: {
  60. wrapperCol: {
  61. span: 20,
  62. },
  63. labelCol: {
  64. span: 4,
  65. },
  66. },
  67. }
  68. },
  69. computed: {
  70. provider () {
  71. return this.params.provider
  72. },
  73. start () {
  74. return this.$moment(this.form.fd.start_day).format('YYYY-MM')
  75. },
  76. end () {
  77. return this.$moment(this.form.fd.end_day).format('YYYY-MM')
  78. },
  79. selectedMonths () {
  80. const list = []
  81. const start = this.$moment(this.start)
  82. const end = this.$moment(this.end)
  83. // eslint-disable-next-line
  84. while (end > start || start.format('M') === end.format('M')) {
  85. list.push(start.format('YYYYMM'))
  86. start.add(1, 'month')
  87. }
  88. return list
  89. },
  90. },
  91. watch: {
  92. },
  93. created () {
  94. },
  95. methods: {
  96. startChange (value) {
  97. const dateEnd = this.form.fc.getFieldValue('end_day')
  98. if (dateEnd && value > dateEnd) {
  99. this.form.fc.setFieldsValue({
  100. end_day: value,
  101. })
  102. }
  103. },
  104. dateDisabledStart (value) {
  105. // const dateEnd = this.form.fc.getFieldValue('end_day')
  106. // if (dateEnd && value > dateEnd) return true
  107. if (this.params.data.every(item => item.provider === 'extdb')) return false
  108. if (value > this.$moment()) return true
  109. return false
  110. },
  111. dateDisabledEnd (value) {
  112. const dateStart = this.form.fc.getFieldValue('start_day')
  113. if (dateStart && value < dateStart) return true
  114. if (this.params.data.every(item => item.provider === 'extdb')) return false
  115. if (value > this.$moment()) return true
  116. return false
  117. },
  118. async postBillTasks (ids, values) {
  119. const manager = new this.$Manager('billtasks/submit', 'v1')
  120. try {
  121. const { start_day, end_day } = values
  122. const data = {
  123. task_type: 'pull_bill',
  124. account_id: ids,
  125. start_day: this.$moment(start_day).startOf('month').format('YYYYMMDD'),
  126. end_day: this.$moment(end_day).endOf('month').format('YYYYMMDD'),
  127. }
  128. await manager.create({
  129. data,
  130. })
  131. } catch (err) {
  132. throw err
  133. }
  134. },
  135. async handleConfirm () {
  136. try {
  137. this.loading = false
  138. const values = await this.form.fc.validateFields()
  139. this.postBillTasks(this.params.data.map(item => item.id), values)
  140. this.loading = false
  141. this.$message.success(this.$t('common.success'))
  142. this.cancelDialog()
  143. } catch (err) {
  144. this.loading = false
  145. throw err
  146. }
  147. },
  148. },
  149. }
  150. </script>