8a8ceba3ce94502d06e486c76c4ef3642ba7803d.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="components-input-demo-presuffix">
  3. <!---->
  4. <a-input @click="openModal" placeholder="请点击选择部门" v-model="textVals" readOnly :disabled="disabled">
  5. <a-icon slot="prefix" type="cluster" title="部门选择控件"/>
  6. <a-icon v-if="storeVals" slot="suffix" type="close-circle" @click="handleEmpty" title="清空"/>
  7. </a-input>
  8. <j-select-depart-modal
  9. ref="innerDepartSelectModal"
  10. :modal-width="modalWidth"
  11. :multi="multi"
  12. :rootOpened="rootOpened"
  13. :depart-id="value"
  14. :store="storeField"
  15. :text="textField"
  16. :treeOpera="treeOpera"
  17. @ok="handleOK"
  18. @initComp="initComp"/>
  19. </div>
  20. </template>
  21. <script>
  22. import JSelectDepartModal from './modal/JSelectDepartModal'
  23. import { underLinetoHump } from '@/components/_util/StringUtil'
  24. export default {
  25. name: 'JSelectDepart',
  26. components:{
  27. JSelectDepartModal
  28. },
  29. props:{
  30. modalWidth:{
  31. type:Number,
  32. default:500,
  33. required:false
  34. },
  35. multi:{
  36. type:Boolean,
  37. default:false,
  38. required:false
  39. },
  40. rootOpened:{
  41. type:Boolean,
  42. default:true,
  43. required:false
  44. },
  45. value:{
  46. type:String,
  47. required:false
  48. },
  49. disabled:{
  50. type: Boolean,
  51. required: false,
  52. default: false
  53. },
  54. // 自定义返回字段,默认返回 id
  55. customReturnField: {
  56. type: String,
  57. default: ''
  58. },
  59. backDepart: {
  60. type: Boolean,
  61. default: false,
  62. required: false
  63. },
  64. // 存储字段 [key field]
  65. store: {
  66. type: String,
  67. default: 'id',
  68. required: false
  69. },
  70. // 显示字段 [label field]
  71. text: {
  72. type: String,
  73. default: 'departName',
  74. required: false
  75. },
  76. treeOpera: {
  77. type: Boolean,
  78. default: false,
  79. required: false
  80. }
  81. },
  82. data(){
  83. return {
  84. visible:false,
  85. confirmLoading:false,
  86. storeVals: '', //[key values]
  87. textVals: '' //[label values]
  88. }
  89. },
  90. computed:{
  91. storeField(){
  92. let field = this.customReturnField
  93. if(!field){
  94. field = this.store;
  95. }
  96. return underLinetoHump(field)
  97. },
  98. textField(){
  99. return underLinetoHump(this.text)
  100. }
  101. },
  102. mounted(){
  103. this.storeVals = this.value
  104. },
  105. watch:{
  106. value(val){
  107. this.storeVals = val
  108. }
  109. },
  110. methods:{
  111. initComp(textVals){
  112. this.textVals = textVals
  113. },
  114. //返回选中的部门信息
  115. backDeparInfo(){
  116. if(this.backDepart===true){
  117. if(this.departIds && this.departIds.length>0){
  118. let arr1 = this.storeVals.split(',')
  119. let arr2 = this.textVals.split(',')
  120. let info = []
  121. for(let i=0;i<arr1.length;i++){
  122. info.push({
  123. value: arr1[i],
  124. text: arr2[i]
  125. })
  126. }
  127. this.$emit('back', info)
  128. }
  129. }
  130. },
  131. openModal(){
  132. this.$refs.innerDepartSelectModal.show()
  133. },
  134. handleOK(rows) {
  135. if (!rows && rows.length <= 0) {
  136. this.textVals = ''
  137. this.storeVals = ''
  138. } else {
  139. let arr1 = []
  140. let arr2 = []
  141. for(let dep of rows){
  142. arr1.push(dep[this.storeField])
  143. arr2.push(dep[this.textField])
  144. }
  145. this.storeVals = arr1.join(',')
  146. this.textVals = arr2.join(',')
  147. }
  148. this.$emit("change", this.storeVals)
  149. this.backDeparInfo()
  150. },
  151. getDepartNames(){
  152. return this.departNames
  153. },
  154. handleEmpty(){
  155. this.handleOK('')
  156. }
  157. },
  158. model: {
  159. prop: 'value',
  160. event: 'change'
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .components-input-demo-presuffix .anticon-close-circle {
  166. cursor: pointer;
  167. color: #ccc;
  168. transition: color 0.3s;
  169. font-size: 12px;
  170. }
  171. .components-input-demo-presuffix .anticon-close-circle:hover {
  172. color: #f5222d;
  173. }
  174. .components-input-demo-presuffix .anticon-close-circle:active {
  175. color: #666;
  176. }
  177. </style>