riku
2023-10-31 2d3d56ff801b73afdb779267004d740f9beafe57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<template>
  <el-button icon="Plus" type="success" plain @click="openDialog"
    >新建方案</el-button
  >
  <el-dialog
    v-model="dialogShow"
    width="600px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    destroy-on-close
  >
    <template #header>
      <span> 新建方案</span>
    </template>
    <el-form
      label-width="90px"
      label-position="left"
      :rules="rules"
      :model="formObj"
      ref="formRef"
    >
      <el-form-item label="方案名称" prop="gsName">
        <el-input
          style="width: 400px"
          v-model="formObj.gsName"
          placeholder="请输入方案名称"
        ></el-input>
      </el-form-item>
      <el-form-item label="方案描述" prop="gsDescription">
        <el-input
          v-model="formObj.gsDescription"
          type="textarea"
          placeholder="请输入方案描述"
        ></el-input>
      </el-form-item>
      <el-form-item label="创建人" prop="gsCreatorName">
        <el-input
          style="width: 200px"
          v-model="formObj.gsCreatorName"
          placeholder="请输入创建人"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="onCancel">取消</el-button>
      <el-button
        :disabled="!edit"
        type="primary"
        :loading="loading"
        @click="onSubmit"
        >确定</el-button
      >
    </template>
  </el-dialog>
</template>
 
<script setup>
import { reactive, ref, watch } from 'vue';
import { useFormConfirm } from '@/composables/formConfirm';
import gridSchemeApi from '@/api/grid/gridSchemeApi';
 
const emit = defineEmits(['created']);
 
const rules = reactive({
  gsName: [
    {
      required: true,
      message: '方案名称不能为空',
      trigger: 'blur'
    }
  ]
});
 
const { formObj, formRef, edit, onSubmit, onCancel } = useFormConfirm(
  {
    submit: {
      do: submit
    },
    cancel: {
      do: cancel
    }
  }
);
 
const dialogShow = ref(false);
function openDialog() {
  dialogShow.value = true;
}
 
function submit() {
  return gridSchemeApi.createScheme(formObj.value).then(() => {
    // clear()
    emit('created')
    dialogShow.value = false;
  });
}
 
function cancel() {
  dialogShow.value = false;
}
</script>