index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- 资金账户下拉列表 -->
  2. <template>
  3. <app-remote-select v-model="selectedValue" :options="dataList"
  4. :option-props="{ label: 'relatedName', value: 'accountId' }" :remote-method="remoteMethod" @change="onChange"
  5. @reset="onReset">
  6. <template #default="{ option }">
  7. <div style="display: flex;justify-content: space-between;">
  8. <span>{{ option.accountId }}</span>
  9. <span>{{ option.relatedName }}</span>
  10. </div>
  11. </template>
  12. </app-remote-select>
  13. </template>
  14. <script lang="ts" setup>
  15. import { computed, toRaw ,PropType} from 'vue'
  16. import { useRequest } from '@/hooks/request'
  17. import { queryTAAccountChildren } from '@/services/api/common'
  18. import AppRemoteSelect from '@pc/components/base/remote-select/index.vue'
  19. const props = defineProps({
  20. modelValue: [Number, String],
  21. params: {
  22. type: Object as PropType<Model.TAAccountChildrenReq>
  23. },
  24. })
  25. const emit = defineEmits(['update:modelValue', 'change'])
  26. const selectedValue = computed({
  27. get: () => props.modelValue,
  28. set: (val) => emit('update:modelValue', val)
  29. })
  30. const { dataList, loading, run } = useRequest(queryTAAccountChildren, {
  31. manual: true,
  32. defaultParams: props.params,
  33. onSuccess: (res) => {
  34. if (!res.data.some((e) => e.accountId.toString() === selectedValue.value?.toString())) {
  35. selectedValue.value = undefined
  36. onChange()
  37. }
  38. }
  39. })
  40. const onReset = () => {
  41. if (!loading.value) {
  42. run()
  43. }
  44. }
  45. const remoteMethod = (query: string) => {
  46. if (!loading.value) {
  47. if (query) {
  48. run({
  49. searchCode: query
  50. })
  51. } else if (!selectedValue.value) {
  52. onReset()
  53. }
  54. }
  55. }
  56. const onChange = (value?: string) => {
  57. const item = dataList.value.find((e) => e.accountId === value)
  58. emit('change', item && toRaw(item))
  59. }
  60. defineExpose({
  61. onReset
  62. })
  63. </script>