settleStyle.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { settleStyleQueryAll } from '@/api/settleStyle'
  2. const CustList = {
  3. template: `
  4. <a-select
  5. :id="id"
  6. :placeholder="placeholder"
  7. allowClear
  8. :value="defaultVal"
  9. :showSearch="true"
  10. @change="handleChange"
  11. :filter-option="filterOption">
  12. <a-select-option v-for="item in list" :key="item[defValKey]" :value="item[defValKey]">{{ item.name }}</a-select-option>
  13. </a-select>
  14. `,
  15. props: {
  16. value: {
  17. type: String,
  18. defatut: ''
  19. },
  20. id: {
  21. type: String,
  22. default: ''
  23. },
  24. defValKey: {
  25. type: String,
  26. default: 'settleStyleSn'
  27. },
  28. placeholder: {
  29. type: String,
  30. default: '请选择结算方式'
  31. }
  32. },
  33. data() {
  34. return {
  35. defaultVal: this.value||undefined,
  36. list: []
  37. };
  38. },
  39. watch: {
  40. value(newValue, oldValue) {
  41. console.log(newValue)
  42. this.defaultVal = newValue||undefined
  43. }
  44. },
  45. mounted() {
  46. this.getList()
  47. },
  48. methods: {
  49. filterOption (input, option) {
  50. return (
  51. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  52. )
  53. },
  54. handleChange(value) {
  55. this.defaultVal = value;
  56. const settleStyleName = this.list.find(item => item[this.defValKey] == value).name
  57. this.$emit('input', value);
  58. this.$emit('change', this.value, settleStyleName);
  59. },
  60. // 列表数据
  61. getList () {
  62. const _this = this
  63. settleStyleQueryAll().then(res => {
  64. if (res.status == 200) {
  65. _this.list = res.data || []
  66. } else {
  67. _this.list = []
  68. }
  69. })
  70. },
  71. },
  72. };
  73. export default CustList