custType.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { custTypeFindAllList } from '@/api/custType'
  2. const custType = {
  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. :dropdownMatchSelectWidth="false"
  13. :filter-option="filterOption">
  14. <a-select-option v-for="item in list" :pinyin="item.pinyin" :key="item.customerTypeSn" :value="item.customerTypeSn">{{ item.name }}</a-select-option>
  15. </a-select>
  16. `,
  17. props: {
  18. value: {
  19. type: String,
  20. },
  21. id: {
  22. type: String,
  23. default: ''
  24. },
  25. placeholder: {
  26. type: String,
  27. default: '请选择客户类型'
  28. }
  29. },
  30. data() {
  31. return {
  32. defaultVal: this.value,
  33. list: []
  34. };
  35. },
  36. mounted() {
  37. this.getList()
  38. },
  39. watch: {
  40. value(newValue, oldValue) {
  41. this.defaultVal = newValue
  42. }
  43. },
  44. methods: {
  45. filterOption (input, option) {
  46. return (
  47. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
  48. option.data.attrs.pinyin.toLowerCase().indexOf(input.toLowerCase()) >= 0
  49. )
  50. },
  51. handleChange(value) {
  52. this.defaultVal = value;
  53. this.$emit('change', value);
  54. this.$emit('input', value);
  55. },
  56. getList () {
  57. custTypeFindAllList().then(res => {
  58. if (res.status == 200) {
  59. this.list = res.data
  60. } else {
  61. this.list = []
  62. }
  63. })
  64. },
  65. },
  66. };
  67. export default custType