d0cfad1d0531ffa56f36676e853662a92896da9f.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div>
  3. <a-input-search
  4. v-model="textVals"
  5. placeholder="请先选择用户"
  6. readOnly
  7. unselectable="on"
  8. @search="onSearchDepUser">
  9. <a-button slot="enterButton" :disabled="disabled">选择用户</a-button>
  10. </a-input-search>
  11. <j-select-user-by-dep-modal
  12. ref="selectModal"
  13. :modal-width="modalWidth"
  14. :multi="multi"
  15. @ok="selectOK"
  16. :user-ids="value"
  17. :store="storeField"
  18. :text="textField"
  19. @initComp="initComp"/>
  20. </div>
  21. </template>
  22. <script>
  23. import JSelectUserByDepModal from './modal/JSelectUserByDepModal'
  24. import { underLinetoHump } from '@/components/_util/StringUtil'
  25. export default {
  26. name: 'JSelectUserByDep',
  27. components: {JSelectUserByDepModal},
  28. props: {
  29. modalWidth: {
  30. type: Number,
  31. default: 1250,
  32. required: false
  33. },
  34. value: {
  35. type: String,
  36. required: false
  37. },
  38. disabled: {
  39. type: Boolean,
  40. required: false,
  41. default: false
  42. },
  43. multi: {
  44. type: Boolean,
  45. default: true,
  46. required: false
  47. },
  48. backUser: {
  49. type: Boolean,
  50. default: false,
  51. required: false
  52. },
  53. // 存储字段 [key field]
  54. store: {
  55. type: String,
  56. default: 'username',
  57. required: false
  58. },
  59. // 显示字段 [label field]
  60. text: {
  61. type: String,
  62. default: 'realname',
  63. required: false
  64. }
  65. },
  66. data() {
  67. return {
  68. storeVals: '', //[key values]
  69. textVals: '' //[label values]
  70. }
  71. },
  72. computed:{
  73. storeField(){
  74. let field = this.customReturnField
  75. if(!field){
  76. field = this.store;
  77. }
  78. return underLinetoHump(field)
  79. },
  80. textField(){
  81. return underLinetoHump(this.text)
  82. }
  83. },
  84. mounted() {
  85. this.storeVals = this.value
  86. },
  87. watch: {
  88. value(val) {
  89. this.storeVals = val
  90. }
  91. },
  92. model: {
  93. prop: 'value',
  94. event: 'change'
  95. },
  96. methods: {
  97. initComp(textVals) {
  98. this.textVals = textVals
  99. },
  100. //返回选中的用户信息
  101. backDeparInfo(){
  102. if(this.backUser===true){
  103. if(this.storeVals && this.storeVals.length>0){
  104. let arr1 = this.storeVals.split(',')
  105. let arr2 = this.textVals.split(',')
  106. let info = []
  107. for(let i=0;i<arr1.length;i++){
  108. info.push({
  109. value: arr1[i],
  110. text: arr2[i]
  111. })
  112. }
  113. this.$emit('back', info)
  114. }
  115. }
  116. },
  117. onSearchDepUser() {
  118. this.$refs.selectModal.showModal()
  119. },
  120. selectOK(rows) {
  121. console.log("当前选中用户", rows)
  122. if (!rows) {
  123. this.storeVals = ''
  124. this.textVals = ''
  125. } else {
  126. let temp1 = []
  127. let temp2 = []
  128. for (let item of rows) {
  129. temp1.push(item[this.storeField])
  130. temp2.push(item[this.textField])
  131. }
  132. this.storeVals = temp1.join(',')
  133. this.textVals = temp2.join(',')
  134. }
  135. this.$emit("change", this.storeVals)
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped>
  141. </style>