SMS.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <a-form
  3. :form="form.fc"
  4. v-bind="formItemLayout">
  5. <a-form-item :label="$t('system.text_295')">
  6. <template v-slot:extra>
  7. <div>{{$t('system.text_296')}}</div>
  8. <div>{{$t('system.text_575')}}</div>
  9. <div>{{$t('system.text_298')}}</div>
  10. <div class="mb-0">{{$t('system.text_299')}}</div>
  11. </template>
  12. <a-input v-decorator="decorators.content" />
  13. </a-form-item>
  14. <a-form-item :wrapper-col="offsetWrapperCol">
  15. <a-button type="primary" @click="handleSubmit" :loading="submiting">{{ $t('common.ok') }}</a-button>
  16. </a-form-item>
  17. </a-form>
  18. </template>
  19. <script>
  20. import * as R from 'ramda'
  21. export default {
  22. name: 'EmailConfig',
  23. props: {
  24. formItemLayout: {
  25. required: true,
  26. type: Object,
  27. },
  28. offsetWrapperCol: {
  29. required: true,
  30. type: Object,
  31. },
  32. loading: Boolean,
  33. },
  34. data () {
  35. return {
  36. submiting: false,
  37. form: {
  38. fc: this.$form.createForm(this),
  39. },
  40. decorators: {
  41. content: [
  42. 'content',
  43. {
  44. rules: [
  45. { required: true, message: this.$t('system.text_300') },
  46. ],
  47. },
  48. ],
  49. },
  50. contactData: null,
  51. }
  52. },
  53. destroyed () {
  54. this.manager = null
  55. },
  56. created () {
  57. this.manager = new this.$Manager('notifytemplates', 'v1')
  58. this.fetchData()
  59. },
  60. methods: {
  61. async fetchData () {
  62. this.$emit('update:loading', true)
  63. try {
  64. const response = await this.manager.list({
  65. params: {
  66. topic: 'VERIFY',
  67. template_type: 'remote',
  68. contact_type: 'mobile',
  69. },
  70. })
  71. const data = response.data.data || []
  72. if (data.length > 0) {
  73. this.contactData = data[0]
  74. this.$nextTick(() => {
  75. this.form.fc.setFieldsValue({
  76. content: data[0].content,
  77. })
  78. })
  79. }
  80. } catch (error) {
  81. this.$message.error(this.$t('common_622', [this.$t('system.text_306')]))
  82. throw error
  83. } finally {
  84. this.$emit('update:loading', false)
  85. }
  86. },
  87. async handleSubmit () {
  88. const values = await this.form.fc.validateFields()
  89. try {
  90. this.submiting = true
  91. if (this.contactData && this.contactData.id) {
  92. await this.manager.update({
  93. id: this.contactData.id,
  94. data: {
  95. content: R.trim(values.content),
  96. },
  97. })
  98. } else {
  99. await this.manager.create({
  100. data: {
  101. contact_type: 'mobile',
  102. topic: 'VERIFY',
  103. template_type: 'remote',
  104. content: R.trim(values.content),
  105. example: '',
  106. },
  107. })
  108. }
  109. await this.fetchData()
  110. this.$message.success(this.$t('system.text_124', [this.$t('system.text_306')]))
  111. } catch (error) {
  112. this.$message.error(this.$t('common_622', [this.$t('system.text_306')]))
  113. throw error
  114. } finally {
  115. this.submiting = false
  116. }
  117. },
  118. },
  119. }
  120. </script>