settleAccount.js 2.2 KB

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