List.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import * as R from 'ramda'
  11. import { mapGetters } from 'vuex'
  12. import { getProjectDomainFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  13. import WindowsMixin from '@/mixins/windows'
  14. import ListMixin from '@/mixins/list'
  15. import CommonMixin from '../mixins/common'
  16. import ColumnsMixin from '../mixins/columns'
  17. import SingleActionsMixin from '../mixins/singleActions'
  18. export default {
  19. name: 'ContactList',
  20. mixins: [CommonMixin, WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  21. props: {
  22. id: String,
  23. getParams: {
  24. type: Object,
  25. },
  26. },
  27. data () {
  28. return {
  29. list: this.$list.createList(this, {
  30. id: this.id,
  31. resource: 'receivers',
  32. apiVersion: 'v1',
  33. getParams: this.getParam,
  34. filterOptions: {
  35. name: {
  36. label: this.$t('system.text_126'),
  37. filter: true,
  38. formatter: val => {
  39. return `name.contains(${val})`
  40. },
  41. },
  42. project_domains: getProjectDomainFilter(),
  43. created_at: getCreatedAtFilter(),
  44. },
  45. }),
  46. exportDataOptions: {
  47. items: [
  48. { label: 'ID', key: 'id' },
  49. { label: this.$t('system.text_126'), key: 'name' },
  50. { label: this.$t('system.text_127'), key: 'created_at' },
  51. { label: this.$t('system.text_131'), key: 'mobile' },
  52. { label: this.$t('system.text_146'), key: 'email' },
  53. { label: this.$t('common_599'), key: 'enabled_contact_types' },
  54. ],
  55. },
  56. groupActions: [
  57. {
  58. label: this.$t('system.text_128'),
  59. permission: 'contacts_create',
  60. action: () => {
  61. this.createDialog('ContactCreateDialog', {
  62. success: () => {
  63. this.refresh()
  64. },
  65. })
  66. },
  67. meta: () => {
  68. return {
  69. buttonType: 'primary',
  70. }
  71. },
  72. },
  73. {
  74. label: this.$t('system.text_166'),
  75. actions: () => {
  76. return [
  77. {
  78. label: this.$t('system.management_notify_channels'),
  79. permission: 'contacts_update',
  80. action: () => {
  81. this.createDialog('SetupNotifyChannelsDialog', {
  82. data: this.list.selectedItems,
  83. columns: this.columns,
  84. success: () => {
  85. this.list.refresh()
  86. },
  87. onManager: this.onManager,
  88. })
  89. },
  90. meta: () => {
  91. const ret = {
  92. validate: true,
  93. tooltip: null,
  94. }
  95. const domain = this.list.selectedItems[0] ? this.list.selectedItems[0].domain_id : ''
  96. if (!this.list.selectedItems.every(item => { return item.domain_id === domain })) {
  97. ret.validate = false
  98. ret.tooltip = this.$t('system.management_notify_channels.domain.tips')
  99. return ret
  100. }
  101. return ret
  102. },
  103. },
  104. {
  105. label: this.$t('system.text_129'),
  106. permission: 'contacts_delete',
  107. action: (obj) => {
  108. this.createDialog('DeleteResDialog', {
  109. vm: this,
  110. data: this.list.selectedItems,
  111. columns: this.columns,
  112. title: this.$t('system.text_129'),
  113. name: this.$t('dictionary.receiver'),
  114. onManager: this.onManager,
  115. })
  116. },
  117. meta: () => this.$getDeleteResult(this.list.selectedItems),
  118. },
  119. ]
  120. },
  121. meta: () => {
  122. return {
  123. validate: !!this.list.selectedItems.length,
  124. }
  125. },
  126. },
  127. ],
  128. }
  129. },
  130. computed: {
  131. ...mapGetters(['userInfo']),
  132. },
  133. created () {
  134. this.list.fetchData()
  135. this.initSidePageTab('contact-detail')
  136. this.$bus.$on('ContactListSingleRefresh', id => {
  137. this.list.singleRefresh(id)
  138. }, this)
  139. },
  140. methods: {
  141. getParam () {
  142. const ret = {
  143. ...this.getParams,
  144. details: true,
  145. with_meta: true,
  146. }
  147. return ret
  148. },
  149. parseDetail (detail) {
  150. const ret = {
  151. enabled: true,
  152. email: {
  153. enabled: false,
  154. verified: false,
  155. contact: '',
  156. },
  157. mobile: {
  158. enabled: false,
  159. verified: false,
  160. contact: '',
  161. },
  162. }
  163. if (!R.is(String, detail)) return ret
  164. const arr = JSON.parse(detail)
  165. arr.forEach(item => {
  166. ret[item.contact_type] = item
  167. if (!item.enabled) {
  168. ret.enabled = false
  169. }
  170. })
  171. return ret
  172. },
  173. handleOpenSidepage (row) {
  174. this.sidePageTriggerHandle(this, 'ContactSidePage', {
  175. id: row.id,
  176. resource: 'receivers',
  177. apiVersion: 'v1',
  178. getParams: this.getParam,
  179. }, {
  180. list: this.list,
  181. })
  182. },
  183. },
  184. }
  185. </script>