index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2023-05-31 16:51:34
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2024-06-20 13:51:54
  7. -->
  8. <template>
  9. <div>
  10. <el-select
  11. v-model="selectId"
  12. clearable
  13. :disabled="disabled"
  14. filterable
  15. :loading="loading"
  16. :placeholder="placeholder"
  17. remote
  18. :remote-method="remoteMethod"
  19. reserve-keyword
  20. @change="handleSelect"
  21. style="width: 100%;"
  22. >
  23. <el-option
  24. v-for="item in selectList"
  25. :key="item.id"
  26. :label="item[searchName]"
  27. :value="item.id"
  28. />
  29. </el-select>
  30. </div>
  31. </template>
  32. <script>
  33. import { getSelectApi } from './api/index'
  34. export default defineComponent({
  35. name: 'BatchSend',
  36. props: {
  37. id: {
  38. type: String,
  39. default: '', //回选id
  40. },
  41. url: {
  42. type: String,
  43. default: '', //请求地址
  44. },
  45. searchName: {
  46. type: String,
  47. default: '', //搜索字段名称
  48. },
  49. placeholder: {
  50. type: String,
  51. default: '请输入筛选数据', //筛选提示文字
  52. },
  53. disabled: {
  54. type: Boolean,
  55. default: false,
  56. },
  57. },
  58. emits: ['fetch-data'],
  59. setup(props, { emit }) {
  60. const state = reactive({
  61. selectList: [],
  62. selectId: '', //工厂id
  63. loading: true,
  64. queryParams: {},
  65. })
  66. watch(
  67. () => props.id,
  68. () => {
  69. if (props.id) {
  70. state.selectId = props.id
  71. } else {
  72. state.selectId = ''
  73. }
  74. }
  75. )
  76. const remoteMethod = (e) => {
  77. state.queryParams[props.searchName] = e
  78. factoryList()
  79. }
  80. const factoryList = async () => {
  81. state.loading = true
  82. const { data } = await getSelectApi(props.url, props.queryParams)
  83. state.selectList = data
  84. state.loading = false
  85. }
  86. //选择工厂
  87. const handleSelect = (e) => {
  88. emit('fetch-data', e)
  89. }
  90. onMounted(() => {
  91. setTimeout(() => {
  92. factoryList()
  93. }, 1000)
  94. })
  95. return {
  96. ...toRefs(state),
  97. remoteMethod,
  98. factoryList,
  99. handleSelect,
  100. }
  101. },
  102. })
  103. </script>