PersonalInfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="title"> 人员信息 </div>
  3. <el-button type="primary" @click="showPositionSetting"> 职位设置 </el-button>
  4. <el-button type="primary" @click="showAddPerson"> 添加人员 </el-button>
  5. <div class="person-info-table">
  6. <el-table :data="tableData" border max-height="700">
  7. <el-table-column prop="date" label="序号">
  8. <template #default="scope">
  9. {{ scope.$index + 1 }}
  10. </template>
  11. </el-table-column>
  12. <el-table-column prop="title" label="岗位职责" />
  13. <el-table-column prop="realname" label="姓名" />
  14. <el-table-column prop="staffNo" label="员工号" />
  15. <el-table-column prop="mobile" label="联系方式" />
  16. <el-table-column prop="department" label="部门" />
  17. <el-table-column prop="jobTitle" label="职务" />
  18. <el-table-column fixed="right" label="操作">
  19. <template #default="scope">
  20. <el-button link type="primary" size="small" @click.prevent="editRow(scope.row)"> 编辑 </el-button>
  21. <el-button link type="primary" size="small" @click.prevent="deleteRow(scope.row)"> 删除 </el-button>
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. </div>
  26. <PositionSetting ref="positionSettingRef" />
  27. <AddPerson ref="addPersonRef" :position-options="positionOptions" />
  28. <EditPerson ref="editPersonRef" :position-options="positionOptions" :person-info="editPersonInfo" />
  29. </template>
  30. <script lang="ts" setup>
  31. import { ref, watch } from 'vue';
  32. import { ElMessageBox, ElMessage } from 'element-plus';
  33. import { storeToRefs } from 'pinia';
  34. import { TeamPersonnelInfoType } from '../../type';
  35. import PositionSetting from './PositionSetting.vue';
  36. import useTeamStore from '../../store/userTeam';
  37. import AddPerson from './AddPerson.vue';
  38. import EditPerson from './EditPerson.vue';
  39. import { PositionType, queryTeamPositionList, deleteTeamPersonnel } from '@/api/emergency-organization/teams';
  40. const { teamAndPersonInfo, loadingTeamInfo } = storeToRefs(useTeamStore());
  41. const { refreshCurTeamInfo } = useTeamStore();
  42. const tableData = ref<TeamPersonnelInfoType[]>([]);
  43. const positionSettingRef = ref<InstanceType<typeof PositionSetting>>();
  44. const addPersonRef = ref<InstanceType<typeof AddPerson>>();
  45. const editPersonRef = ref<InstanceType<typeof EditPerson>>();
  46. const positionOptions = ref<PositionType[]>([]);
  47. const editPersonInfo = ref({
  48. id: 0,
  49. userId: 0,
  50. positionId: '',
  51. realname: '',
  52. staffNo: '',
  53. mobile: '',
  54. department: '',
  55. jobTitle: '',
  56. });
  57. async function editRow(row) {
  58. if (!(await positionIsSet())) return;
  59. editPersonInfo.value = {
  60. id: row.id,
  61. userId: row.userId,
  62. positionId: row.positionId,
  63. realname: row.realname,
  64. staffNo: row.staffNo,
  65. mobile: row.mobile,
  66. department: row.department,
  67. jobTitle: row.jobTitle,
  68. };
  69. editPersonRef.value?.dialogShow();
  70. }
  71. function deleteRow(row) {
  72. ElMessageBox.confirm('是否确认删除该人员').then(async () => {
  73. loadingTeamInfo.value = true;
  74. await deleteTeamPersonnel(row.id);
  75. await refreshCurTeamInfo();
  76. loadingTeamInfo.value = false;
  77. });
  78. }
  79. function showPositionSetting() {
  80. positionSettingRef.value?.dialogShow();
  81. }
  82. async function showAddPerson() {
  83. if (!(await positionIsSet())) return;
  84. addPersonRef.value?.dialogShow();
  85. }
  86. async function positionIsSet() {
  87. loadingTeamInfo.value = true;
  88. positionOptions.value = await queryTeamPositionList(teamAndPersonInfo.value!.teamId);
  89. loadingTeamInfo.value = false;
  90. if (positionOptions.value.length === 0) {
  91. ElMessage({
  92. message: '请先设置职位',
  93. type: 'warning',
  94. });
  95. return false;
  96. }
  97. return true;
  98. }
  99. watch(
  100. () => teamAndPersonInfo.value,
  101. () => {
  102. tableData.value = teamAndPersonInfo.value?.personnelList || [];
  103. },
  104. );
  105. </script>
  106. <style scoped lang="scss">
  107. .person-info-table {
  108. margin-top: 15px;
  109. }
  110. </style>