employee.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { employeeQueryList } from '@/api/expenseManagement'
  2. const Employee = {
  3. template: `
  4. <a-select
  5. :placeholder="placeholder"
  6. :id="id"
  7. allowClear
  8. :value="defaultVal"
  9. :showSearch="true"
  10. @change="handleChange"
  11. option-filter-prop="children"
  12. :filter-option="filterOption">
  13. <a-select-option v-for="item in list" :key="item.employeeSn" :value="item.employeeSn">
  14. {{ item.name }}
  15. <span v-if="item.kdDepartmentAllName">--{{item.kdDepartmentAllName}}</span>
  16. </a-select-option>
  17. </a-select>
  18. `,
  19. props: {
  20. value: {
  21. type: String,
  22. defatut: ''
  23. },
  24. id: {
  25. type: String,
  26. default: ''
  27. },
  28. placeholder: {
  29. type: String,
  30. default: '请选择申请人(输入名称搜索)'
  31. },
  32. },
  33. data() {
  34. return {
  35. defaultVal: this.value,
  36. list: []
  37. };
  38. },
  39. mounted() {
  40. this.getList()
  41. },
  42. watch: {
  43. value(newValue, oldValue) {
  44. this.defaultVal = newValue
  45. },
  46. },
  47. methods: {
  48. filterOption (input, option) {
  49. return (
  50. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  51. )
  52. },
  53. handleChange(value) {
  54. this.defaultVal = value;
  55. const item = this.list.find(item => item.employeeSn == value)
  56. this.$emit('change', value, item);
  57. this.$emit('input', value);
  58. },
  59. getList () {
  60. employeeQueryList({}).then(res => {
  61. if (res.status == 200) {
  62. this.list = res.data
  63. } else {
  64. this.list = []
  65. }
  66. })
  67. },
  68. },
  69. };
  70. export default Employee