Form.vue
8.43 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll append-to-body width="600px">
<el-row :gutter="15" class="" >
<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="isDetail === true" :rules="rules">
<el-col :span="24">
<el-form-item label="培训名称" prop="pxmc">
<el-input v-model="dataForm.pxmc" placeholder="请输入培训名称" clearable :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="关联产品" prop="sssb">
<el-select v-model="sssbValue" placeholder="请选择关联产品" clearable filterable @change="handleSssbChange" :style='{"width":"100%"}' >
<el-option v-for="item in cpglOptions" :key="item.id || item.cpid" :label="item.cpmc" :value="item.id || item.cpid">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备名称" prop="sbmc">
<el-input v-model="dataForm.sbmc" placeholder="自动填充" readonly :style='{"width":"100%"}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发布时间" prop="fbsj">
<el-date-picker v-model="dataForm.fbsj" placeholder="请选择" clearable :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
</el-date-picker>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="概要" prop="gy">
<el-input v-model="dataForm.gy" placeholder="请输入概要" clearable :style='{"width":"100%"}' type="textarea" :rows="3" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="分类" prop="fl">
<el-select v-model="dataForm.fl" placeholder="请选择分类" clearable :style='{"width":"100%"}' >
<el-option label="安装" value="安装" />
<el-option label="维修" value="维修" />
<el-option label="保养" value="保养" />
<el-option label="检查" value="检查" />
<el-option label="操作" value="操作" />
<el-option label="理论" value="理论" />
<el-option label="其他" value="其他" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="详情" prop="jj">
<NCC-Quill v-model="dataForm.jj" placeholder="请输入内容..." >
</NCC-Quill>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="缩略图" prop="slt">
<NCC-UploadImg v-model="dataForm.slt" :fileSize="1" sizeUnit="GB" :limit="9" >
</NCC-UploadImg>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="展示附件" prop="fj1">
<NCC-UploadFz v-model="dataForm.fj1" :fileSize="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
</NCC-UploadFz>
</el-form-item>
</el-col>
</el-form>
</el-row>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
import { previewDataInterface } from '@/api/systemData/dataInterface'
export default {
components: {},
props: [],
data() {
return {
loading: false,
visible: false,
isDetail: false,
dataForm: {
id: '',
pxmc: undefined,
sbmc: undefined,
fbsj: undefined,
gy: undefined,
fl: undefined,
jj: undefined,
fj1: [],
slt: [],
sssb: undefined
},
cpglOptions: [],
sssbValue: '',
rules: {
},
}
},
computed: {},
watch: {
visible(val) {
if (!val) {
// 对话框关闭时,重置 isDetail 为 false
this.isDetail = false
}
}
},
created() {
this.getCpglOptions()
},
mounted() {
},
methods: {
async getCpglOptions() {
try {
const res = await request({
url: '/api/Extend/Cpgl',
method: 'GET',
data: {
currentPage: 1,
pageSize: 1000,
sort: 'desc',
sidx: ''
}
})
if (res.data && res.data.list) {
this.cpglOptions = res.data.list
}
} catch (error) {
console.error('获取产品选项失败:', error)
}
},
handleSssbChange(value) {
this.dataForm.sssb = value && value !== '' ? value : null
// 自动填充设备名称
if (value) {
const product = this.cpglOptions.find(item => {
const id = String(item.id || item.cpid || '')
return id === String(value)
})
if (product && product.cpmc) {
this.dataForm.sbmc = product.cpmc
}
} else {
this.dataForm.sbmc = undefined
}
},
goBack() {
this.$emit('refresh')
},
init(id, isDetail) {
// 强制重置 isDetail,确保表单可编辑
this.isDetail = false;
// 如果明确传入 isDetail 为 true,才设置为详情模式
if (isDetail === true) {
this.isDetail = true;
}
this.dataForm.id = id || 0;
console.log('Pxzs Form init - id:', id, 'isDetail:', this.isDetail);
this.visible = true;
this.$nextTick(() => {
this.$refs['elForm'].resetFields();
if (this.dataForm.id) {
request({
url: '/api/Extend/Pxzs/' + this.dataForm.id,
method: 'get'
}).then(res =>{
this.dataForm = res.data;
if(!this.dataForm.fj1)this.dataForm.fj1=[];
// 设置关联产品选择值
this.sssbValue = this.dataForm.sssb || ''
// 如果有关联产品,自动填充设备名称
if (this.dataForm.sssb) {
this.handleSssbChange(this.dataForm.sssb)
}
})
} else {
// 新建时重置
this.sssbValue = ''
this.dataForm.sssb = undefined
this.dataForm.sbmc = undefined
}
})
},
dataFormSubmit() {
this.$refs['elForm'].validate((valid) => {
if (valid) {
// 确保 sssb 字段正确设置
this.dataForm.sssb = this.sssbValue && this.sssbValue !== '' ? this.sssbValue : null
console.log('提交数据前,sssbValue:', this.sssbValue);
console.log('提交数据前,dataForm.sssb:', this.dataForm.sssb);
console.log('完整提交数据:', JSON.stringify(this.dataForm, null, 2));
if (!this.dataForm.id) {
request({
url: `/api/Extend/Pxzs`,
method: 'post',
data: this.dataForm,
}).then((res) => {
console.log('新建成功,响应:', res);
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false,
this.$emit('refresh', true)
}
})
})
} else {
console.log('更新数据前,sssbValue:', this.sssbValue);
console.log('更新数据前,dataForm.sssb:', this.dataForm.sssb);
console.log('完整更新数据:', JSON.stringify(this.dataForm, null, 2));
request({
url: '/api/Extend/Pxzs/' + this.dataForm.id,
method: 'PUT',
data: this.dataForm
}).then((res) => {
console.log('更新成功,响应:', res);
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false
this.$emit('refresh', true)
}
})
})
}
}
})
},
}
}
</script>