feat: 增加批量添加证书功能
This commit is contained in:
parent
9392557254
commit
b053b0eea7
|
@ -17,6 +17,14 @@ export function createCandidate(data){
|
|||
})
|
||||
}
|
||||
|
||||
export function importCertificate(data){
|
||||
return request({
|
||||
url:'/crm/candidate/import/',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function updateCandidate(id, data) {
|
||||
return request({
|
||||
url: `/crm/candidate/${id}/`,
|
||||
|
|
|
@ -19,6 +19,23 @@
|
|||
type="primary"
|
||||
@click="handleAdd"
|
||||
>手动创建</el-button>
|
||||
<el-popover placement="top" width="160" v-if="checkPermission(['certificate_create'])"
|
||||
v-model="popovervisible">
|
||||
<p>导入题目前,请下载模板并按格式录入.</p>
|
||||
<div style="text-align: left; margin: 0;">
|
||||
<el-link href="/media/muban/certificate.xlsx" target="_blank" @click="popovervisible = false"
|
||||
type="primary">下载模板</el-link>
|
||||
<el-upload
|
||||
:action="upUrl"
|
||||
:on-success="handleUploadSuccess"
|
||||
accept=".xlsx"
|
||||
:headers="upHeaders"
|
||||
:show-file-list="true">
|
||||
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button>
|
||||
</el-upload>
|
||||
</div>
|
||||
<el-button slot="reference" type="primary">批量导入</el-button>
|
||||
</el-popover>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
|
@ -28,7 +45,7 @@
|
|||
border
|
||||
fit
|
||||
highlight-current-row
|
||||
max-height="600"
|
||||
max-height="700"
|
||||
row-key="id"
|
||||
default-expand-all
|
||||
>
|
||||
|
@ -267,6 +284,7 @@
|
|||
import {
|
||||
getCandidateList,
|
||||
createCandidate,
|
||||
importCertificate,
|
||||
updateCandidate
|
||||
} from '@/api/candidate'
|
||||
import {
|
||||
|
@ -286,6 +304,7 @@ export default {
|
|||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
popovervisible: false,
|
||||
uploadUrl: process.env.VUE_APP_BASE_API,
|
||||
upHeaders: upHeaders(),
|
||||
upUrl: upUrl(),
|
||||
|
@ -326,6 +345,31 @@ export default {
|
|||
handleAvatarSuccess(res, file) {
|
||||
this.candidate.photo = res.data.path
|
||||
},
|
||||
handleUploadSuccess(res, file) {
|
||||
if (res.code == 200) {
|
||||
const loading = this.$loading({ text: "正在导入中..." })
|
||||
importCertificate(res.data).then(response => {
|
||||
loading.close()
|
||||
if (response.code == 200) {
|
||||
this.$message({
|
||||
message: '导入成功',
|
||||
type: 'success'
|
||||
});
|
||||
this.getList(listQuery)
|
||||
} else if (response.code == 206) {
|
||||
this.$message({
|
||||
message: '部分未成功' + response.data,
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
this.$message.error(response.msg);
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
this.$message.error("Excel上传失败!");
|
||||
}
|
||||
},
|
||||
getOpllevelName(value) {
|
||||
console.log(value, 'value')
|
||||
const numValue = Number(value)
|
||||
|
|
|
@ -795,7 +795,68 @@ class CandidateViewSet(RetrieveModelMixin, ListModelMixin, CreateModelMixin, Upd
|
|||
queryset = self.queryset.filter(consumer=request.user)
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(methods=['post'], detail=False, url_path='import', url_name='import_certificate')
|
||||
def import_consumer(self, request):
|
||||
"""
|
||||
导入证书
|
||||
"""
|
||||
xlsxpath = request.data['path']
|
||||
fullpath = settings.BASE_DIR + xlsxpath
|
||||
wb = load_workbook(fullpath)
|
||||
sheet = wb.worksheets[0]
|
||||
# 验证文件内容
|
||||
if sheet['a1'].value != '证书号':
|
||||
return Response({"error":"证书号列错误!"})
|
||||
if sheet['b1'].value != '姓名':
|
||||
return Response({"error":"姓名列错误!"})
|
||||
if sheet['c1'].value != '性别':
|
||||
return Response({"error":"性别列错误!"})
|
||||
if sheet['d1'].value != '身份证号':
|
||||
return Response({"error":"身份证号列错误!"})
|
||||
if sheet['e1'].value != '工作类别':
|
||||
return Response({"error":"工作类别列错误!"})
|
||||
if sheet['f1'].value != '职业等级':
|
||||
return Response({"error":"职业等级列错误!"})
|
||||
if sheet['g1'].value != '单位':
|
||||
return Response({"error":"单位列错误!"})
|
||||
if sheet['h1'].value != '发证日期':
|
||||
return Response({"error":"发证日期列错误!"})
|
||||
m = 2
|
||||
while sheet['B'+str(m)].value:
|
||||
number = sheet['A'+str(m)].value
|
||||
if number:
|
||||
number = str(number).replace(' ', '')
|
||||
consumer_name = sheet['B'+str(m)].value
|
||||
if consumer_name:
|
||||
consumer_name = str(consumer_name).replace(' ', '').replace("\n", "")
|
||||
gender = sheet['C'+str(m)].value
|
||||
if gender:
|
||||
gender = str(gender).replace(' ', '').replace("\n", "")
|
||||
ID_number = sheet['D'+str(m)].value
|
||||
if ID_number:
|
||||
ID_number = str(ID_number).replace(' ', '').replace("\n", "")
|
||||
workscope_name = sheet['E'+str(m)].value
|
||||
if workscope_name:
|
||||
workscope_name = str(workscope_name).replace(' ', '').replace("\n", "")
|
||||
opllevel = sheet['F'+str(m)].valueki
|
||||
company_name = sheet['G'+str(m)].value
|
||||
if company_name:
|
||||
company_name = str(company_name).replace(' ', '').replace("\n", "")
|
||||
issue_date = sheet['H'+str(m)].value
|
||||
if issue_date:
|
||||
# 检查时间格式是否为年月日
|
||||
try:
|
||||
issue_date = datetime.strftime(issue_date, '%Y-%m-%d')
|
||||
except ValueError:
|
||||
return Response({"error":"发证日期格式错误!"})
|
||||
|
||||
obj = Candidate(number=number, consumer_name=consumer_name, gender=gender,issue_date = issue_date, create_admin = self.request.user,
|
||||
ID_number=ID_number, workscope_name=workscope_name, opllevel=opllevel, company_name=company_name)
|
||||
obj.save()
|
||||
m = m + 1
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class MsgViewSet(CreateModelMixin, ListModelMixin, GenericViewSet):
|
||||
perms_map = [
|
||||
|
|
Loading…
Reference in New Issue