employee.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. notInSn:{
  33. type: Array,
  34. default: () => []
  35. }
  36. },
  37. data() {
  38. return {
  39. defaultVal: this.value,
  40. list: []
  41. };
  42. },
  43. mounted() {
  44. this.getList()
  45. },
  46. watch: {
  47. value(newValue, oldValue) {
  48. this.defaultVal = newValue
  49. },
  50. notInSn(a,b){
  51. console.log(a,b)
  52. if(JSON.stringify(a) !== JSON.stringify(b)){
  53. this.getList()
  54. }
  55. }
  56. },
  57. methods: {
  58. filterOption (input, option) {
  59. return (
  60. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  61. )
  62. },
  63. handleChange(value) {
  64. this.defaultVal = value;
  65. const item = this.list.find(item => item.employeeSn == value)
  66. this.$emit('change', value, item);
  67. this.$emit('input', value);
  68. },
  69. getList () {
  70. console.log(11)
  71. this.list = this.$store.state.app.employeeList.filter(item => this.notInSn.indexOf(item.employeeSn)<0)
  72. if(this.list.length==0){
  73. employeeQueryList({}).then(res => {
  74. if (res.status == 200) {
  75. this.list = res.data
  76. } else {
  77. this.list = []
  78. }
  79. })
  80. }
  81. },
  82. },
  83. };
  84. export default Employee