index.vue 2.2 KB

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