index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2023-05-31 16:51:34
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-06-13 09:24:52
  7. -->
  8. <template>
  9. <div>
  10. <el-select
  11. v-model="classfy_id"
  12. clearable
  13. :disabled="disabled"
  14. filterable
  15. :loading="loading"
  16. :multiple="multiple"
  17. placeholder="请输入来源部门"
  18. remote
  19. :remote-method="remoteMethod"
  20. reserve-keyword
  21. style="width: 100%"
  22. @change="changeFactory"
  23. >
  24. <el-option
  25. v-for="item in selectList"
  26. :key="item.id"
  27. :label="item.name"
  28. :value="item.id"
  29. />
  30. </el-select>
  31. </div>
  32. </template>
  33. <script>
  34. import { getSelectList } from './api/index'
  35. export default defineComponent({
  36. name: 'BatchSend',
  37. props: {
  38. classfy: {
  39. type: String,
  40. default: '',
  41. },
  42. disabled: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. multiple: {
  47. type: Boolean,
  48. default: false,
  49. },
  50. },
  51. emits: ['fetch-data'],
  52. setup(props, { emit }) {
  53. const state = reactive({
  54. selectList: [],
  55. classfy_id: '', //工厂id
  56. loading: true,
  57. })
  58. watch(
  59. () => props.classfy,
  60. () => {
  61. if (props.classfy) {
  62. state.classfy_id = props.classfy
  63. } else {
  64. state.classfy_id = ''
  65. }
  66. }
  67. )
  68. const remoteMethod = (e) => {
  69. classfyList(e)
  70. }
  71. const classfyList = async (e) => {
  72. state.loading = true
  73. const { data } = await getSelectList({ name: e, status: 1 })
  74. console.log(data, 'shuju')
  75. const list = data.data
  76. if (list && list.length > 0) {
  77. state.selectList = list
  78. } else {
  79. state.selectList = []
  80. }
  81. state.loading = false
  82. }
  83. //选择工厂
  84. const changeFactory = () => {
  85. emit('fetch-data', state.classfy_id)
  86. }
  87. onMounted(() => {
  88. classfyList()
  89. })
  90. return {
  91. ...toRefs(state),
  92. remoteMethod,
  93. classfyList,
  94. changeFactory,
  95. }
  96. },
  97. })
  98. </script>