YNUtdPlatform/pages/realName/workbench/wageWitness/index.vue

375 lines
9.4 KiB
Vue
Raw Normal View History

2024-09-09 09:44:11 +08:00
<template>
<view class="page">
<u-navbar class="u-navbar" title="工资卡见证" placeholder @leftClick="leftClick" leftIconColor="#fff" bgColor="#00337A" :titleStyle="{ color: '#FFF', fontSize: '32rpx' }"/>
<scroll-view class="content" scroll-y="true">
<view class="img-view">
<view class="view-item">
<view>工程名称</view>
<view style="margin-left: 40rpx;">xxx工程</view>
</view>
<view class="view-item" style="display: block;">
<view>工资卡见证</view>
<view class="img-box">
<view class="img-item upload-btn" @click="openPhotograph()">
<image class="img" src="@/static/realName/tianjia-img.png" mode=""></image>
</view>
<view class="img-item" v-if="imgUrl!=''">
<image class="img" :src="imgUrl" mode=""></image>
</view>
</view>
</view>
<view class="view-item">
<view>人脸识别</view>
<view style="margin-left: 40rpx;" class="btn">点击人脸识别</view>
</view>
</view>
<view class="img-view" style="margin-bottom: 60rpx;">
<u--form class="addForm" :model="entryBankBean" ref="cForm">
<view class="form-input-box">
<view style="width:25%;height: 100%;">
<text>银行卡号</text>
</view>
<u-form-item prop='bankCard' style="width:70%;height: 100%;" >
<u--input v-model="entryBankBean.bankCard" type="number" placeholder="请输入" maxlength="40" border="surround" clearable></u--input>
</u-form-item>
</view>
<view class="form-input-box">
<view style="width:25%;height: 100%;">
<text>银行名称</text>
</view>
<u-form-item prop='bankName' style="width:70%;height: 100%;" >
<u--input v-model="entryBankBean.bankName" type="text" placeholder="请输入" maxlength="40" border="surround" clearable></u--input>
</u-form-item>
</view>
<view class="form-input-box">
<view style="width:25%;height: 100%;">
<text>银行支行名称</text>
</view>
<u-form-item prop='bankRollName' style="width:70%;height: 100%;" >
<u--input v-model="entryBankBean.bankRollName" type="text" placeholder="请输入" maxlength="40" border="surround" clearable></u--input>
</u-form-item>
</view>
</u--form>
</view>
<view class="sumbit-btn" @click="sumbit"> </view>
</scroll-view>
</view>
</template>
<script>
import { pathToBase64, base64ToPath } from 'image-tools';
import chooseFile from '../../util/chooseFile.js';
import config from '@/config'
export default {
data() {
return {
idNumber:uni.getStorageSync('realNameUser').idNumber,
imgUrl:'',
entryBankBean:{
"idNumber":uni.getStorageSync('realNameUser').idNumber,
"bankName": "",//银行名称
"bankCard": "",//银行卡号
"bankRollName": "",//银行支行名称
"path": "",//见证照片
"proId":uni.getStorageSync('realNameUser').proId,//工程id
"uploadDate": "",//日期
"uploadTime": "",//时间
"uploadId": uni.getStorageSync('realNameUser').userId,//上传人id
"isActive": "1",
"type": "2",
},
// imgs: [],
// imgsId: [],
}
},
onLoad() {
console.log('🚀 ~ mounted ~ mounted-index:');
},
onShow() {
console.log(this.timeFormat(null,'yyyy-mm-dd'))
},
methods: {
// 拍照录入
openPhotograph() {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: res => {
console.log('🚀 ~ res-拍照:', res)
uni.uploadFile({
url: `http://192.168.0.14:1909/file/file/upload`, //服务器地址
fileType:"image",//ZFB必填,不然报错
filePath: res.tempFilePaths[0],//这个就是我们上面拍照返回或者先中照片返回的数组
name: "imgFile",
formData: {
photoType:'salary',
},
success: (uploadFileRes) => {
if(uploadFileRes.statusCode==200){
this.entryBankBean.path=JSON.parse(uploadFileRes.data).data.url;
}else{
uni.$u.toast('上传失败');
}
},
fail: err => {
uni.$u.toast('上传失败');
console.log(err)
}
});
this.imgToBase64(res.tempFilePaths[0]).then(base64 => {
this.imgUrl=base64
})
},
fail: err => {
console.log('🚀 ~ err:', err)
}
})
},
imgToBase64(data) {
return new Promise((resolve, reject) => {
pathToBase64(data)
.then(base64 => {
resolve(base64)
})
.catch(error => {
console.error(error)
reject(error)
})
})
},
chooseFile(){
chooseFile((path)=>{
console.log('111111111',path);
})
},
sumbit(){
if(this.entryBankBean.path==''){
uni.$u.toast('工资卡见证照片未上传');
}else if(this.entryBankBean.bankCard==''){
uni.$u.toast('请填写银行卡号');
}else if(this.entryBankBean.bankName==''){
uni.$u.toast('请填写银行名称');
}else if(this.entryBankBean.bankRollName==''){
uni.$u.toast('请填写银行支行名称');
}else{
this.entryBankBean.uploadDate = this.timeFormat(null,'yyyy-mm-dd');
this.entryBankBean.uploadTime = this.timeFormat(null,'yyyy-mm-dd hh:MM:ss');
console.log(this.entryBankBean)
uni.request({
url: config.realAppUrl+'/payCard/insertPayCard',
method: 'post',
data: this.entryBankBean,
header: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: uni.getStorageSync('realNameToken')
},
success: res => {
console.log(res)
res = res.data;
if(res.code==200){
uni.showToast({
title: res.data,
icon: 'none'
})
setTimeout(()=>{
uni.navigateBack({
delta: 1 // 返回到已存在的页面
});
},1000)
}else{
uni.showToast({
title: res.msg,
icon: 'none'
})
}
},
fail: err => {
console.log(err)
}
})
}
},
// 返回
leftClick() {
console.log('返回')
uni.navigateBack({
delta: 1 // 返回
});
},
timeFormat(dateTime = null, formatStr = 'yyyy-mm-dd') {
let date
// 若传入时间为假值,则取当前时间
if (!dateTime) {
date = new Date()
}
// 若为unix秒时间戳则转为毫秒时间戳逻辑有点奇怪但不敢改以保证历史兼容
else if (/^\d{10}$/.test(dateTime?.toString().trim())) {
date = new Date(dateTime * 1000)
}
// 若用户传入字符串格式时间戳new Date无法解析需做兼容
else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) {
date = new Date(Number(dateTime))
}
// 处理平台性差异在Safari/Webkit中new Date仅支持/作为分割符的字符串时间
// 处理 '2022-07-10 01:02:03',跳过 '2022-07-10T01:02:03'
else if (typeof dateTime === 'string' && dateTime.includes('-') && !dateTime.includes('T')) {
date = new Date(dateTime.replace(/-/g, '/'))
}
// 其他都认为符合 RFC 2822 规范
else {
date = new Date(dateTime)
}
const timeSource = {
'y': date.getFullYear().toString(), // 年
'm': (date.getMonth() + 1).toString().padStart(2, '0'), // 月
'd': date.getDate().toString().padStart(2, '0'), // 日
'h': date.getHours().toString().padStart(2, '0'), // 时
'M': date.getMinutes().toString().padStart(2, '0'), // 分
's': date.getSeconds().toString().padStart(2, '0') // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
}
for (const key in timeSource) {
const [ret] = new RegExp(`${key}+`).exec(formatStr) || []
if (ret) {
// 年可能只需展示两位
const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0
formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex))
}
}
return formatStr
}
},
}
</script>
<style lang="scss">
.page {
width: 100vw;
height: 100vh;
background-color: #f8f8f8;
box-sizing: border-box;
font: 24rpx;
.content{
width: 100%;
height: 92vh;
margin-top: 20rpx;
}
.img-view{
width: 94%;
margin: 20rpx auto;
background-color: #FFF;
border-radius: 10rpx;
}
.btn{
background-color:#00337A;
color: #FFF;
padding:10rpx 20rpx;
border-radius: 10rpx;
}
.view-item{
width: 94%;
margin: 0rpx auto;
padding:20rpx;
display: flex;
border-bottom: 1rpx solid #f8f8f8;
font-size: 26rpx;
}
.img-box{
width: 94%;
height: auto;
margin: 0rpx auto;
padding:20rpx;
display: flex;
border-bottom: 1rpx solid #f8f8f8;
.img-item {
float: left;
width: 200upx;
height: 200upx;
border: 1px solid #ddd;
margin: 0 22rpx 20upx 0upx;
position: relative;
box-sizing: border-box;
background: #eee;
.img {
display: block;
width: 100%;
height: 100%;
}
.remove-btn {
position: absolute;
top: -18upx;
right: -18upx;
width: 44upx;
height: 44upx;
z-index: 2;
}
}
.upload-btn {
display: flex;
justify-content: center;
align-items: center;
.img {
width: 60upx;
height: 60upx;
margin: unset;
}
}
}
.btn2{
color: #999;
margin-top: 20rpx;
margin-left: 20rpx;
padding: 20rpx;
}
.popup-header{
width: 100%;
height: 80rpx;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
}
.popup-content{
width: 100%;
height: 15vh;
background-color: #fff;
}
.addForm{
width: 100%;
height: auto;
font-size: 26rpx;
.form-input-box{
padding: 0 20rpx;
display: flex;
align-items: center;
border-bottom: 1rpx solid #eee;
}
}
.sumbit-btn{
width: 94%;
height: 80rpx;
margin: 0 auto;
margin-bottom: 100rpx;
display: flex;align-items: center;justify-content: center;
background: #00337A;
color: #FFF;
border-radius: 10rpx;
}
}
</style>