index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div>
  3. <el-input placeholder="选择企业" :size="size" :disabled="true" :readonly="readonly" style="line-hight:40px"
  4. v-model="name" class="input-with-select">
  5. <el-button slot="append" :disabled="disabled" :readonly="readonly" @click="showUserSelect"
  6. icon="el-icon-search"></el-button>
  7. </el-input>
  8. <qySelect ref="qySelect" @doSubmit="selectQyToInput" :limit="limit" :selectData="selectData"></qySelect>
  9. </div>
  10. </template>
  11. <script>
  12. import qySelect from './QySelectDialog'
  13. import EnterpriseInfoService from '@/api/enterpriseinfo/enterpriseInfoService'
  14. export default {
  15. data () {
  16. return {
  17. name: '',
  18. labelValue: this.value,
  19. selectData: [],
  20. isOnlyOne: false
  21. }
  22. },
  23. props: {
  24. limit: Number,
  25. value: String,
  26. size: {
  27. type: String,
  28. default: () => { return 'small' }
  29. },
  30. readonly: {
  31. type: Boolean,
  32. default: () => { return false }
  33. },
  34. disabled: {
  35. type: Boolean,
  36. default: () => { return false }
  37. }
  38. },
  39. components: {
  40. qySelect
  41. },
  42. enterpriseInfoService: null,
  43. beforeCreate () {
  44. },
  45. watch: {
  46. value: {
  47. handler (newVal) {
  48. if (!this.isOnlyOne) {
  49. this.selectData = []
  50. if (newVal) {
  51. newVal.split(',').forEach((id) => {
  52. if (EnterpriseInfoService) {
  53. EnterpriseInfoService.queryById(id).then(({data}) => {
  54. if (!this.isOnlyOne) {
  55. if (data && data.id !== '') {
  56. this.selectData.push(data)
  57. }
  58. }
  59. })
  60. }
  61. })
  62. }
  63. }
  64. },
  65. immediate: true,
  66. deep: false
  67. },
  68. selectData: {
  69. handler (newVal) {
  70. this.name = newVal.map(site => { return site.name }).join(',')
  71. },
  72. immediate: false,
  73. deep: false
  74. }
  75. },
  76. mounted () {
  77. },
  78. methods: {
  79. selectQyToInput (sites) {
  80. console.log("GG:"+JSON.stringify(sites))
  81. this.selectData = sites
  82. this.$emit('valueChanges', this.selectData, this)
  83. this.labelValue = sites.map(site => { return site.id }).join(',')
  84. this.name = sites.map(site => { return site.name }).join(',')
  85. this.$emit('getValue', this.labelValue, this.name,
  86. sites
  87. )
  88. this.$emit('valueChange', this.selectData)
  89. },
  90. showUserSelect () {
  91. this.$refs.qySelect.init()
  92. }
  93. }
  94. }
  95. </script>
  96. <style>
  97. .el-form-item__content .el-input-group {
  98. vertical-align: middle;
  99. }
  100. .el-tag+.el-tag {
  101. margin-left: 5px;
  102. margin-bottom: 5px;
  103. }
  104. </style>