getTenantList.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { getReportPutTenantList } from '@/api/allocLinkagePut'
  2. import { getReportOutTenantList } from '@/api/allocLinkageOut'
  3. // 调出对象
  4. const getTenantList = {
  5. template: `
  6. <a-select
  7. :id="id"
  8. :placeholder="placeholder"
  9. allowClear
  10. :value="defaultVal"
  11. :showSearch="true"
  12. @change="handleChange"
  13. :filter-option="filterOption">
  14. <a-select-option v-for="item in list" :key="item[defValKey]" :value="item[defValKey]">{{ item.dealerName }}</a-select-option>
  15. </a-select>
  16. `,
  17. props: {
  18. value: {
  19. type: String,
  20. default: ''
  21. },
  22. id: {
  23. type: String,
  24. default: ''
  25. },
  26. defValKey: {
  27. type: String,
  28. default: 'dealerSn'
  29. },
  30. placeholder: {
  31. type: String,
  32. default: '请选择调出对象'
  33. },
  34. type: {
  35. type: String,
  36. default: 'put'
  37. },
  38. state: {
  39. type: String,
  40. default: ''
  41. }
  42. },
  43. data() {
  44. return {
  45. defaultVal: this.value||undefined,
  46. list: []
  47. };
  48. },
  49. watch: {
  50. value(newValue, oldValue) {
  51. console.log(newValue)
  52. this.defaultVal = newValue||undefined
  53. }
  54. },
  55. mounted() {
  56. this.getList()
  57. },
  58. methods: {
  59. filterOption (input, option) {
  60. return (
  61. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  62. )
  63. },
  64. handleChange(value) {
  65. console.log(value)
  66. this.defaultVal = value;
  67. const row = this.list.find(item => item[this.defValKey] == value)
  68. this.$emit('input', value);
  69. this.$emit('change', this.defaultVal, row?row.dealerName:'');
  70. },
  71. // 列表数据
  72. getList () {
  73. const _this = this
  74. const fun = this.type == 'put' ? getReportPutTenantList : getReportOutTenantList
  75. fun({state: this.state}).then(res => {
  76. if (res.status == 200) {
  77. _this.list = res.data || []
  78. } else {
  79. _this.list = []
  80. }
  81. })
  82. },
  83. },
  84. };
  85. export default getTenantList