main.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. <template>
  12. <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">
  13. </el-option>
  14. </template>
  15. </el-select>
  16. <el-tooltip class="item" effect="dark" content="获取最新客户资料" placement="top-start">
  17. <el-button icon="el-icon-refresh" size="mini" v-if="label != 'shortName'" :disabled="disabled"
  18. @click="refreshData"></el-button>
  19. </el-tooltip>
  20. </div>
  21. </template>
  22. <script>
  23. import {allCropList} from "@/api/basicData/customerInformation";
  24. import {kMaxLength} from "buffer";
  25. import {getAllList} from "@/api/basicData/portinformation";
  26. export default {
  27. name: "main",
  28. data() {
  29. return {
  30. form: {},
  31. corpList: []
  32. };
  33. },
  34. props: {
  35. value: String,
  36. name: String,
  37. label: String,
  38. corpType: String,
  39. disabled: Boolean
  40. },
  41. model: {
  42. prop: "value",
  43. event: "balabala",
  44. },
  45. created() {
  46. this.getCorpList()
  47. },
  48. methods: {
  49. getCorpList(type) {
  50. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  51. if (this.corpType == 'DD'){
  52. getAllList().then(res => {
  53. this.corpList = res.data.data;
  54. if (type) {
  55. for (let item of this.corpList) {
  56. if (item.name == this.value) {
  57. return this.getKeyId(item.id)
  58. }
  59. }
  60. for (let item of this.corpList) {
  61. if (item.id == this.value) {
  62. return this.getKeyId(item.id)
  63. }
  64. }
  65. }
  66. });
  67. }else if(this.corpType == 'DD-ID'){
  68. getAllList().then(res => {
  69. this.corpList = res.data.data;
  70. if (type) {
  71. for (let item of this.corpList) {
  72. if (item.name == this.value) {
  73. return this.getKeyId(item.id)
  74. }
  75. }
  76. for (let item of this.corpList) {
  77. if (item.id == this.value) {
  78. return this.getKeyId(item.id)
  79. }
  80. }
  81. }
  82. });
  83. }else {
  84. allCropList({
  85. corpType: this.corpType ? this.corpType : 'KH',
  86. adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null
  87. }).then(res => {
  88. this.corpList = res.data.data;
  89. if (type) {
  90. for (let item of this.corpList) {
  91. if (item.cname == this.value) {
  92. return this.getKeyId(item.id)
  93. }
  94. }
  95. for (let item of this.corpList) {
  96. if (item.id == this.value) {
  97. return this.getKeyId(item.id)
  98. }
  99. }
  100. }
  101. });
  102. }
  103. },
  104. refreshData() {
  105. this.getCorpList(true)
  106. },
  107. getKeyId(row) {
  108. console.log(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. watch: {}
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. </style>