index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="jnpf-users-select w-full">
  3. <selectBox v-model="innerValue" :placeholder="placeholder" @openSelect="openSelect"
  4. :select-open="selectShow" :disabled="disabled" v-if="isInput" />
  5. <SelectPopup v-model="selectShow" :selectedData="selectedData" :hasSys="hasSys" @close="handleClose"
  6. @confirm="handleConfirm" />
  7. </view>
  8. </template>
  9. <script>
  10. import SelectPopup from './SelectPopup';
  11. import selectBox from '@/components/selectBox'
  12. import {
  13. getSelectedList
  14. } from '@/api/common'
  15. export default {
  16. name: 'jnpf-users-select',
  17. components: {
  18. SelectPopup,
  19. selectBox
  20. },
  21. props: {
  22. modelValue: {
  23. default: ''
  24. },
  25. isInput: {
  26. type: Boolean,
  27. default: true
  28. },
  29. placeholder: {
  30. type: String,
  31. default: '请选择'
  32. },
  33. disabled: {
  34. type: Boolean,
  35. default: false
  36. },
  37. hasSys: {
  38. type: Boolean,
  39. default: false
  40. },
  41. },
  42. data() {
  43. return {
  44. selectShow: false,
  45. innerValue: '',
  46. selectedData: [],
  47. multiple: true
  48. }
  49. },
  50. watch: {
  51. modelValue: {
  52. handler() {
  53. this.setDefault()
  54. },
  55. immediate: true
  56. },
  57. },
  58. methods: {
  59. setDefault() {
  60. if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
  61. const ids = this.multiple ? this.modelValue : [this.modelValue];
  62. getSelectedList(ids).then((res) => {
  63. if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
  64. const selectedData = res.data.list || []
  65. this.selectedData = selectedData
  66. this.innerValue = this.selectedData.map(o => o.orgNameTree).join();
  67. });
  68. },
  69. setNullValue() {
  70. this.innerValue = '';
  71. this.selectedData = [];
  72. },
  73. openSelect() {
  74. if (this.disabled) return
  75. this.selectShow = true
  76. },
  77. handleConfirm(selectedData, selectedIds) {
  78. if (!this.multiple) {
  79. this.$emit('update:modelValue', selectedIds[0])
  80. this.$emit('change', selectedIds[0], selectedData[0])
  81. } else {
  82. this.$emit('update:modelValue', selectedIds)
  83. this.$emit('change', selectedIds, selectedData)
  84. }
  85. },
  86. handleClose() {
  87. this.selectShow = false
  88. }
  89. }
  90. }
  91. </script>