jhprjv2/ruoyi-ui/src/views/project/projectCommittee/projectCommitteeDrawer.vue

210 lines
7.9 KiB
Vue
Raw Normal View History

2024-04-08 23:34:32 +08:00
<template>
<div class="project-committee-drawer">
<el-drawer v-if="isOpen" :visible.sync="isOpen" direction="rtl" size="40%" style="padding-left: 20px">
<template slot="title">
<div>工委会管理</div>
</template>
<el-form ref="form" label-width="120px">
2024-04-20 16:19:07 +08:00
<el-tabs type="card" v-model="activeName" @tab-click="handleClick">
2024-04-08 23:34:32 +08:00
<el-tab-pane v-for="(dict, idx) in dict.type.project_working_type" :key="dict.value"
2024-04-10 00:12:56 +08:00
:label="dict.label" :name="'' + dict.value">
2024-04-08 23:34:32 +08:00
<el-row v-for="(dataItem, index) in datas[idx]" :key="idx + '-' + index">
<el-col :span="4">
<el-form-item :label="dataItem.committeeName"></el-form-item>
</el-col>
<el-col :span="10">
<el-form-item label="成本名称">
<el-input v-model="dataItem.costName" placeholder="请输成本名称" maxlength="200" :class="checkRow(dataItem,1)"/>
</el-form-item>
</el-col>
<el-col :span="10">
2024-04-26 00:08:04 +08:00
<el-form-item label="申报金额">
<el-input v-model="dataItem.money" placeholder="请输申报金额" :class="checkRow(dataItem,2)"
2024-04-08 23:34:32 +08:00
@blur="v => formatAmount(dataItem)" maxlength="200">
<template slot="append">万元</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</el-tab-pane>
</el-tabs>
2024-09-12 23:56:50 +08:00
</el-form>
<div class="dialog-footer" style="text-align: center;">
2024-04-08 23:34:32 +08:00
<el-button type="primary" @click="submitForm"></el-button>
<el-button @click="doCancel"> </el-button>
</div>
</el-drawer>
</div>
</template>
<script>
2024-04-10 00:12:56 +08:00
import { listProjectCommittee, getProjectCommittee, delProjectCommittee, addProjectCommittee, updateProjectCommittee,addProjectCommitteeList } from "@/api/project/projectCommittee";
2024-04-08 23:34:32 +08:00
import { listCommittee, getCommittee, delCommittee, addCommittee, updateCommittee } from "@/api/base/committee";
import axios from 'axios'
export default {
dicts: ['project_working_type'],
data() {
return {
isOpen: false,
projectId: 0,
prjInfo: null,
2024-04-10 00:12:56 +08:00
activeName: '1',
2024-04-08 23:34:32 +08:00
datas: [],
}
},
methods: {
checkRow(datas,type){
let costName=(datas.costName||"").trim();
let money=((datas.money||"")+"").trim();
let tmp=costName+money;
return (tmp.length>0 && (costName.length==0 || money.length==0) && (type==1?costName.length==0:money.length==0)) ?"is-error":"";
},
submitForm(){
2024-04-10 00:12:56 +08:00
let dicts=this.dict.type.project_working_type
let tmps=dicts.filter(d=>d.value==this.activeName);
if(tmps.length==0){ return;}
let tmp=tmps[0];
let idx=dicts.indexOf(tmp);
if(idx==-1){return;}
if(!this.checkDatas(idx)){
this.$modal.msgError("请输入数据!");
return;
}
for(let i=0;i<dicts.length;i++){
if(i!=idx){
if(!this.checkDatas(i)){
this.activeName=dicts[i].value;
this.$modal.msgError("请输入数据!");
return;
}
}
}
let postData=[];
this.datas.forEach(it=>{
it.forEach(item=>{
item.money*=1;
2024-09-12 23:56:50 +08:00
item.applicationDate=this.$dt(item.committeeName)
2024-04-10 00:12:56 +08:00
postData.push(item);
})
});
addProjectCommitteeList(postData).then(d=>{
if(d.code==200){
this.$modal.msgSuccess("保存成功!");
this.loadData();
}else{
this.$modal.msgError("保存失败!!");
}
});
},
checkDatas(idx){
let tmps=this.datas[idx];
let isPass=true;
tmps.forEach(d=>{
let data1=d.costName||"";
let data2=d.money||""+"";
let data3=data1+data2;
if(data3.length>0 && (data1.length==0 || data2.length==0)){
isPass=false;
}
});
return isPass;
2024-04-08 23:34:32 +08:00
},
doCancel(){
this.isOpen=false;
},
formatAmount(it) {
let value=it.money;
// 使用正则表达式来格式化金额输入
it.money = value.replace(/[^\d.]/g, '') // 清除非数字和点
.replace(/\.{2,}/g, '.') // 只保留第一个点
.replace(/^(\d+)\./g, '$1.') // 保证第一个数字前有一个点
.replace('.', '$#$')
.replace(/\./g, '')
.replace('$#$', '.')
.replace(/^(\d+)$/, '$1.00') // 保证输入为一个整数时,末尾有两个零
.replace(/^0+([1-9])/, '$1') // 保证输入的金额不以零开头
.replace(/^(\d+\.\d{2})./, '$1'); // 保留两位小数
},
handleClick(tab, event) {
},
show(row) {
this.prjInfo = row;
this.isOpen = true;
2024-04-10 00:12:56 +08:00
this.activeName=this.dict.type.project_working_type.length>0?this.dict.type.project_working_type[0].value:"";
2024-04-08 23:34:32 +08:00
this.loadData();
},
loadData() {
let ajaxs = [
listProjectCommittee({ projectId: this.prjInfo.id, pageNum: 1, pageSize: 1000 }),
listCommittee({ pageNum: 1, pageSize: 1000 })
]
axios.all(ajaxs).then(res => {
this.makeData(res[0].rows || [], res[1].rows || []);
});
},
makeData(data, commits) {
let list = [];
this.dict.type.project_working_type.forEach(dic => {
let tmps = [];
commits.forEach(c => {
var find = data.filter(d => d.committeeId == c.id && d.workingType == dic.value);
if (find.length > 0) {
let f = find[0]
f.committeeName = c.name,
tmps.push(f);
} else {
tmps.push({
committeeId: c.id,
committeeName: c.name,
projectId: this.prjInfo.id,
workingType: dic.value,
costName: '',
money: null
})
}
});
list.push(tmps);
})
this.datas = list;
}
}
}
</script>
<style lang="scss">
.project-committee-drawer {
.el-drawer__header {
margin-bottom: 0px;
}
.el-drawer__body {
2024-09-12 23:56:50 +08:00
padding: 12px 24px 60px;
position: relative;
2024-04-08 23:34:32 +08:00
.el-row{
2024-04-10 00:12:56 +08:00
.el-input.is-error{
.el-input__inner{
2024-04-08 23:34:32 +08:00
border:solid 1px red;
2024-04-10 00:12:56 +08:00
}
2024-04-08 23:34:32 +08:00
}
}
}
2024-09-12 23:56:50 +08:00
.dialog-footer{
position: fixed;
bottom: 0px;
line-height: 60px;
background: #fff;
width: 100%;
text-align: left !important;
box-shadow: 0 8px 10px -5px rgba(0,0,0,.2), 0 16px 24px 2px rgba(0,0,0,.14), 0 6px 30px 5px rgba(0,0,0,.12);
margin-left: -24px;
padding-left: 20%;
}
2024-04-08 23:34:32 +08:00
.el-drawer {
min-width: 800px;
}
}
</style>