index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div>
  3. <el-select
  4. v-model="supplier_id"
  5. clearable
  6. :disabled="disabled"
  7. filterable
  8. :loading="loading"
  9. placeholder="请输入供应商简称"
  10. remote
  11. :remote-method="remoteMethod"
  12. reserve-keyword
  13. style="width: 100%"
  14. @change="changeFactory"
  15. >
  16. <el-option
  17. v-for="item in supplierList"
  18. :key="item.id"
  19. :label="item.name"
  20. :value="item.id"
  21. />
  22. </el-select>
  23. </div>
  24. </template>
  25. <script>
  26. import { getSupplierList } from './api/index'
  27. export default defineComponent({
  28. name: 'BatchSend',
  29. props: {
  30. supplier: {
  31. type: String,
  32. default: '',
  33. },
  34. disabled: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. },
  39. emits: ['fetch-data'],
  40. setup(props, { emit }) {
  41. const state = reactive({
  42. supplierList: [],
  43. supplier_id: '', //工厂id
  44. loading: true,
  45. })
  46. watch(
  47. () => props.supplier,
  48. () => {
  49. console.log(props.supplier, ' props.supplierId')
  50. if (props.supplier) {
  51. state.supplier_id = props.supplier
  52. } else {
  53. state.supplier_id = ''
  54. }
  55. }
  56. )
  57. const remoteMethod = (e) => {
  58. factoryList(e)
  59. }
  60. const factoryList = async (e) => {
  61. state.loading = true
  62. const { data } = await getSupplierList({ s_name: e, status: 1 })
  63. const arr = []
  64. if (data && data.length > 0) {
  65. data.map((item) => {
  66. arr.push({
  67. id: item.id,
  68. name:
  69. '【' + (item.s_name ? item.s_name : '未知') + '】' + item.name,
  70. })
  71. })
  72. }
  73. state.supplierList = arr
  74. state.loading = false
  75. }
  76. //选择工厂
  77. const changeFactory = () => {
  78. emit('fetch-data', state.supplier_id)
  79. }
  80. onMounted(() => {
  81. factoryList()
  82. })
  83. return {
  84. ...toRefs(state),
  85. remoteMethod,
  86. factoryList,
  87. changeFactory,
  88. }
  89. },
  90. })
  91. </script>