main.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <!-- 中文下拉 -->
  3. <el-select v-model="value" @input="$emit('selectedValue', value)" :placeholder="'请输入 ' + placeholder"
  4. @change="selectChange" @clear="clear" :clearable="clearable" :multiple="multiple" :filterable="filterable"
  5. :remote="remote" :remote-method="remoteMethod" :loading="loading" :size="size" :disabled="disabled">
  6. <el-option v-for="item in options" :key="item[key]" :label="item[label]" :value="item[keyValue?keyValue:label]">
  7. </el-option>
  8. </el-select>
  9. </template>
  10. <script>
  11. import { getDicinit } from "@/api/dicSelect/index";
  12. export default {
  13. data() {
  14. return {
  15. options: [],
  16. loading: false,
  17. data: {}
  18. }
  19. },
  20. props: {
  21. activateCreated: {
  22. type: Boolean,
  23. default: true
  24. },
  25. key: {
  26. type: [String, Number],
  27. default: null
  28. },
  29. label: {
  30. type: String,
  31. default: ''
  32. },
  33. keyValue: {
  34. type: [String, Number],
  35. default: null
  36. },
  37. res: {
  38. type: String,
  39. default: ''
  40. },
  41. placeholder: {
  42. type: String,
  43. default: '请输入'
  44. },
  45. clearable: {
  46. type: Boolean,
  47. default: true
  48. },
  49. value: {
  50. type: [String, Number],
  51. default: ''
  52. },
  53. method: {
  54. type: String,
  55. default: 'GET'
  56. },
  57. url: {
  58. type: String,
  59. default: ''
  60. },
  61. dataName: {
  62. type: String,
  63. default: ''
  64. },
  65. multiple: {
  66. type: Boolean,
  67. default: false
  68. },
  69. filterable: {
  70. type: Boolean,
  71. default: false
  72. },
  73. remote: {
  74. type: Boolean,
  75. default: false
  76. },
  77. size: {
  78. type: String,
  79. default: 'small'
  80. },
  81. disabled: {
  82. type: Boolean,
  83. default: false
  84. },
  85. },
  86. model: {
  87. prop: "value",
  88. event: "selectedValue"
  89. },
  90. created() {
  91. if (this.activateCreated) {
  92. this.getDicData()
  93. }
  94. },
  95. methods: {
  96. remoteMethod(query) {
  97. if (query !== '') {
  98. setTimeout(() => {
  99. this.data[this.dataName] = query
  100. this.getDicData()
  101. }, 200);
  102. } else {
  103. setTimeout(() => {
  104. this.data = this.$options.data().data
  105. this.getDicData()
  106. }, 200);
  107. }
  108. },
  109. getDicData() {
  110. this.loading = true
  111. getDicinit(this.method, this.url, this.data).then(res => {
  112. if (this.res) {
  113. this.options = res.data.data[this.res]
  114. } else {
  115. this.options = res.data.data
  116. }
  117. }).finally(() => {
  118. this.loading = false;
  119. })
  120. },
  121. IdGetDicData(data) {
  122. this.loading = true
  123. getDicinit(this.method, this.url, data).then(res => {
  124. if (this.res) {
  125. this.options = res.data.data[this.res]
  126. } else {
  127. this.options = res.data.data
  128. }
  129. }).finally(() => {
  130. this.loading = false;
  131. })
  132. },
  133. selectChange(row) {
  134. this.options.forEach(e => {
  135. if (row == e[this.label]) {
  136. this.$emit('selectChange', e)
  137. }
  138. })
  139. },
  140. clear() {
  141. if (this.remote) {
  142. this.getDicData()
  143. }
  144. this.$emit('selectChange', null)
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped></style>