xm-inputselectuser-render.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div :class="$style.xmselinput">
  3. <a-input v-model="defaultValue" v-bind="$attrs" @blur="setinputvalue" />
  4. <a-button type="primary" @click="selectUser">选择</a-button>
  5. </div>
  6. </template>
  7. <script>
  8. import pickValues from '@/common/services/pick-values'
  9. import sdUserPicker from '@/common/components/sd-user-picker.vue'
  10. import components from './_import-components/xm-inputselectuser-render-import'
  11. export default {
  12. name: 'XmInputselectuserRender',
  13. metaInfo: {
  14. title: 'XmInputselectuserRender',
  15. },
  16. components,
  17. props: {
  18. userIdField: {
  19. type: String,
  20. default: '',
  21. },
  22. userAccountField: {
  23. type: String,
  24. default: '',
  25. },
  26. userNameField: {
  27. type: String,
  28. default: '',
  29. },
  30. },
  31. data() {
  32. return {
  33. defaultValue: '',
  34. }
  35. },
  36. inject: {
  37. SdFormContext: { default: () => {} },
  38. },
  39. mounted() {
  40. const name = this.SdFormContext.getFieldValue(this.userNameField)
  41. if (name) {
  42. this.defaultValue = name
  43. }
  44. },
  45. methods: {
  46. selectUser() {
  47. pickValues(
  48. sdUserPicker, // 第一个参数:使用的选择器组件
  49. // 第二个参数:传递给选择器的props。默认选中的值、是否单选等,都可以传递
  50. {
  51. single: false,
  52. }
  53. )
  54. // 用户选择完成后,promise返回选中的值。用户取消返回undefined
  55. .then((values) => {
  56. let ids = '' // 人员id
  57. let accounts = '' // 人员account
  58. let names = '' // 人员name
  59. values?.forEach((item) => {
  60. // 人员id
  61. if (ids === '') {
  62. ids = item.code
  63. } else {
  64. ids = ids + ',' + item.code
  65. }
  66. // 人员account
  67. if (accounts === '') {
  68. accounts = item.code
  69. } else {
  70. accounts = accounts + ',' + item.code
  71. }
  72. // 人员name
  73. if (names === '') {
  74. names = item.name
  75. } else {
  76. names = names + ',' + item.name
  77. }
  78. })
  79. this.SdFormContext.setFieldValue(this.userIdField, ids)
  80. this.SdFormContext.setFieldValue(this.userAccountField, accounts)
  81. this.SdFormContext.setFieldValue(this.userNameField, names)
  82. this.defaultValue = names
  83. this.$emit('input', names)
  84. })
  85. },
  86. setinputvalue(val) {
  87. if (this.defaultValue) {
  88. this.SdFormContext.setFieldValue(this.userIdField, '')
  89. this.SdFormContext.setFieldValue(this.userAccountField, '')
  90. this.SdFormContext.setFieldValue(this.userNameField, this.defaultValue)
  91. this.$emit('input', this.defaultValue)
  92. }
  93. },
  94. },
  95. }
  96. </script>
  97. <style module lang="scss">
  98. @use '@/common/design' as *;
  99. .xmselinput {
  100. :global .ant-input {
  101. width: 70%;
  102. margin-right: 10px;
  103. }
  104. :global .ant-btn {
  105. width: auto;
  106. padding: 0 10px;
  107. }
  108. }
  109. </style>