audit-project-select.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div style="width:100%">
  3. <a-select v-model="project" style="width:100%" mode="multiple" @change="projectChange">
  4. <a-select-option v-for="(item, i) in optionsData" :key="i" :value="item[field.key]">{{
  5. item[field.name]
  6. }}</a-select-option>
  7. <a-select-option key="2" value="2">被审计单位</a-select-option>
  8. </a-select>
  9. </div>
  10. </template>
  11. <script>
  12. import components from './_import-components/audit-project-select-import'
  13. export default {
  14. name: 'AuditProjectSelect',
  15. metaInfo: {
  16. title: 'AuditProjectSelect',
  17. },
  18. components,
  19. model: {
  20. prop: 'value',
  21. event: 'change',
  22. },
  23. props: {
  24. value: {
  25. type: Array,
  26. default: () => [],
  27. },
  28. options: {
  29. type: Array,
  30. default: () => [],
  31. },
  32. field: {
  33. type: Object,
  34. default: () => ({
  35. key: 'id',
  36. name: 'name',
  37. }),
  38. },
  39. },
  40. data() {
  41. return {
  42. project: ['allOptionKey'],
  43. optionsData: [],
  44. initObj: {},
  45. }
  46. },
  47. watch: {
  48. options(val) {
  49. if (this.options.length) {
  50. this.optionsData = [this.initObj, ...this.options]
  51. }
  52. },
  53. },
  54. mounted() {
  55. this.initObj[this.field.key] = 'allOptionKey'
  56. this.initObj[this.field.name] = '全部项目'
  57. },
  58. methods: {
  59. projectChange(value) {
  60. // 如果是value最后一位则清除其他选项否则取消全部选项
  61. if (value[value.length - 1] === 'allOptionKey') {
  62. this.project = ['allOptionKey']
  63. this.$emit(
  64. 'change',
  65. this.options.map((item) => item[this.field.key])
  66. )
  67. } else {
  68. this.project = value.filter((item) => item !== 'allOptionKey')
  69. this.$emit('change', this.project)
  70. }
  71. },
  72. },
  73. }
  74. </script>
  75. <style module lang="scss">
  76. @use '@/common/design' as *;
  77. </style>