custList.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <a-select
  3. show-search
  4. label-in-value
  5. :size="size"
  6. :value="dealerName"
  7. mode="combobox"
  8. placeholder="请输入客户名称搜索"
  9. style="width: 100%"
  10. :filter-option="false"
  11. :not-found-content="fetching ? undefined : null"
  12. :dropdownMatchSelectWidth="false"
  13. :defaultActiveFirstOption="false"
  14. @search="fetchUser"
  15. @change="handleChange"
  16. allowClear
  17. >
  18. <a-spin v-if="fetching" slot="notFoundContent" size="small" />
  19. <a-select-option v-for="item in data" :key="item.customerSn" :value="item.customerName" :disabled="(isValidateEnabled ? item.enabledFlag=='0' : false) || (dealerDisabled?item.dealerFlag==1:false)">
  20. {{ item.customerName }}
  21. <span v-if="isValidateEnabled && item.enabledFlag=='0'">(已禁用)</span>
  22. </a-select-option>
  23. </a-select>
  24. </template>
  25. <script>
  26. import debounce from 'lodash/debounce'
  27. import { custList } from '@/api/customer'
  28. export default {
  29. props: {
  30. isValidateEnabled: {
  31. type: Boolean,
  32. default: false
  33. },
  34. size: {
  35. type: String,
  36. default: 'default'
  37. },
  38. itemSn: {
  39. type: String || Number,
  40. default: undefined
  41. },
  42. notSn:{
  43. type: String || Number,
  44. default: ''
  45. },
  46. isEnabled: { // 是否只查启用状态
  47. type: Boolean,
  48. default: false
  49. },
  50. mainFlag: {
  51. type: Boolean,
  52. default: true
  53. },
  54. satelliteFlag: {
  55. type: Boolean,
  56. default: false
  57. },
  58. dealerDisabled: {
  59. type: Boolean,
  60. default: false
  61. }
  62. },
  63. data () {
  64. this.lastFetchId = 0
  65. this.fetchUser = debounce(this.fetchUser, 800)
  66. return {
  67. data: [],
  68. dealerName: undefined,
  69. fetching: false
  70. }
  71. },
  72. methods: {
  73. fetchUser (dealerName) {
  74. console.log('fetching user', dealerName)
  75. if (dealerName == '') return
  76. this.lastFetchId += 1
  77. const fetchId = this.lastFetchId
  78. this.data = []
  79. this.fetching = true
  80. const params = { pageNo: 1, pageSize: 20, mainFlag: this.mainFlag ? 1 : 0 }
  81. if (this.satelliteFlag) {
  82. params.satelliteFlag = 1
  83. }
  84. if (this.itemSn) {
  85. params.customerSn = this.itemSn
  86. } else {
  87. params.queryWord = dealerName
  88. }
  89. if (this.isEnabled) {
  90. params.enabledFlag = 1
  91. }
  92. custList(params).then(res => {
  93. if (fetchId !== this.lastFetchId) {
  94. return
  95. }
  96. this.data = res.data && res.data.list ? res.data.list : []
  97. this.data = this.data.filter(item => item.customerSn != this.notSn)
  98. this.fetching = false
  99. })
  100. },
  101. handleChange (value) {
  102. console.log('handleChange', value)
  103. if (value && value.key) {
  104. const ind = this.data.findIndex(item => item.customerName == value.key)
  105. value.row = ind != -1 ? this.data[ind] : undefined
  106. }
  107. Object.assign(this, {
  108. dealerName: value,
  109. data: [],
  110. fetching: false
  111. })
  112. this.$emit('input', value && value.key || undefined)
  113. this.$emit('change', value && value.key || undefined, value && value.row || undefined)
  114. },
  115. resetForm () {
  116. this.dealerName = undefined
  117. this.setData(undefined)
  118. },
  119. setData (value) {
  120. Object.assign(this, {
  121. dealerName: value,
  122. data: [],
  123. fetching: false
  124. })
  125. }
  126. },
  127. mounted () {
  128. if (this.itemSn) {
  129. this.fetchUser(this.itemSn)
  130. this.setData({ key: this.itemSn })
  131. }
  132. }
  133. }
  134. </script>