index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 18:06:16
  7. -->
  8. <template>
  9. <div>
  10. <el-select
  11. v-model="factory_id"
  12. clearable
  13. :disabled="disabled"
  14. filterable
  15. :loading="loading"
  16. placeholder="请输入招聘企业"
  17. remote
  18. :remote-method="remoteMethod"
  19. reserve-keyword
  20. style="width: 100%"
  21. @change="changeFactory"
  22. >
  23. <el-option
  24. v-for="item in companyList"
  25. :key="item.id"
  26. :label="item.name"
  27. :value="item.id"
  28. />
  29. </el-select>
  30. </div>
  31. </template>
  32. <script>
  33. import { getFactoryList } from './api/index'
  34. export default defineComponent({
  35. name: 'BatchSend',
  36. props: {
  37. factory: {
  38. type: String,
  39. default: '',
  40. },
  41. disabled: {
  42. type: Boolean,
  43. default: false,
  44. },
  45. },
  46. emits: ['fetch-data'],
  47. setup(props, { emit }) {
  48. const state = reactive({
  49. companyList: [],
  50. factory_id: '', //工厂id
  51. loading: true,
  52. })
  53. watch(
  54. () => props.factory,
  55. () => {
  56. if (props.factory) {
  57. state.factory_id = props.factory
  58. } else {
  59. state.factory_id = ''
  60. }
  61. }
  62. )
  63. const remoteMethod = (e) => {
  64. factoryList(e)
  65. }
  66. const factoryList = async (e) => {
  67. state.loading = true
  68. const { data } = await getFactoryList({ s_name: e, status: 1 })
  69. const arr = []
  70. if (data && data.length > 0) {
  71. data.map((item) => {
  72. arr.push({
  73. id: item.id,
  74. name: '【' + item.s_name + '】' + item.name,
  75. s_name: item.s_name,
  76. })
  77. })
  78. }
  79. state.companyList = arr
  80. state.loading = false
  81. }
  82. //选择工厂
  83. const changeFactory = () => {
  84. let name = ''
  85. state.companyList.map((item) => {
  86. if (item.id == state.factory_id) {
  87. name = item.s_name
  88. }
  89. })
  90. emit('fetch-data', state.factory_id)
  91. emit('fetch-name', name)
  92. }
  93. onMounted(() => {
  94. factoryList()
  95. })
  96. return {
  97. ...toRefs(state),
  98. remoteMethod,
  99. factoryList,
  100. changeFactory,
  101. }
  102. },
  103. })
  104. </script>