km-business-area-picker.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <km-list-selector :options="listData" v-bind="$attrs" :read-only="readOnly" v-on="$listeners" />
  3. </template>
  4. <script>
  5. import findAncestorComponent from '@/common/services/find-ancestor-component'
  6. import PageService from '@/common/services/page-service'
  7. import components from './_import-components/km-business-area-picker-import'
  8. const processArrayInStr = {
  9. getDisplayValue(arr) {
  10. return arr.map((v) => v.name).join(', ')
  11. },
  12. parseBackendValue: (v) => JSON.parse(v),
  13. toBackendValue: (v) => JSON.stringify(v),
  14. }
  15. export default {
  16. name: 'KmBusinessAreaPicker',
  17. components,
  18. model: {
  19. prop: 'value',
  20. event: 'change',
  21. },
  22. props: {
  23. /**
  24. * 只读
  25. */
  26. readOnly: {
  27. required: true,
  28. type: Boolean,
  29. default: false,
  30. },
  31. },
  32. data() {
  33. return { listData: [] }
  34. },
  35. created() {
  36. // 只读模式不调接口
  37. if (!this.readOnly) {
  38. this.getData()
  39. }
  40. // 自动处理 parseBackendValue 等
  41. const item =
  42. findAncestorComponent(this, 'SdFormItemInner') ||
  43. findAncestorComponent(this, 'SdFormItemTdInput')
  44. if (!item || Array.isArray(item.name)) return
  45. this.SdFormContext.fieldOptions[item.name] = {
  46. ...this.SdFormContext.fieldOptions[item.name],
  47. ...processArrayInStr,
  48. dataType: 'array',
  49. }
  50. this.SdFormContext.fieldOptions = { ...this.SdFormContext.fieldOptions }
  51. this.SdFormContext.parseBackendValue(item.name)
  52. },
  53. inject: {
  54. SdFormContext: { default: () => ({}) },
  55. },
  56. methods: {
  57. // 获取业务领域接口
  58. getData() {
  59. const params = {
  60. columns: 'id,name',
  61. expressions: [],
  62. formId: 'kmDomain',
  63. maxResults: -1,
  64. startPosition: 0,
  65. }
  66. PageService.getList(params).then((res) => {
  67. this.listData = res.data.data
  68. })
  69. },
  70. },
  71. }
  72. </script>
  73. <style module lang="scss">
  74. @use '@/common/design' as *;
  75. </style>