zhouwx
2025-06-13 49aee4d0b0b71c844f50e34479b7acd07f667f83
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
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="550px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-form :model="state.form" size="default" ref="busRef" :rules="state.formRules" label-width="150px" >
        <el-form-item label="取得资质证书名称:" prop="certificateName" >
          <el-input v-model="state.form.certificateName" :disabled="title === '查看'"  placeholder="请输入取得资质证书名称"/>
        </el-form-item>
        <el-form-item label="证书编号:" prop="certificateNum" >
          <el-input v-model="state.form.certificateNum" :disabled="title === '查看'" placeholder="请输入证书编号"/>
        </el-form-item>
        <el-form-item label="有效期:" prop="effectiveTime" >
          <el-date-picker
              :disabled="title === '查看'"
              v-model="state.form.effectiveTime"
              type="date"
              placeholder="请选择截止日期"
              style="width: 100%"
              value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item label="证书附件:" prop="filePath" >
          <el-upload
              :disabled="title === '查看'"
              style="width: 100%;"
              accept=".pdf"
              :action="state.uploadUrl"
              :headers="state.header"
              method="post"
              :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)"
              :on-exceed="showTip"
              v-model:file-list="state.fileList"
              :on-remove="handleRemove"
              :limit='1'
              :before-upload="picSize"
          >
            <el-button type="primary">证书上传</el-button>
            <template #tip>
              <div class="el-upload__tip">上传文件尺寸小于15M,最多可上传1份</div>
            </template>
          </el-upload>
        </el-form-item>
 
      </el-form>
      <template #footer v-if="title !== '查看'">
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmit" size="default" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {reactive, ref, toRefs} from 'vue'
import Editor from "@/components/Editor/index.vue";
import {ElMessage, ElMessageBox} from "element-plus";
import {addNotice} from "@/api/backManage/notice";
import {addDict, editDict, getDictDetail} from "@/api/backManage/evaluate";
import {addCompany, checkName, distributeCompany, editCompany} from "@/api/onlineEducation/company";
import {verifyPhone} from "@/utils/validate";
import {getToken} from "@/utils/auth";
import {addQualification, editQualification} from "@/api/companyInfo/qualifications";
import Cookies from "js-cookie";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const state = reactive({
  form: {
    id: '',
    companyId: '',
    certificateName: '',
    certificateNum: '',
    effectiveTime: '',
    filePath: '',
    fileName: ''
  },
  formRules:{
    certificateName:[{ required: true, message: '请输入取得资质证书名称', trigger: 'blur' }],
    certificateNum:[{ required: true, message: '请输入证书编号', trigger: 'blur' }],
    effectiveTime:[{ required: true, message: '请选择截止日期', trigger: 'blur' }],
    filePath:[{ required: true, message: '请上传证书', trigger: 'blur' }],
  },
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
  header: {
    Authorization: getToken()
  },
  fileList: [],
})
 
 
const openDialog = async (type, value) => {
  title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
  if(type === 'edit' || type === 'review') {
    state.form = JSON.parse(JSON.stringify(value));
    const obj = {
      path: state.form.filePath,
      name: state.form.fileName
    }
    state.fileList.push(obj)
  }
  dialogVisible.value = true;
}
 
const onSubmit = async () => {
  const valid = await busRef.value.validate();
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  state.form.companyId = userInfo.companyId
  if(valid){
    if(title.value === '新增'){
      const {id, ...data} = JSON.parse(JSON.stringify(state.form))
      const res = await addQualification(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '新增成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }else if(title.value === '编辑'){
      const {...data} = JSON.parse(JSON.stringify(state.form))
      const res = await editQualification(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }
  }
}
 
const handleClose = () => {
  busRef.value.clearValidate();
  reset();
  dialogVisible.value = false;
  emit("getList")
 
}
const handleAvatarSuccess = (res,uploadFile) => {
  if(res.code === 200){
    state.form.filePath = state.fileList[0].response.data.path
    state.form.fileName = state.fileList[0].response.data.originName
  }else {
    state.fileList = []
    ElMessage({
      type: 'warning',
      message: res.message
    })
  }
}
// 上传
const showTip =()=>{
  ElMessage({
    type: 'warning',
    message: '超出文件上传数量'
  });
}
 
const picSize = async (rawFile) => {
  console.log("111",rawFile.name.length)
  if(rawFile.name.length >100){
    ElMessage({
      type: 'warning',
      message: '文件名不能超过100字'
    });
    return false
  }
  if(rawFile.size / 1024 / 1024 > 15){
    ElMessage({
      type: 'warning',
      message: '文件大小不能超过15M'
    });
    return false
  }
};
const handleRemove = async (file, uploadFiles) => {
  state.form.filePath = ''
  state.form.fileName = ''
  state.fileList = []
 
}
const reset = () => {
  state.form = {
    id: '',
    companyId: '',
    certificateName: '',
    certificateNum: '',
    effectiveTime: '',
    filePath: '',
    fileName: ''
  }
  state.fileList = [];
}
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>