张诺
4 天以前 d8fead89b61acd2b1462559c2fa634b05f73c5d1
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
  <div>
    <el-dialog v-model="dialogVisible" :title="title" width="600" :close-on-click-modal="false"
      :before-close="handleClose">
      <el-form ref="formRef" style="max-width: 400px; margin: 0 auto" :model="formData" :rules="rules"
        label-width="auto">
        <el-form-item label="方案名称" prop="schemeName">
          <el-input v-model="formData.schemeName" placeholder="请输入方案名称"  prop="schemeName" />
        </el-form-item>
        <el-form-item label="方案类型" props="fieldName">
          <el-select v-model="formData.fieldName" placeholder="Select" style="width: 240px" clearable multiple>
            <template #label="{ label }">
              <span>{{ label }}: </span>
              <span style="font-weight: bold">{{ value }}</span>
            </template>
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <template #footer>
          <el-form-item label="字段描述" prop="fieldDescription">
            <el-input v-model="formData.fieldDescription" type="textarea" placeholder="请输入字段描述" />
          </el-form-item>
 
        </template>
        <el-form-item>
          <el-button type="primary" @click="submitForm"> 确定 </el-button>
          <el-button v-if="addOrEdit === 'edit'" @click="resetForm">重置</el-button>
          <el-button v-if="addOrEdit === 'add'" @click="cancelForm">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { ref, watch, defineProps, onMounted } from "vue";
import addressList from "@/api/jsonApi/areaList.json";
const props = defineProps({
  beforeClose: {
    type: Function,
    default: () => { },
  },
  form: {
    type: Object,
    default: () => ({}),
  },
  addOrEdit: {
    type: String,
    default: "add",
  },
  title: {
    type: String,
    default: "",
  },
});
const options = [
  {
    value: 'Option1',
    label: 'Label1',
  },
  {
    value: 'Option2',
    label: 'Label2',
  },
  {
    value: 'Option3',
    label: 'Label3',
  },
  {
    value: 'Option4',
    label: 'Label4',
  },
  {
    value: 'Option5',
    label: 'Label5',
  },
]
const emit = defineEmits(["submit", "handleBeforeClose"]);
 
// 表单数据
const formData = ref({ ...props.form });
// 弹窗可见性
const dialogVisible = defineModel("coalQualityMaintenanceDialogFormVisible", {
  required: true,
  type: Boolean,
});
// 提交表单
const submitForm = async () => {
  if (!formRef.value) return;
  await formRef.value.validate(async (valid, fields) => {
    if (valid) {
      // let result = await addOrEditCoalQuality({...formData.value});
      // console.log(result);
      // emit("submit", formData.value);
    }
  });
};
// 取消表单
const cancelForm = () => {
  emit("update:coalQualityMaintenanceDialogFormVisible", false);
  formData.value = {};
};
// 重置表单
const resetForm = () => {
  if (!formRef.value) return;
  formRef.value.resetFields();
};
// 关闭弹窗
const handleClose = () => {
  // 触发父组件的关闭函数
  emit("handleBeforeClose");
  emit("update:coalQualityMaintenanceDialogFormVisible", false);
};
const rules = reactive({
  coal: [
    { required: true, message: "请输入煤种名称", trigger: "blur" },
  ],
});
</script>
<style lang="sass" scoped>
</style>