index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 } from 'vue'
  16. import { useRequest } from '@/hooks/request'
  17. import { queryTAAccountChildrenSelect } from '@/services/api/report'
  18. import AppRemoteSelect from '@pc/components/base/remote-select/index.vue'
  19. const props = defineProps({
  20. modelValue: [Number, String]
  21. })
  22. const emit = defineEmits(['update:modelValue', 'change'])
  23. const selectedValue = computed({
  24. get: () => props.modelValue,
  25. set: (val) => emit('update:modelValue', val)
  26. })
  27. const { dataList, loading, run } = useRequest(queryTAAccountChildrenSelect, {
  28. manual: true,
  29. onSuccess: (res) => {
  30. if (!res.data.some((e) => e.accountid.toString() === selectedValue.value?.toString())) {
  31. selectedValue.value = undefined
  32. onChange()
  33. }
  34. }
  35. })
  36. const onReset = () => {
  37. if (!loading.value) {
  38. run()
  39. }
  40. }
  41. const remoteMethod = (query: string) => {
  42. if (!loading.value) {
  43. if (query) {
  44. run({
  45. searchcode: query
  46. })
  47. } else if (!dataList.value.length) {
  48. onReset()
  49. }
  50. }
  51. }
  52. const onChange = (value?: number) => {
  53. const item = dataList.value.find((e) => e.accountid === value)
  54. emit('change', item && toRaw(item))
  55. }
  56. defineExpose({
  57. onReset
  58. })
  59. </script>