PositionSetting.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <el-dialog v-model="showDialog" class="add-position-dialog" title="岗位职责设置" width="800" destroy-on-close>
  3. <el-form :model="formData" ref="ruleFormRef" :rules="rules">
  4. <el-table :data="formData" border v-loading="showLoading">
  5. <el-table-column align="center" prop="positionLevel" width="200" label="等级" />
  6. <el-table-column align="center" label="岗位职责名称">
  7. <template #default="{ row, $index }">
  8. <el-form-item :prop="`[${$index}].title`" :rules="rules.title">
  9. <el-input class="position-title" v-model="row.title" />
  10. </el-form-item>
  11. </template>
  12. </el-table-column>
  13. <el-table-column align="center" width="200" label="操作">
  14. <template #default="{ $index }">
  15. <el-button v-if="$index + 1 === formData.length" @click="addRow">添加</el-button>
  16. <el-button v-if="formData.length > 1" @click="deleteRow($index)">删除</el-button>
  17. </template>
  18. </el-table-column>
  19. </el-table>
  20. </el-form>
  21. <template #footer>
  22. <div v-if="!showLoading" class="dialog-footer">
  23. <el-button type="primary" @click="submitForm"> 提交 </el-button>
  24. <el-button @click="showDialog = false">取消</el-button>
  25. </div>
  26. </template>
  27. </el-dialog>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref, watch } from 'vue';
  31. import { storeToRefs } from 'pinia';
  32. import type { FormInstance, FormRules } from 'element-plus';
  33. import useTeamStore from '../../store/userTeam';
  34. import { PositionType, queryTeamPositionList } from '@/api/emergency-organization/teams';
  35. const { curTeam } = storeToRefs(useTeamStore());
  36. const { setPositionInfo } = useTeamStore();
  37. const showDialog = ref(false);
  38. const showLoading = ref(true);
  39. const formData = ref<PositionType[]>([
  40. {
  41. positionLevel: 1,
  42. title: '',
  43. },
  44. ]);
  45. const ruleFormRef = ref<FormInstance>();
  46. const rules = ref<FormRules<PositionType>>({
  47. title: [{ required: true, message: '请输入岗位', trigger: 'blur' }],
  48. });
  49. function dialogShow() {
  50. showDialog.value = true;
  51. }
  52. function addRow() {
  53. formData.value.push({ positionLevel: formData.value.length + 1, title: '' });
  54. }
  55. function deleteRow(index: number) {
  56. formData.value.splice(index, 1);
  57. formData.value.forEach((row, index) => (row.positionLevel = index + 1));
  58. }
  59. async function submitForm() {
  60. await ruleFormRef.value!.validate((valid) => {
  61. if (valid) {
  62. setPositionInfo(formData.value);
  63. showDialog.value = false;
  64. }
  65. });
  66. }
  67. watch(
  68. () => showDialog.value,
  69. async () => {
  70. if (showDialog.value && curTeam.value?.teamId) {
  71. const res = await queryTeamPositionList(curTeam.value.teamId);
  72. formData.value = res.map((position) => {
  73. return { id: position.id, positionLevel: position.positionLevel, title: position.title };
  74. });
  75. if (!formData.value.length) {
  76. formData.value.push({
  77. positionLevel: 1,
  78. title: '',
  79. });
  80. }
  81. showLoading.value = false;
  82. } else showLoading.value = true;
  83. },
  84. );
  85. defineExpose({
  86. dialogShow,
  87. });
  88. </script>
  89. <style scoped lang="scss"></style>
  90. <style>
  91. .add-position-dialog {
  92. min-height: 0;
  93. .el-table .cell {
  94. overflow: visible;
  95. }
  96. .el-table__row > :nth-child(2) {
  97. .cell {
  98. height: 35px;
  99. margin-top: 2px;
  100. }
  101. }
  102. }
  103. </style>