index.vue
4.88 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
<template>
<div class="app-container">
<el-tabs v-model="activeName">
<el-tab-pane v-for="c in cert_type" :key="c.value" :label="c.label" :name="c.value">
<el-card>
<el-form
ref="certConfigRef" :model="form" :rules="rules" label-width="100px" label-suffix=":"
>
<!-- <el-form-item label="发布方式" prop="pushType">-->
<!-- <el-radio-group v-model="form.pushType">-->
<!-- <el-radio label="0">自动发布</el-radio>-->
<!-- <el-radio label="1">手动发布</el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="发布时间" prop="days">-->
<!-- <el-input v-model="form.days" type="number" placeholder="如输入0,则为立即发布" style="width: 340px">-->
<!-- <template #prepend>审批通过</template>-->
<!-- <template #append>天</template>-->
<!-- </el-input>-->
<!-- </el-form-item>-->
<el-form-item label-width="0" prop="templateName">
<el-radio-group v-model="form.templateName">
<div v-for="t in templateArr" :key="t.name">
<el-image :src="fillImgUrl(t.picUrl)" style="width: 150px;height: 150px"/>
<br>
<el-radio :label="t.name">{{ t.name }}</el-radio>
</div>
</el-radio-group>
</el-form-item>
</el-form>
<div class="text-center mt20">
<el-button type="primary" style="width: 180px" size="large" @click="submitForm">保 存</el-button>
</div>
</el-card>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script setup name="Cert">
import { getCurrentInstance, ref, toRefs, watch } from 'vue'
import { addCertConfig, getCertConfigByType, updateCertConfig } from '@/api/system/certConfig'
import { reactive } from '@vue/runtime-core'
import _ from 'lodash'
const { proxy } = getCurrentInstance()
const { cert_type } = proxy.useDict('cert_type')
const activeName = ref('')
const templateArr = ref([])
const data = reactive({
form: {
pushType: '1',
days: 0
},
rules: {
pushType: [
{ required: true, message: '发布方式不能为空', trigger: 'change' }
],
days: [
{ required: true, message: '发布时间不能为空', trigger: 'blur' }
],
templateName: [
{ required: true, message: '模板不能为空', trigger: 'change' }
]
}
})
const { form, rules } = toRefs(data)
watch(cert_type, (val) => {
if (val && val.length > 0) {
activeName.value = val[0].value
}
}, { immediate: true })
let index = 0
watch(activeName, (val) => {
if (!val) {
return
}
switch (val) {
case '20001':
index = 0
templateArr.value = [
{ name: '模板一', picUrl: '', pdfUrl: '' }
// { name: '模板二', picUrl: '', pdfUrl: '' },
// { name: '模板三', picUrl: '', pdfUrl: '' }
]
break
case '20002':
index = 1
templateArr.value = [
{ name: '模板一', picUrl: '', pdfUrl: '' }
// { name: '模板五', picUrl: '', pdfUrl: '' },
// { name: '模板六', picUrl: '', pdfUrl: '' }
]
break
case '20003':
index = 2
templateArr.value = [
{ name: '模板一', picUrl: '', pdfUrl: '' }
// { name: '模板八', picUrl: '', pdfUrl: '' },
// { name: '模板九', picUrl: '', pdfUrl: '' }
]
break
case '20004':
index = 3
templateArr.value = [
{ name: '模板一', picUrl: '', pdfUrl: '' }
// { name: '模板十一', picUrl: '', pdfUrl: '' },
// { name: '模板十二', picUrl: '', pdfUrl: '' }
]
break
}
getCertConfigByType(val).then((res) => {
if (res.data.length > 0) {
const template = JSON.parse(res.data[0].template)
form.value = {
templateName: template.name,
...res.data[0]
}
} else {
form.value = {
certType: val,
status: '0',
pushType: '1',
days: 0
}
_.each(proxy.$refs['certConfigRef'], (ref) => {
ref.resetFields()
})
}
})
}, { immediate: true })
function submitForm() {
proxy.$refs['certConfigRef'][index].validate(valid => {
if (valid) {
form.value.template = JSON.stringify(_.find(templateArr.value, (t) => {
return t.name === form.value.templateName
}))
if (form.value.certId) {
updateCertConfig(form.value).then(response => {
proxy.$modal.msgSuccess('修改成功')
})
} else {
addCertConfig(form.value).then((res) => {
proxy.$modal.msgSuccess('新增成功')
form.value.certId = res.data
})
}
}
})
}
</script>