EditGroup.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <Dialog draggable custom-show :title="groupForm.group_id ? '编辑分组' : '添加分组'" type="xs" height="auto" hide-footer @close="handleClose">
  3. <div class="form-item">
  4. <div class="text1">分组名称</div>
  5. <el-input v-model="groupForm.group_name" class="custom-input" placeholder="请输入" />
  6. </div>
  7. <div class="form-action">
  8. <div v-if="!groupForm.group_id" class="common-btn-primary" @click="handleAddGroup">保存</div>
  9. <div v-else class="common-btn-primary" @click="handleUpdateGroup">保存</div>
  10. <div v-if="groupForm.group_id" class="common-btn-primary" @click="handleDeleteGroup">删除</div>
  11. <div class="common-btn" @click="handleClose">取消</div>
  12. </div>
  13. </Dialog>
  14. </template>
  15. <script lang="ts" setup>
  16. import { addGroup, delGroup, getGroupInfo, updateGroup } from '@/api/globalMap/onlinePlotting';
  17. import { showSuccessMsg } from '@/utils/notification';
  18. const props = defineProps({
  19. modelValue: Boolean,
  20. patternId: String,
  21. groupId: String
  22. });
  23. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  24. const emits = defineEmits(['update:modelValue', 'change']);
  25. let groupForm = ref({
  26. group_id: '',
  27. group_name: ''
  28. });
  29. watch(
  30. () => props.groupId,
  31. () => {
  32. if (!!props.groupId) {
  33. // 获取详情
  34. getGroupInfo(props.groupId).then((res) => {
  35. groupForm.value = res.data;
  36. });
  37. }
  38. },
  39. {
  40. immediate: true
  41. }
  42. );
  43. // 新增分组
  44. const handleAddGroup = () => {
  45. const obj = {
  46. group_name: groupForm.value.group_name,
  47. pattern_id: props.patternId
  48. };
  49. addGroup(obj).then(() => {
  50. emits('change');
  51. showSuccessMsg('新增成功');
  52. handleClose();
  53. });
  54. };
  55. // 修改分组
  56. const handleUpdateGroup = () => {
  57. updateGroup(groupForm.value).then(() => {
  58. emits('change');
  59. showSuccessMsg('修改成功');
  60. handleClose();
  61. });
  62. };
  63. // 关闭弹窗
  64. const handleClose = () => {
  65. emits('update:modelValue', false);
  66. };
  67. // 删除分组
  68. const handleDeleteGroup = async () => {
  69. await proxy?.$modal.confirm('您确定要删除该分组?');
  70. delGroup(groupForm.value.group_id).then(() => {
  71. showSuccessMsg('删除成功');
  72. emits('change');
  73. handleClose();
  74. });
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .form-item {
  79. display: flex;
  80. align-items: center;
  81. .text1 {
  82. flex-shrink: 0;
  83. margin-right: 10px;
  84. }
  85. .custom-input {
  86. flex: 1;
  87. }
  88. }
  89. .form-action {
  90. display: flex;
  91. align-items: center;
  92. justify-content: center;
  93. }
  94. </style>