main.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div style="display: flex;">
  3. <el-select
  4. v-model="value"
  5. placeholder="请选择"
  6. filterable
  7. clearable
  8. allow-create
  9. default-first-option
  10. @change="getKeyId(value)" :disabled="disabled"
  11. @clear="clear()">
  12. <template>
  13. <el-option v-for="item in corpList" :key="item.id" :label="corpType == 'DD'?item.name:corpType == 'DD-ID'?item.name:item.cname" :value="item.id">
  14. </el-option>
  15. </template>
  16. </el-select>
  17. <el-tooltip class="item" effect="dark" content="获取最新客户资料" placement="top-start">
  18. <el-button icon="el-icon-refresh" size="mini" v-if="label != 'shortName'" :disabled="disabled"
  19. @click="refreshData"></el-button>
  20. </el-tooltip>
  21. </div>
  22. </template>
  23. <script>
  24. import {allCropList} from "@/api/basicData/customerInformation";
  25. import {kMaxLength} from "buffer";
  26. import {getAllList} from "@/api/basicData/portinformation";
  27. export default {
  28. name: "main",
  29. data() {
  30. return {
  31. form: {},
  32. corpList: []
  33. };
  34. },
  35. props: {
  36. value: String,
  37. name: String,
  38. label: String,
  39. corpType: String,
  40. disabled: Boolean
  41. },
  42. model: {
  43. prop: "value",
  44. event: "balabala",
  45. },
  46. created() {
  47. this.getCorpList()
  48. },
  49. methods: {
  50. getCorpList(type) {
  51. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  52. if (this.corpType == 'DD'){
  53. getAllList().then(res => {
  54. this.corpList = res.data.data;
  55. if (type) {
  56. for (let item of this.corpList) {
  57. if (item.name == this.value) {
  58. return this.getKeyId(item.id)
  59. }
  60. }
  61. for (let item of this.corpList) {
  62. if (item.id == this.value) {
  63. return this.getKeyId(item.id)
  64. }
  65. }
  66. }
  67. });
  68. }else if(this.corpType == 'DD-ID'){
  69. getAllList().then(res => {
  70. this.corpList = res.data.data;
  71. if (type) {
  72. for (let item of this.corpList) {
  73. if (item.name == this.value) {
  74. return this.getKeyId(item.id)
  75. }
  76. }
  77. for (let item of this.corpList) {
  78. if (item.id == this.value) {
  79. return this.getKeyId(item.id)
  80. }
  81. }
  82. }
  83. });
  84. }else {
  85. allCropList({
  86. corpType: this.corpType ? this.corpType : 'KH',
  87. adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null
  88. }).then(res => {
  89. this.corpList = res.data.data;
  90. if (type) {
  91. for (let item of this.corpList) {
  92. if (item.cname == this.value) {
  93. return this.getKeyId(item.id)
  94. }
  95. }
  96. for (let item of this.corpList) {
  97. if (item.id == this.value) {
  98. return this.getKeyId(item.id)
  99. }
  100. }
  101. }
  102. });
  103. }
  104. },
  105. refreshData() {
  106. this.getCorpList(true)
  107. },
  108. getKeyId(row) {
  109. if (row) {
  110. let res = this.corpList.find(e => {
  111. return e.id == row
  112. })
  113. if (res) {
  114. if (this.corpType == 'DD'){
  115. this.$emit('balabala',res.name)
  116. this.$emit('getCropId', res)
  117. }else if (this.corpType == 'DD-ID'){
  118. this.$emit('balabala',res.id)
  119. this.$emit('getCropId', res)
  120. }else {
  121. this.$emit('balabala',res.id)
  122. this.$emit('getCropId', res)
  123. }
  124. } else {
  125. if (this.corpType == 'DD'){
  126. this.$emit('update:name', row);
  127. }else if (this.corpType == 'DD-ID'){
  128. this.$emit('update:name', row);
  129. }else {
  130. this.$emit('update:name', row);
  131. }
  132. this.$emit('balabala',row)
  133. this.$emit('getCropId', null)
  134. }
  135. } else {
  136. this.$emit('balabala', null)
  137. this.$emit('getCropId', null)
  138. }
  139. },
  140. // 清空
  141. clear() {
  142. this.$emit('clear', null)
  143. }
  144. },
  145. watch: {}
  146. };
  147. </script>
  148. <style lang="scss" scoped>
  149. </style>