ZhiYeJianKang_QiYe_APP/pages/Custodyfile/Custodyfile.vue

627 lines
16 KiB
Vue
Raw Permalink Normal View History

2025-02-20 15:38:43 +08:00
<template>
<view class="app">
<view class="body">
<u-form :model="formxcjyListadd" ref="uForm" :label-width='200' :rules="rules">
<u-form-item label="报告名称 " labelWidth="130" prop="tjbgName"><u-input v-model="formxcjyListadd.tjbgName"
placeholder="{企业简称首字母}-{企业全名}-{年月日}-{序列号}" /></u-form-item>
<u-form-item label="体检机构名称" prop="tjjgName">
<lx-input class="input" placeholder="请选择机构" v-model="formxcjyListadd.tjjgName" :list="testname"
:hidden.sync="hidden" @clickItem="confirm" @input="input"></lx-input>
<!-- <u-select v-model="showitem" mode="single-column" :list="testname" @confirm="confirm"
@cancel="cancel"></u-select>
<u-input v-model="formxcjyListadd.tjjgName" type="select" @tap="showitemlist" placeholder="请选择机构" /> -->
</u-form-item>
<view class="" @tap="showdays()">
<u-form-item label="体检时间" labelWidth="140" prop="bgtime">
<view class="button" v-if="button">请选择体检时间</view>
<u-calendar v-model="showday" :mode="mode" @change="changetime">
</u-calendar>
{{formxcjyListadd.bgtime | formatDate('-')}}
</u-form-item>
</view>
<!-- <u-form-item label="报告时间"><u-input v-model="form.intro" /></u-form-item> -->
<u-form-item label="下次体检时间" prop="nexttjtime">
<u-radio-group v-model="formxcjyListadd.reportPeriod">
<u-radio name="半年" @change="halfChange">半年</u-radio>
<u-radio shape="circle" name="一年" @change="oneChange">一年</u-radio>
<u-radio shape="circle" name="两年" @change="twoChange">两年</u-radio>
<u-radio shape="circle" name="三年" @change="threeChange">三年</u-radio>
<view class="time" v-if="formxcjyListadd.nexttjtime">
{{ formxcjyListadd.nexttjtime }}
</view>
</u-radio-group>
</u-form-item>
<u-form-item label="职业健康检查总报" labelWidth="250" prop="qyreport">
<lsj-upload ref="lsjUpload" childId="upload1" :option="option" :size="size" :formats="formats"
:debug="debug" :instantly="instantly" @uploadEnd="onuploadEnd" @progress="onprogre"
@change="change">
<u-button type="primary" size="medium" class="up">文件上传</u-button>
<u-icon name="checkbox-mark" v-if="formxcjyListadd.qyreport" class="icon"></u-icon>
</lsj-upload>
</u-form-item>
<u-form-item label="职业健康检查结果汇总表" labelWidth="250" prop="collectReport">
<lsj-upload ref="lsjUpload" childId="upload1" :option="option" :size="size" :formats="formats"
:debug="debug" :instantly="instantly" @uploadEnd="onuploadEndReport" @progress="onprogreReport"
@change="changeReport">
<u-button type="primary" size="medium" class="up">文件上传</u-button>
<u-icon name="checkbox-mark" v-if="formxcjyListadd.collectReport" class="icon"></u-icon>
</lsj-upload>
</u-form-item>
</u-form>
<view class="but">
<view class="sub">
<u-button type="primary" text="确定" @tap="submit()">提交</u-button>
</view>
<view class="res">
<u-button type="primary" text="确定" @tap="reset()">重置</u-button>
</view>
</view>
<u-toast ref="uToast" />
</view>
</view>
</template>
<script>
import {
tjjgListno,
inserttjxxno,
} from "@/api/Custodyfile/Custodyfile.js";
import baseUrl from '@/api/baseurl.js'
import moment from 'moment'
export default {
data() {
return {
formxcjyListadd: {
id: '',
enterpriseid: '',
enterprisename: '',
tjjgName: '',
tjjgid: '',
bgtime: '',
nexttjtime: '',
qyreport: '',
collectReport: '',
tjbgName: '',
reportPeriod: '',
},
showday: false, //报告时间
showitem: false,
mode: 'date',
value: '',
token: '',
tadytime: '',
jiansheadd: [],
testname: [],
button: true,
rules: {
tjbgName: [{
required: true,
message: "请填写报告名称",
trigger: "blur"
}, ],
tjjgName: [{
required: true,
message: "请选择体检机构名称",
trigger: "blur"
}, ],
bgtime: [{
required: true,
message: "请选择体检时间",
trigger: "blur"
}, ],
nexttjtime: [{
required: true,
message: "请选择下次体检时间",
trigger: "blur"
}, ],
qyreport: [{
required: true,
message: "请上传职业健康检查总报",
trigger: "blur"
}, ],
collectReport: [{
required: true,
message: "请上传职业健康检查结果汇总表",
trigger: "blur"
}, ]
},
hidden: false,
/////////////////////////////////////////////////////////////
// 上传接口参数
option: {
// 上传服务器地址,需要替换为你的接口地址
url: baseUrl + `/dzzyb/a/zyb/ar/uploadFile`, // 该地址非真实路径,需替换为你项目自己的接口地址
// 上传附件的key
name: 'file',
// 根据你接口需求自定义请求头,默认不要写content-type,让浏览器自适配
header: {
// 示例参数可删除
token: '',
},
// 根据你接口需求自定义body参数
formData: {
// 'orderId': 1000
}
},
// 选择文件后是否立即自动上传true=选择后立即上传
instantly: true,
// 必传宽高且宽高应与slot宽高保持一致
// width: '300rpx',
// height: '120rpx',
// 限制允许上传的格式,空串=不限制,默认为空
formats: '',
// 文件上传大小限制
size: 30,
// 文件数量限制
count: 1,
// 文件回显列表
files: new Map(),
// 微信小程序Map对象for循环不显示所以转成普通数组不要问为什么我也不知道
wxFiles: [],
// 是否打印日志
debug: true,
// 演示用
tabIndex: 0,
list: [],
}
},
created() {
this.option.header.token = uni.getStorageSync("token")
// console.log(this.token)
// console.log(moment().format("YYYY-MM-DD HH:mm"))
this.getlist()
},
filters: {
// 时间戳处理
formatDate: function(value, spe = '/') {
if (value) {
value = value
let data = new Date(value);
let year = data.getFullYear();
let month = data.getMonth() + 1;
let day = data.getDate();
// let h = data.getHours();
// let mm = data.getMinutes();
// let s = data.getSeconds();
month = month >= 10 ? month : "0" + month;
day = day >= 10 ? day : "0" + day;
// h = h >= 10 ? h : "0" + h;
// mm = mm >= 10 ? mm : "0" + mm;
// s = s >= 10 ? s : "0" + s;
return `${year}${spe}${month}${spe}${day}`;
}
}
},
onReady() {
this.$refs.uForm.setRules(this.rules);
},
methods: {
/**
* 某文件上传结束回调(成功失败都回调)
* @param {Object} item 当前上传完成的文件
*/
onuploadEnd(item) {
// 更新当前窗口状态变化的文件
this.files.set(item.name, item);
if (item['responseText']) {
// console.log('演示服务器返回的字符串JSON转Object对象');
this.files.get(item.name).responseText = JSON.parse(item.responseText);
this.formxcjyListadd.qyreport = this.files.get(item.name).responseText.data.src
this.$refs.uToast.show({
title: '上传成功',
type: 'success',
duration: 1500
})
uni.hideLoading();
}
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
// 强制更新视图
this.$forceUpdate();
},
/**
* 上传进度回调
* 如果网页上md文档没有渲染出事件名称onprogre请复制代码的小伙伴自行添加上哈没有哪个事件是只(item)
* @param {Object} item 当前正在上传的文件
*/
onprogre(item) {
// uni.showLoading({
// title: '文件上传中'
// });
// 更新当前状态变化的文件
this.files.set(item.name, item);
// console.log('打印对象', JSON.parse(JSON.stringify(this.files.get(item.name))));
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
// 强制更新视图
this.$forceUpdate();
},
/**
* 文件选择回调
* @param {Object} files 已选择的所有文件Map集合
*/
change(files) {
// console.log('当前选择的文件列表:', JSON.stringify([...files.values()]));
// 更新选择的文件
this.files = files;
// 强制更新视图
this.$forceUpdate();
// 微信小程序Map对象for循环不显示所以转成普通数组不要问为什么我也不知道
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
},
// 职业健康检查结果汇总表
onuploadEndReport(item) {
// 更新当前窗口状态变化的文件
this.files.set(item.name, item);
if (item['responseText']) {
// console.log('演示服务器返回的字符串JSON转Object对象');
this.files.get(item.name).responseText = JSON.parse(item.responseText);
this.formxcjyListadd.collectReport = this.files.get(item.name).responseText.data.src
this.$refs.uToast.show({
title: '上传成功',
type: 'success',
duration: 1500
})
uni.hideLoading();
}
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
// 强制更新视图
this.$forceUpdate();
},
onprogreReport(item) {
// uni.showLoading({
// title: '文件上传中'
// });
// 更新当前状态变化的文件
this.files.set(item.name, item);
// console.log('打印对象', JSON.parse(JSON.stringify(this.files.get(item.name))));
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
// 强制更新视图
this.$forceUpdate();
},
changeReport(files) {
// console.log('当前选择的文件列表:', JSON.stringify([...files.values()]));
// 更新选择的文件
this.files = files;
// 强制更新视图
this.$forceUpdate();
// 微信小程序Map对象for循环不显示所以转成普通数组不要问为什么我也不知道
// #ifdef MP-WEIXIN
this.wxFiles = [...this.files.values()];
// #endif
},
// 报告时间
showdays() {
this.showday = true;
},
// 体检时间点击事件
changetime(e) {
this.button = false
this.formxcjyListadd.bgtime = e.result
// 获取当前时间
// 获取半年后时间
console.log(this.formxcjyListadd.reportPeriod)
if (this.formxcjyListadd.reportPeriod == '三年') {
// 赋值给新值
this.tadytime = e.result
let newdate = moment(this.tadytime).subtract(-3, 'year').format('YYYY-MM-DD') // 三年
this.formxcjyListadd.nexttjtime = newdate
} else if (this.formxcjyListadd.reportPeriod == '半年') {
this.tadytime = e.result
let newdate = moment(this.tadytime).subtract(-0.5, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
} else if (this.formxcjyListadd.reportPeriod == '一年') {
this.tadytime = e.result
let newdate = moment(this.tadytime).subtract(-1, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
} else if (this.formxcjyListadd.reportPeriod == '两年') {
this.tadytime = e.result
let newdate = moment(this.tadytime).subtract(-2, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
}
// console.log(e);
// // console.log(this.formlist)
// this.formxcjyListadd.bgtime = e.result
},
// 检测机构名称
// getlist() {
// tjjgListno().then(res => {
// console.log(res)
// this.jiansheadd = res
// })
// },
// showitemlist() {
// this.testname = [],
// this.showitem = true
// this.jiansheadd.forEach((e) => {
// var obj = {
// label: e.companyName,
// value: e.id
// };
// this.testname.push(obj);
// })
// },
getlist() {
tjjgListno().then(res => {
this.jiansheadd = res
this.testname = []
this.jiansheadd.forEach((e) => {
var obj = {
label: e.companyName,
value: e.id
};
this.testname.push(obj);
})
})
},
// 检测机构名称确定
confirm(e) {
this.formxcjyListadd.tjjgName = e.label
this.formxcjyListadd.tjjgid = e.value
// console.log(e);
},
input(e) {
if (e) {
this.formxcjyListadd.tjjgName = e
this.formxcjyListadd.tjjgid = ''
console.log(e)
}
},
cancel(e) {
},
halfChange(e) {
console.log(this.formxcjyListadd.bgtime)
this.formxcjyListadd.reportPeriod = e
if (this.formxcjyListadd.bgtime) {
let newdate = moment(this.formxcjyListadd.bgtime).subtract(-0.5, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
console.log(this.formxcjyListadd.nexttjtime)
}
},
// 一年
oneChange(e) {
this.formxcjyListadd.reportPeriod = e
if (this.formxcjyListadd.bgtime) {
let newdate = moment(this.formxcjyListadd.bgtime).subtract(-1, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
}
},
// 两年
twoChange(e) {
this.formxcjyListadd.reportPeriod = e
if (this.formxcjyListadd.bgtime) {
let newdate = moment(this.formxcjyListadd.bgtime).subtract(-2, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
}
},
// 三年
threeChange(e) {
this.formxcjyListadd.reportPeriod = e
if (this.formxcjyListadd.bgtime) {
let newdate = moment(this.formxcjyListadd.bgtime).subtract(-3, 'year').format('YYYY-MM-DD')
this.formxcjyListadd.nexttjtime = newdate
}
},
// 选中任一radio时由radio-group触发
radioGroupChange(e) {
// console.log(e);
},
// 重置
reset() {
this.button = true
this.formxcjyListadd = {
id: '',
enterpriseid: '',
enterprisename: '',
tjjgName: '',
tjjgid: '',
bgtime: '',
nexttjtime: '',
qyreport: '',
collectReport: '',
tjbgName: '',
reportPeriod: '',
}
},
// 提交
submit() {
console.log(this.formxcjyListadd)
this.$refs.uForm.validate(valid => {
if (valid) {
inserttjxxno(this.formxcjyListadd).then(response => {
if (response.code == '0' && response.mess == '下次检测日期重复!') {
this.$refs.uToast.show({
title: response.mess,
type: 'error',
duration: 1500
})
} else {
this.$refs.uToast.show({
title: '新增成功',
type: 'success',
duration: 1500
})
uni.$emit('update', '1')
setTimeout(function() {
uni.switchTab({
url: '/pages/homepage/homepage'
});
}, 2000);
}
});
}
});
}
}
}
</script>
<style lang="scss">
//css函数 声明函数
@function tovmin($rpx) {
//$rpx为需要转换的字号
@return #{$rpx * 100 / 750}vmin;
}
::v-deep .u-form-item {
padding-left: tovmin(50) !important;
}
::v-deep .u-form-item .lsj-file {
z-index: 1 !important;
}
// ::v-deep .u-iconfont {
// margin-right: tovmin(30);
// }
::v-deep .u-icon__icon uicon-checkbox-mark u-iconfont {
left: tovmin(8)
}
::v-deep .srollViewBox .scrollView-item {
padding-left: 0 !important;
line-height: tovmin(50) !important;
color: #3C9CFF !important;
}
::v-deep .inputBox .focusBox .inputStyle {
width: 100% !important;
color: #000 !important;
}
::v-deep .uni-input-placeholder {
font-size: tovmin(27) !important;
color: #C0C4CC !important;
}
::v-deep .srollViewBox .scrollView {
height: tovmin(200) !important;
}
::v-deep .srollViewBox {
z-index: 999 !important;
height: tovmin(220) !important;
}
::v-deep .uni-input-input {
font-size: tovmin(27) !important;
}
.app {
color: #C3C1C1;
font-weight: 400;
height: 100vh;
.btn {}
.body {
margin-top: tovmin(30);
.but {
display: flex;
justify-content: space-around;
margin-top: tovmin(50);
.res {
width: tovmin(170);
height: tovmin(70);
line-height: tovmin(70);
text-align: center;
color: #fff;
background-color: #3C9CFF;
border-radius: tovmin(10);
}
.sub {
width: tovmin(170);
height: tovmin(70);
line-height: tovmin(70);
text-align: center;
color: #fff;
background-color: #3C9CFF;
border-radius: tovmin(10);
}
}
}
.up {
// background-color: red;
position: absolute;
// right: tovmin(120);
}
.icon {
position: absolute;
right: tovmin(60);
top: tovmin(18);
}
.button {
color: #C0C4CC;
}
}
</style>