Update.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_141', [$t('system.text_317')])}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="$t('system.text_142')" :name="$t('system.text_317')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 5)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('system.text_131')">
  11. <mobile-input v-decorator="decorators.international_mobile" />
  12. </a-form-item>
  13. <a-form-item :label="$t('system.text_132')">
  14. <a-input v-decorator="decorators.email" />
  15. </a-form-item>
  16. <a-form-item>
  17. <span slot="label">
  18. {{ $t('common_599') }}
  19. <a-tooltip effect="dark" placement="top">
  20. <a-icon type="info-circle" />
  21. <div slot="title">{{$t('system.contact')}}</div>
  22. </a-tooltip>
  23. </span>
  24. <a-checkbox-group
  25. v-decorator="decorators.enabled_contact_types">
  26. <a-checkbox
  27. v-for="(v, index) in contactArrOpts"
  28. :key="index"
  29. :value="v.value"
  30. :disabled="v.disabled">
  31. {{ v.label }}
  32. </a-checkbox>
  33. </a-checkbox-group>
  34. </a-form-item>
  35. </a-form>
  36. </div>
  37. <div slot="footer">
  38. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  39. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  40. </div>
  41. </base-dialog>
  42. </template>
  43. <script>
  44. import { contactMap } from '@/constants'
  45. import DialogMixin from '@/mixins/dialog'
  46. import WindowsMixin from '@/mixins/windows'
  47. import MobileInput from '@/sections/MobileInput'
  48. import { findAndUnshift } from '@/utils/utils'
  49. export default {
  50. name: 'ContactUpdateDialog',
  51. components: { MobileInput },
  52. mixins: [DialogMixin, WindowsMixin],
  53. data () {
  54. return {
  55. loading: false,
  56. form: {
  57. fc: this.$form.createForm(this),
  58. },
  59. contactArrOpts: [],
  60. decorators: {
  61. international_mobile: [
  62. 'international_mobile',
  63. {
  64. initialValue: { mobile: '', area_code: '86' },
  65. rules: [
  66. {
  67. type: 'object',
  68. required: true,
  69. },
  70. { validator: this.checkInternationalMobile },
  71. ],
  72. },
  73. ],
  74. email: [
  75. 'email',
  76. {
  77. rules: [
  78. {
  79. required: true,
  80. message: this.$t('system.text_139'),
  81. whitespace: true,
  82. },
  83. {
  84. validator: this.$validate('email'),
  85. message: this.$t('system.text_140'),
  86. whitespace: true,
  87. },
  88. ],
  89. },
  90. ],
  91. enabled_contact_types: [
  92. 'enabled_contact_types',
  93. {
  94. initialValue: [],
  95. },
  96. ],
  97. },
  98. formItemLayout: { // 兼容英文版
  99. wrapperCol: {
  100. span: 18,
  101. },
  102. labelCol: {
  103. span: 6,
  104. },
  105. },
  106. }
  107. },
  108. destroyed () {
  109. this.manager = null
  110. },
  111. created () {
  112. const domain_id = this.params.data[0]?.domain_id
  113. this.manager = new this.$Manager('receivers', 'v1')
  114. this.generateContactArrOpts({ domain_ids: [domain_id] })
  115. },
  116. mounted () {
  117. this.$nextTick(() => {
  118. const { international_mobile, email, enabled_contact_types } = this.params.data[0]
  119. this.form.fc.setFieldsValue({
  120. international_mobile,
  121. email,
  122. enabled_contact_types,
  123. })
  124. })
  125. },
  126. methods: {
  127. async handleConfirm () {
  128. this.loading = true
  129. try {
  130. const values = await this.form.fc.validateFields()
  131. const { domain, email, international_mobile, enabled_contact_types } = values
  132. const data = {
  133. email,
  134. domain,
  135. international_mobile,
  136. enabled_contact_types,
  137. force_verified: true,
  138. }
  139. await this.manager.update({
  140. id: this.params.data[0].id,
  141. data,
  142. })
  143. this.loading = false
  144. this.params.success()
  145. this.cancelDialog()
  146. } catch (error) {
  147. this.loading = false
  148. throw error
  149. }
  150. },
  151. async generateContactArrOpts (params) {
  152. let config_contact_types = []
  153. try {
  154. config_contact_types = await this.fetchConfig(params)
  155. } catch (error) {
  156. throw error
  157. }
  158. const contactArrOpts = config_contact_types.filter((item) => {
  159. return !item.includes('robot')
  160. }).map((item) => {
  161. return {
  162. label: contactMap[item].label || item,
  163. value: item,
  164. disabled: item === 'webconsole',
  165. }
  166. })
  167. this.contactArrOpts = contactArrOpts
  168. },
  169. fetchConfig (params) {
  170. return new Promise((resolve, reject) => {
  171. new this.$Manager('receivers', 'v1').performClassAction({ action: 'get-types', data: params }).then((res) => {
  172. const { types } = res.data
  173. const sortData = findAndUnshift(types, item => item === 'webconsole')
  174. resolve(sortData)
  175. }).catch((err) => {
  176. reject(err)
  177. })
  178. })
  179. },
  180. checkInternationalMobile (rule, value, callback) {
  181. if (!value.mobile) {
  182. callback(this.$t('system.text_138'))
  183. }
  184. if (!/^[0-9-]{6,14}$/.test(value.mobile)) {
  185. callback(this.$t('validator.phone'))
  186. }
  187. if (!value.area_code) {
  188. callback(this.$t('system.country_code'))
  189. }
  190. callback()
  191. },
  192. },
  193. }
  194. </script>