people.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <CusDialog
  3. title="新增人员"
  4. :show="show"
  5. @close="$emit('update:show', false)"
  6. @submit="onSubmit"
  7. width="400px"
  8. maxHeight="80%"
  9. footAlign="right"
  10. >
  11. <div class="__normal-form">
  12. <CusForm labelWidth="100px" ref="ref_form">
  13. <CusFormColumn
  14. :span="24"
  15. required
  16. label="单位:"
  17. link="select"
  18. v-model:param="cusDetail.deptId"
  19. :options="$store.state.dictionary.deptList"
  20. :disabled="true"/>
  21. <CusFormColumn
  22. :span="24"
  23. required
  24. label="值班人员:"
  25. v-model:param="cusDetail.peopleId"
  26. link="select"
  27. static
  28. labelKey="displayName"
  29. valueKey="id"
  30. multiple
  31. :options="peopleList"
  32. :isLoading="loadingPeople"
  33. @getObject="getPeopleObj"/>
  34. </CusForm>
  35. </div>
  36. </CusDialog>
  37. </template>
  38. <script lang="ts">
  39. import {
  40. defineComponent,
  41. computed,
  42. onMounted,
  43. ref,
  44. reactive,
  45. watch,
  46. getCurrentInstance,
  47. ComponentInternalInstance,
  48. toRefs,
  49. nextTick
  50. } from 'vue'
  51. import {useStore} from 'vuex'
  52. import {useRouter, useRoute} from 'vue-router'
  53. import {ElMessage, ElMessageBox} from "element-plus";
  54. export default defineComponent({
  55. name: '',
  56. components: {},
  57. props: {
  58. show: {},
  59. transfer: <any>{}
  60. },
  61. setup(props, {emit}) {
  62. const store = useStore();
  63. const router = useRouter();
  64. const route = useRoute();
  65. const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
  66. const state = reactive({
  67. cusDetail: <any>{},
  68. peopleList: {},
  69. selectPeopleList: [],
  70. selectUserId: [],
  71. loadingPeople: false
  72. })
  73. const ref_form = ref()
  74. watch(() => props.show, (n) => {
  75. if (n) {
  76. state.cusDetail = {
  77. deptId: props.transfer.deptId,
  78. peopleId: []
  79. }
  80. state.selectUserId = props.transfer.selectUserId
  81. getPeople()
  82. nextTick(() => {
  83. ref_form.value.reset()
  84. })
  85. }
  86. })
  87. const getPeople = () => {
  88. state.loadingPeople = true
  89. state.peopleList = []
  90. that.$api.getSeatDutyUnitPersonList({externalId: store.state.dictionary.deptMap.get(state.cusDetail.deptId).externalId}).then(res => {
  91. if (res.code === 200) {
  92. state.peopleList = res.data.filter(v => !state.selectUserId.includes(v.id))
  93. } else {
  94. ElMessage.error(res.message)
  95. }
  96. state.loadingPeople = false
  97. }).catch(() => {
  98. state.loadingPeople = false
  99. })
  100. }
  101. const onSubmit = () => {
  102. ref_form.value.submit().then(() => {
  103. emit('getPeople', state.selectPeopleList)
  104. emit('update:show', false)
  105. }).catch((e) => {
  106. ElMessage({
  107. message: e[0].message,
  108. grouping: true,
  109. type: 'warning',
  110. })
  111. })
  112. }
  113. const getPeopleObj = (arr) => {
  114. state.selectPeopleList = arr.map(v => {
  115. const obj = {
  116. linkPhone: v.phoneNumber,
  117. name: v.displayName,
  118. accountId: v.id
  119. }
  120. return obj
  121. })
  122. }
  123. return {
  124. ...toRefs(state),
  125. onSubmit,
  126. ref_form,
  127. getPeopleObj
  128. }
  129. },
  130. })
  131. </script>
  132. <style scoped lang="scss">
  133. </style>