马宇豪
2023-08-07 7ed4982b8f2a345bfad95a96070143c32142bc61
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<template>
    <div class="system-menu-dialog-container">
        <el-dialog :title="materialDialogState.title" v-model="materialDialogState.materialDialogVisible"  :close-on-click-modal="false" width="600px">
            <el-form ref="MaterialFormRef" :rules="materialDialogState.materialFormRules" :model="materialDialogState.materialForm" size="default" label-width="120px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="实验材料" prop="stuffName">
                            <el-input v-model="materialDialogState.materialForm.stuffName" placeholder="实验材料" clearable class="input-length"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="编号" prop="stuffCode">
                            <el-input v-model="materialDialogState.materialForm.stuffCode" placeholder="编号" clearable class="input-length"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="材料类型" prop="stuffType">
                            <el-select v-model="materialDialogState.materialForm.stuffType" placeholder="材料类型" clearable class="input-length">
                                <el-option v-for="item in materialDialogState.stuffTypeList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="材料储存" prop="stuffStorage">
                            <el-select v-model="materialDialogState.materialForm.stuffStorage" placeholder="材料储存" clearable class="input-length">
                                <el-option v-for="item in materialDialogState.stuffStorageList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="计量单位" prop="stuffUnit">
                            <el-select v-model="materialDialogState.materialForm.stuffUnit" placeholder="计量单位" clearable class="input-length">
                                <el-option v-for="item in materialDialogState.stuffUnitList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="materialDialogState.materialDialogVisible = !materialDialogState.materialDialogVisible" size="default">取 消</el-button>
                    <el-button type="primary" @click="onSubmitMaterial" size="default">确定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import { reactive, ref } from "vue";
import {useMenuApi} from "/@/api/systemManage/menu";
import {ElMessage} from "element-plus";
import {materialApi} from "/@/api/basic/material";
 
const MaterialFormRef = ref()
 
const materialDialogState = reactive<MaterialDialogType>({
    title: '',
    materialDialogVisible: false,
    materialForm: {
        stuffCode: '',
        stuffName: '',
        stuffStorage: null,
        stuffType: null,
        stuffUnit: null,
    },
    materialFormRules: {
        stuffCode: [{ required: true, message: '请填写实验材料', trigger: 'blur' }],
        stuffName: [{ required: true, message: '请填写编号', trigger: 'blur' }],
        stuffStorage: [{ required: true, message: '请选择材料类型', trigger: 'change' }],
        stuffType: [{ required: true, message: '请选择材料储存', trigger: 'change' }],
        stuffUnit: [{ required: true, message: '请选择计量单位', trigger: 'change' }]
    },
    stuffTypeList: [
        {id: 1, name: '化学试剂'},
        {id:2, name: '基础材料'}
    ],
    stuffStorageList: [
        {id:1, name: '智能试剂柜'},
        {id:2, name: '普通储存柜'},
    ],
    stuffUnitList: [
        {id:1, name: 'g'},
        {id:2, name: 'kg'},
        {id:3, name: 'ml'},
        {id:4, name: 'l'},
    ]
})
 
const showMaterialDialog = (title: string, value: MaterialType) => {
    materialDialogState.materialDialogVisible = true;
    setTimeout(() => {
        MaterialFormRef.value.clearValidate();
    });
    if(title === '新增'){
        materialDialogState.title = '新增';
        materialDialogState.materialForm = {
            stuffName: '',
            stuffCode: '',
            stuffType: null,
            stuffStorage: null,
            stuffUnit: null,
        };
    }else{
        materialDialogState.title = '编辑'
        materialDialogState.materialForm = {
            id: value.id,
            stuffName: value.stuffName,
            stuffCode: value.stuffCode,
            stuffType: value.stuffType,
            stuffStorage: value.stuffStorage,
            stuffUnit: value.stuffUnit,
        };
    }
};
 
const onSubmitMaterial = () => {
    MaterialFormRef.value.validate(async(valid: boolean) => {
        if(valid){
            if(materialDialogState.title === '新增'){
                let res = await materialApi().addMaterial(materialDialogState.materialForm);
                if(res.data.code === 100){
                    emit('refresh')
                    materialDialogState.materialDialogVisible = false;
                    ElMessage({
                        type: 'success',
                        message: '新增成功'
                    })
                }else{
                    ElMessage({
                        type: 'warning',
                        message: res.data.msg,
                    });
                }
            }else{
                let res = await materialApi().modMaterial(materialDialogState.materialForm)
                if(res.data.code === 100){
                    emit('refresh')
                    materialDialogState.materialDialogVisible = false;
                    ElMessage({
                        type: 'success',
                        message: '编辑成功'
                    })
                }else{
                    ElMessage({
                        type: 'warning',
                        message: res.data.msg,
                    });
                }
            }
        }else{
            ElMessage({
                type: 'warning',
                message: '请完善基本信息',
            });
        }
    })
}
 
const emit = defineEmits(['refresh'])
 
defineExpose({
    showMaterialDialog
})
</script>
 
<style scoped>
 
</style>