detection-business/pages/staff/StaffInfo.vue

409 lines
12 KiB
Vue
Raw Normal View History

2024-12-20 14:19:43 +08:00
<template>
<view class="content">
<view class="c-top">
<view class="" @click="getback()">
<uni-icons type="left" size="18"></uni-icons>
</view>
<view class="c-title">{{ topName }}</view>
<view class=""></view>
</view>
<view class="ail">
<view class="on-input">
<view class="s-huix">姓名</view>
2025-02-06 10:03:16 +08:00
<view class=""><input v-model="staff.nickname" type="text" placeholder="请输入姓名"></view>
2024-12-20 14:19:43 +08:00
</view>
<view class="on-input">
<view class="s-huix">电话</view>
2025-02-06 10:03:16 +08:00
<view class=""><input v-model="staff.mobile" type="text" placeholder="请输入手机号"></view>
2024-12-20 14:19:43 +08:00
</view>
<view class="on-input">
<view class="s-huix">学历</view>
2024-12-20 19:32:47 +08:00
<view class="" @click="showEducation = true"><input disabled :value="getEducation" type="text"
2025-02-06 10:03:16 +08:00
placeholder="请选择学历" v-model="staff.educational"></view>
2024-12-20 14:19:43 +08:00
</view>
<view class="on-input">
<view class="s-huix">身份证号</view>
2025-02-06 10:03:16 +08:00
<view class=""><input v-model="staff.idCard" type="text" placeholder="请输入身份证号"></view>
2024-12-20 14:19:43 +08:00
</view>
<view class="on-input">
<view class="s-huix">入职时间</view>
2024-12-20 19:32:47 +08:00
<view class="" @click="showJoinedDate = true"><input disabled :value="formattedJoinedDate" type="text"
2024-12-20 14:19:43 +08:00
placeholder="请选择入职时间"></view>
</view>
<view class="on-input">
<view class="s-huix">转正时间</view>
2024-12-20 19:32:47 +08:00
<view class="" @click="showFormalDate = true"><input disabled :value="formattedFormalDate" type="text"
2024-12-20 14:19:43 +08:00
placeholder="请选择转正时间"></view>
</view>
<view class="on-input">
<view class="s-huix">购买保险时间</view>
2024-12-20 19:32:47 +08:00
<view class="" @click="showSafeDate = true"><input disabled :value="formattedSafeDate" type="text"
2024-12-20 14:19:43 +08:00
placeholder="请选择购买保险时间"></view>
</view>
2025-02-06 10:03:16 +08:00
<view class="on-input">
<view class="s-huix">驾照类型</view>
<view class="" @click="showDriveType = true">
<input disabled :value="driverLicenseTypeArrStr" type="text"
placeholder="请选择驾照类型">
</view>
</view>
2024-12-20 14:19:43 +08:00
<view class="">
<view style="display: flex;justify-content: space-between;margin: 1rem auto">
<view class="s-huix" style="text-align: left">附件</view>
<view class="" style="color: #3391ff" @click="addFile">添加附件</view>
</view>
2025-02-06 10:03:16 +08:00
<view v-for="(item, index) in files" :key="fileKey + index" style="margin-bottom: 1rem;border-bottom: 1px solid #DAE1F8;">
2024-12-20 14:19:43 +08:00
<view class="on-input">
<view class="s-huix">名称</view>
2025-02-06 10:03:16 +08:00
<view class=""><input v-model="item.name" type="text" placeholder="请输入附件名称"></view>
2024-12-20 14:19:43 +08:00
</view>
2025-02-06 10:03:16 +08:00
<u-upload v-if="!item.url"
2024-12-20 14:19:43 +08:00
@afterRead="uploadFilePromise($event, index)"
name="6"
multiple
:maxCount="1"
width="100%"
height="140px"
>
</u-upload>
<view v-else class="image-container">
2025-02-06 10:03:16 +08:00
<image :src="baseImageUrl + '/' + item.url" style="width: 100%;height: 140px;"></image>
2024-12-20 14:19:43 +08:00
<view @click="deletedUrl(index)" class="close-button">
<text>x</text>
</view>
</view>
</view>
</view>
<view class="tjiao" @click="getyadd">
<text>保存更改</text>
</view>
</view>
<u-picker :show="showEducation" ref="uPicker" :columns="[educations]"
@confirm="chooseEducation" @cancel="showEducation = false"
keyName="label"></u-picker>
<u-datetime-picker
:show="showJoinedDate"
2025-02-06 10:03:16 +08:00
v-model="staff.joinDate"
2024-12-20 14:19:43 +08:00
@cancel="showJoinedDate = false"
@confirm="chooseJoinDate"
mode="date"
return-type='string'
></u-datetime-picker>
<u-datetime-picker
:show="showFormalDate"
2025-02-06 10:03:16 +08:00
v-model="staff.probationPeriod"
2024-12-20 14:19:43 +08:00
@cancel="showFormalDate = false"
@confirm="chooseFormalDate"
mode="date"
return-type='string'
></u-datetime-picker>
<u-datetime-picker
:show="showSafeDate"
2025-02-06 10:03:16 +08:00
v-model="staff.socialSecurityBuyDate"
2024-12-20 14:19:43 +08:00
@cancel="showSafeDate = false"
@confirm="chooseSafeDate"
mode="date"
return-type='string'
></u-datetime-picker>
2025-02-06 10:03:16 +08:00
<qianziyu-select
:show="showDriveType"
type="checkbox"
name="id"
:dataLists="driverLicenseType"
:showSearch=false
@cancel="showDriveType = false"
:checkboxData="driverLicenseTypeArr"
@submit="onsubmit"
@update:checkboxData="driverLicenseTypeArr = $event"
>
</qianziyu-select>
2024-12-20 14:19:43 +08:00
</view>
</template>
<script>
import request from "../../utils/request";
import {formatDate, getDictDataByType} from "../../utils/utils";
import config from '@/config'
import upload from '@/utils/upload.js'
export default {
name: "StaffInfo",
2025-02-06 10:03:16 +08:00
data() {
return {
2024-12-20 14:19:43 +08:00
userId: null,
staff: {},
user: {},
educations: [],
files: [],
showEducation: false,
showJoinedDate: false,
showFormalDate: false,
showSafeDate: false,
2025-02-06 10:03:16 +08:00
showDriveType: false,
topName: null,
driverLicenseTypeArr: [],
driverLicenseType: [],
driverLicenseTypeArrStr: null,
baseImageUrl: config.baseImageUrl,
fileKey: 0, // 初始化 key 值
2024-12-20 14:19:43 +08:00
}
},
2025-02-06 10:03:16 +08:00
onLoad(data) {
if (data.id) {
2024-12-20 14:19:43 +08:00
this.userId = data.id
this.getInfoByUserId()
2025-02-06 10:03:16 +08:00
this.getDriveType()
2024-12-20 14:19:43 +08:00
}
},
2025-02-06 10:03:16 +08:00
computed: {
getEducation() {
if (!this.educations || this.educations.length === 0) {
2024-12-20 14:19:43 +08:00
this.getEducations()
}
const index = this.educations.findIndex(item => item.value === this.staff.education)
2025-02-06 10:03:16 +08:00
if (index !== -1) {
2024-12-20 14:19:43 +08:00
return this.educations[index].label
}
return ''
},
formattedJoinedDate() {
2025-02-06 10:03:16 +08:00
if (!this.staff.joinDate) return '';
return formatDate(this.staff.joinDate); // 确保formatDate返回'yyyy-MM-dd'格式
2024-12-20 14:19:43 +08:00
},
formattedFormalDate() {
2025-02-06 10:03:16 +08:00
if (!this.staff.probationPeriod) return '';
return formatDate(this.staff.probationPeriod); // 确保formatDate返回'yyyy-MM-dd'格式
2024-12-20 14:19:43 +08:00
},
formattedSafeDate() {
2025-02-06 10:03:16 +08:00
if (!this.staff.socialSecurityBuyDate) return '';
return formatDate(this.staff.socialSecurityBuyDate); // 确保formatDate返回'yyyy-MM-dd'格式
2024-12-20 14:19:43 +08:00
},
},
2025-02-06 10:03:16 +08:00
methods: {
getyadd() {
if (!this.staff.nickname || !this.staff.mobile) {
2024-12-20 14:19:43 +08:00
uni.showToast({
title: '姓名和电话不能有空',
icon: 'none'
})
return
}
2025-02-06 10:03:16 +08:00
// 手动格式化日期字段,确保是格式化后的字符串
if (this.staff.probationPeriod) {
this.staff.probationPeriod = formatDate(this.staff.probationPeriod);
}
this.staff.userId = this.userId
console.log(this.staff)
2024-12-20 14:19:43 +08:00
const data = {
...this.staff,
2025-02-06 10:03:16 +08:00
fileList: this.files,
driverLicenseType: this.driverLicenseTypeArrStr,
driverLicenseTypeArr: this.driverLicenseTypeArr.map(item => item.id)
2024-12-20 14:19:43 +08:00
}
request({
2025-02-06 10:03:16 +08:00
url: '/inspectionStaff/update',
method: 'put',
2024-12-20 14:19:43 +08:00
data: data
}).then(res => {
uni.showToast({
title: "保存成功"
})
this.getInfoByUserId()
})
},
2025-02-06 10:03:16 +08:00
forceRefreshFiles() {
this.fileKey += 1; // 改变 key 值以强制刷新组件
},
2024-12-20 14:19:43 +08:00
addFile() {
if (this.files.length === 0 || this.files[0].fileUrl !== null) {
this.files.unshift({
fileName: "未命名",
fileUrl: null
})
}
},
uploadFilePromise(event, index) {
upload({
url: '/common/upload',
filePath: event.file[0].url,
}).then((res) => {
this.files[index].name = event.file[0].name
2025-02-06 10:03:16 +08:00
this.files[index].url = res.data.url
this.forceRefreshFiles(); // 强制刷新文件列表
2024-12-20 14:19:43 +08:00
})
2025-02-06 10:03:16 +08:00
console.log(this.files)
2024-12-20 14:19:43 +08:00
},
deletedUrl(index) {
this.files.splice(index, 1)
},
chooseJoinDate(e) {
this.staff.joinedDate = formatDate(e.value)
this.showJoinedDate = false
},
chooseFormalDate(e) {
2025-02-06 10:03:16 +08:00
const formattedDate = formatDate(e.value);
console.log('Formatted probationPeriod:', formattedDate); // 确认输出是字符串
this.staff.probationPeriod = formattedDate;
console.log(this.staff.probationPeriod); // 确认保存的值是格式化后的字符串
this.showFormalDate = false;
2024-12-20 14:19:43 +08:00
},
2025-02-06 10:03:16 +08:00
2024-12-20 14:19:43 +08:00
chooseSafeDate(e) {
2025-02-06 10:03:16 +08:00
this.staff.socialSecurityBuyDate = formatDate(e.value)
2024-12-20 14:19:43 +08:00
this.showSafeDate = false
},
chooseEducation(e) {
2025-02-06 10:03:16 +08:00
this.$set(this.staff, 'education', e.value[0].label)
2024-12-20 14:19:43 +08:00
// this.staff['education'] = e.value[0].value
2025-02-06 10:03:16 +08:00
// console.log('education', this.staff.education)
this.staff.educational = e.value[0].label
2024-12-20 14:19:43 +08:00
this.showEducation = false
},
2025-02-06 10:03:16 +08:00
async getEducations() {
2024-12-20 19:32:47 +08:00
this.educations = await getDictDataByType("company_staff_edu")
2024-12-20 14:19:43 +08:00
},
2025-02-06 10:03:16 +08:00
async getInfoByUserId() {
2024-12-20 14:19:43 +08:00
const res = await request({
2025-02-06 10:03:16 +08:00
url: '/inspectionStaff/get',
params: {
id: this.userId
},
2024-12-20 14:19:43 +08:00
method: 'get'
})
2025-02-06 10:03:16 +08:00
this.staff = res.data
this.topName = this.staff?.nickname
if (res.data.driverLicenseType) {
this.driverLicenseTypeArrStr = res.data.driverLicenseType
res.data.driverLicenseTypeArr.forEach(item => {
let temp = {
id: item,
name: item
}
this.driverLicenseTypeArr.push(temp)
})
2024-12-20 14:19:43 +08:00
}
2025-02-06 10:03:16 +08:00
if (this?.staff?.fileList) {
2024-12-20 14:19:43 +08:00
this.files = []
2025-02-06 10:03:16 +08:00
this.staff.fileList.forEach((item) => {
2024-12-20 14:19:43 +08:00
const temp = {
2025-02-06 10:03:16 +08:00
name: item.name,
url: item.url
2024-12-20 14:19:43 +08:00
}
this.files.push(temp)
})
}
},
2025-02-06 10:03:16 +08:00
getDriveType() {
return request({
url: '/common/down/getDriverLicenseType',
method: 'get'
}).then(res => {
//提取出数组中的id属性
this.driverLicenseType = res.data
})
},
onsubmit(selectedData) {
console.log('提交的数据:', selectedData);
selectedData.map(item => item.id);
this.driverLicenseTypeArr = selectedData;
this.driverLicenseTypeArrStr = selectedData.map(item => item.id).join(',');
this.showDriveType = false; // 提交后关闭弹窗
},
getback() {
2024-12-20 14:19:43 +08:00
uni.navigateBack()
},
}
}
</script>
<style scoped lang="scss">
.content {
box-sizing: border-box;
width: 100%;
height: calc(100vh);
background: white;
}
2025-02-06 10:03:16 +08:00
.c-top {
2024-12-20 14:19:43 +08:00
width: 100%;
box-sizing: border-box;
padding: 15px;
padding-top: 55px;
display: flex;
justify-content: space-between;
align-items: center;
background-color: white;
}
2025-02-06 10:03:16 +08:00
.c-title {
2024-12-20 14:19:43 +08:00
font-size: 18px;
font-weight: bold
}
2025-02-06 10:03:16 +08:00
.ail {
2024-12-20 14:19:43 +08:00
width: 100%;
box-sizing: border-box;
padding: 15px;
}
2025-02-06 10:03:16 +08:00
2024-12-20 14:19:43 +08:00
.on-input {
width: 100%;
display: flex;
align-items: center;
border-bottom: 1px solid #DAE1F8;;
box-sizing: border-box;
padding-bottom: 5px;
margin: 10px;
justify-content: space-between;
}
2025-02-06 10:03:16 +08:00
2024-12-20 14:19:43 +08:00
.on-input input {
text-align: right;
padding-right: 1rem
}
2025-02-06 10:03:16 +08:00
2024-12-20 14:19:43 +08:00
.s-huix {
width: 30%;
text-align: right;
}
2025-02-06 10:03:16 +08:00
2024-12-20 14:19:43 +08:00
.image-container {
position: relative; /* 使子元素可以相对于此容器进行绝对定位 */
width: 100%;
height: 140px;
}
.close-button {
position: absolute;
top: 5px; /* 调整距离顶部的距离 */
right: 5px; /* 调整距离右侧的距离 */
width: 24px; /* 圆的直径 */
height: 24px;
background-color: #ff0000;
color: white;
border-radius: 50%; /* 使按钮呈现圆形 */
display: flex;
//align-items: center;
justify-content: center;
font-size: 16px; /* 调整“X”的字体大小 */
cursor: pointer; /* 鼠标悬停时显示为指针 */
}
.tjiao {
width: 40%;
height: 30px;
margin: 5px auto;
display: flex;
align-items: center;
justify-content: center;
background: #0D2E8D;
color: white;
border-radius: 50px;
}
</style>