custList.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. dealerFlag: { // 0不含下级,1 只是下级,all是全部
  63. type: String,
  64. default: 'all'
  65. }
  66. },
  67. data () {
  68. this.lastFetchId = 0
  69. this.fetchUser = debounce(this.fetchUser, 800)
  70. return {
  71. data: [],
  72. dealerName: undefined,
  73. fetching: false
  74. }
  75. },
  76. methods: {
  77. fetchUser (dealerName) {
  78. if (dealerName == '') return
  79. this.lastFetchId += 1
  80. const fetchId = this.lastFetchId
  81. this.data = []
  82. this.fetching = true
  83. const params = { pageNo: 1, pageSize: 20, mainFlag: this.mainFlag ? 1 : 0, dealerFlag: this.dealerFlag == 'all' ? undefined : this.dealerFlag }
  84. if (this.satelliteFlag) {
  85. params.satelliteFlag = 1
  86. }
  87. if (this.itemSn) {
  88. params.customerSn = this.itemSn
  89. } else {
  90. params.queryWord = dealerName.trim()
  91. }
  92. if (this.isEnabled) {
  93. params.enabledFlag = 1
  94. }
  95. custList(params).then(res => {
  96. if (fetchId !== this.lastFetchId) {
  97. return
  98. }
  99. this.data = res.data && res.data.list ? res.data.list : []
  100. this.data = this.data.filter(item => item.customerSn != this.notSn)
  101. this.fetching = false
  102. })
  103. },
  104. handleChange (value) {
  105. if (value && value.key) {
  106. value.key = value.key.trim()
  107. const ind = this.data.findIndex(item => item.customerName == value.key)
  108. value.row = ind != -1 ? this.data[ind] : undefined
  109. }
  110. Object.assign(this, {
  111. dealerName: value,
  112. data: [],
  113. fetching: false
  114. })
  115. this.$emit('input', value && value.key || undefined)
  116. this.$emit('change', value && value.key || undefined, value && value.row || undefined)
  117. },
  118. resetForm () {
  119. this.dealerName = undefined
  120. this.setData(undefined)
  121. },
  122. setData (value) {
  123. Object.assign(this, {
  124. dealerName: value,
  125. data: [],
  126. fetching: false
  127. })
  128. }
  129. },
  130. mounted () {
  131. if (this.itemSn) {
  132. this.fetchUser(this.itemSn)
  133. this.setData({ key: this.itemSn })
  134. }
  135. }
  136. }
  137. </script>