<template>
|
<div class="main">
|
<div class="main_header">
|
<div class="header_item">
|
<span class="header_label">合同编号:</span>
|
<el-input v-model="contractNum" :size="size" clearable placeholder="请输入合同编号"></el-input>
|
</div>
|
<div class="header_item">
|
<span class="header_label">合同名称:</span>
|
<el-input v-model="contractName" :size="size" clearable placeholder="请输入合同名称"></el-input>
|
</div>
|
<div class="header_item">
|
<el-button
|
icon="el-icon-search"
|
v-if="showButton('search')"
|
@click="searchContractInfoList(true)"
|
>查询</el-button>
|
<el-button
|
class="search_btn"
|
icon="el-icon-plus"
|
v-if="showButton('insert')"
|
@click="propInsert()"
|
>新增</el-button>
|
</div>
|
</div>
|
<div class="main_content">
|
<el-table
|
v-loading="loading"
|
:data="contractList"
|
height="100%">
|
<el-table-column label="序号" align="center" width="80">
|
<template #default="scope">
|
<span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="contractNum" label="合同编号" align="center"></el-table-column>
|
<el-table-column prop="proName" label="项目名称" align="center"></el-table-column>
|
<el-table-column prop="contractName" label="合同名称" align="center"></el-table-column>
|
<el-table-column label="上传附件" align="center" width="150">
|
<template #default="{ row }">
|
<el-button class="table_btn" size="mini" @click="propLookFile(row)">查看文件</el-button>
|
</template>
|
</el-table-column>
|
<el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
|
<el-table-column label="操作" align="center" width="200">
|
<template #default="{ row }">
|
<el-button class="table_btn" size="mini" v-if="showButton('update')" @click="propUpdate(row)">修改</el-button>
|
<el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteInfo(row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
<div class="main_footer">
|
<el-pagination
|
background
|
@current-change="changePageNum"
|
@size-change="changePageSize"
|
:current-page="pageNum"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="pageSize"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total">
|
</el-pagination>
|
</div>
|
<!-- 新增合同 修改合同信息 -->
|
<el-dialog
|
class="prop_dialog"
|
:title="asyncTitle ? '新增合同' : '修改合同信息'"
|
:visible.sync="asyncContract"
|
width="35%">
|
<el-form ref="form" :model="formContract" :rules="rulesContract" label-width="auto" class="rule_form">
|
<el-form-item label="合同编号:" prop="contractNum">
|
<el-input v-model="formContract.contractNum" :size="size" clearable placeholder="请输入合同编号"></el-input>
|
</el-form-item>
|
<el-form-item label="项目名称:" prop="proId">
|
<el-select v-model="formContract.proId" :size="size" clearable placeholder="请选择项目">
|
<el-option
|
v-for="item in projectData"
|
:key="item.proId"
|
:label="item.proName"
|
:value="item.proId">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="合同名称:" prop="contractName">
|
<el-input v-model="formContract.contractName" :size="size" clearable placeholder="请输入合同名称"></el-input>
|
</el-form-item>
|
<el-form-item label="上传附件:" prop="contracfileList">
|
<upload-file :file-list.sync="formContract.contracfileList">
|
<template #info>
|
<span>点击上传文件,支持xls、xlsx、ppt、doc、docx、pdf格式</span>
|
</template>
|
</upload-file>
|
</el-form-item>
|
<el-form-item label="备注:">
|
<el-input
|
v-model="formContract.remark"
|
type="textarea"
|
:size="size"
|
clearable
|
placeholder="请输入备注"
|
maxlength="200"
|
show-word-limit
|
></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer">
|
<el-button @click="asyncContract = false">取 消</el-button>
|
<el-button class="submit_btn" @click="asyncTitle ? submitInsertForm() : submitUpdateForm()">提 交</el-button>
|
</div>
|
</el-dialog>
|
<!-- 查看文件 -->
|
<look-file :file-list.sync="fileList" :async-file.sync="asyncFile"></look-file>
|
</div>
|
</template>
|
|
<script>
|
import { buttonPinia } from '../../pinia';
|
import { changeSize, throttle } from '../../plugins/public';
|
import UploadFile from '../../components/uploadFile';
|
import LookFile from '../../components/LookFile'
|
export default {
|
data() {
|
var fileMustUpload = (rule, value, callback) => {
|
if (!value) {
|
callback(new Error('请上传项目文件'));
|
} else if (value.length < 0) {
|
callback(new Error('请上传项目文件'));
|
} else {
|
this.$refs.form.clearValidate('proInfoFiles');
|
callback();
|
}
|
};
|
return {
|
contractNum: '',
|
contractName: '',
|
size: changeSize(),
|
total: 0,
|
pageNum: 1,
|
pageSize: 10,
|
loading: false,
|
contractList: [], // 列表信息
|
asyncTitle: true, // true 新增合同 false 修改合同信息
|
asyncContract: false, // 弹窗
|
formContract: {
|
contracfileList: []
|
}, // 表单信息
|
rulesContract: {
|
contractNum: [{
|
required: true,
|
message: '请输入合同编号',
|
trigger: 'blur'
|
}],
|
proId: [{
|
required: true,
|
message: '请选择项目',
|
trigger: ['blur', 'change']
|
}],
|
contractName: [{
|
required: true,
|
message: '请输入合同名称',
|
trigger: 'blur'
|
}],
|
contracfileList: [{
|
required: true,
|
message: '请上传项目文件'
|
}, {
|
validator: fileMustUpload,
|
trigger: ['change']
|
}]
|
}, // 表单校验信息
|
projectData: [],
|
asyncFile: false,
|
fileList: []
|
}
|
},
|
mounted() {
|
const that = this;
|
// 根据窗口大小动态修改组件尺寸
|
window.onresize = () => {
|
that.size = changeSize();
|
}
|
that.searchContractInfoList(true);
|
},
|
methods: {
|
// 获取全合同目信息
|
async getAllProjectData() {
|
const { data } = await this.$api.Engineer.searchProjects({
|
pageNum: 1,
|
pageSize: 1000000
|
});
|
this.projectData = data.list;
|
},
|
// 获取合同信息下文件
|
async searchContractFileList(contractId) {
|
const { data } = await this.$api.Project.searchContractFileList({
|
contractId: contractId
|
})
|
return data;
|
},
|
// 查询合同信息列表
|
searchContractInfoList(bol) {
|
if(bol) {
|
this.pageNum = 1;
|
}
|
this.loading = true;
|
this.contractList = [];
|
this.$api.Project.searchContractInfoList({
|
pageNum: this.pageNum,
|
pageSize: this.pageSize,
|
contractNum: this.contractNum,
|
contractName: this.contractName
|
}).then((res) => {
|
if(res.success) {
|
this.total = res.data.total;
|
this.contractList = res.data.list;
|
}
|
this.loading = false;
|
}).catch(() => {
|
this.loading = false;
|
})
|
},
|
// 打开添加信息
|
propInsert() {
|
this.asyncTitle = true;
|
this.asyncContract = true;
|
},
|
// 打开修改信息
|
propUpdate(row) {
|
this.aysncTitle = false;
|
this.asyncContract = true;
|
this.$set(this.formContract, 'contractId', row.contractId);
|
this.$set(this.formContract, 'contractNum', row.contractNum);
|
this.$set(this.formContract, 'proId', row.proId);
|
this.$set(this.formContract, 'contractName', row.contractName);
|
this.$set(this.formContract, 'remark', row.remark);
|
this.searchContractFileList(row.contractId).then((res) => {
|
this.$set(this.formContract, 'contracfileList', res.list.map(item => {
|
const type = item.contractFileName.split('.');
|
return {
|
id: item.contractFileId,
|
type: type[type.length - 1],
|
name: item.contractFileName,
|
url: item.contractFile
|
}
|
}));
|
})
|
},
|
// 查看文件
|
propLookFile(row) {
|
this.fileList = [];
|
this.searchContractFileList(row.contractId).then(res => {
|
let list = res.list.map(item => {
|
const type = item.contractFileName.split('.');
|
return {
|
id: item.id,
|
type: type[type.length - 1],
|
name: item.contractFileName,
|
url: item.contractFile
|
}
|
})
|
this.fileList = list;
|
});
|
this.asyncFile = true;
|
},
|
// 删除信息
|
deleteInfo(row) {
|
this.$confirm("该操作将删除该合同信息,是否继续删除?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning"
|
})
|
.then(() => {
|
this.$api.Project.deleteContractInfo({contractId: row.contractId})
|
.then(res => {
|
if(res.statusMsg === 'ok') {
|
this.searchContractInfoList(true);
|
this.$message.success("删除成功!");
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
})
|
.catch(() => {
|
this.$message.warning("您已取消");
|
})
|
},
|
// 提交添加信息
|
submitInsertForm: throttle(function() {
|
this.$refs.form.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.formContract);
|
params.contracfileList = params.contracfileList.map(item => {
|
return {
|
contractFile: item.url
|
}
|
});
|
this.$api.Project.insertContractInfo(params).then((res) => {
|
if(res.success) {
|
this.asyncContract = false;
|
this.$message.success('添加成功!');
|
this.searchContractInfoList();
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
// 提交修改信息
|
submitUpdateForm: throttle(function() {
|
this.$refs.form.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.formContract);
|
params.contracfileList = params.contracfileList.map(item => {
|
return {
|
contractFile: item.url
|
}
|
});
|
this.$api.Project.insertContractInfo(params).then((res) => {
|
if(res.success) {
|
this.asyncContract = false;
|
this.$message.success('修改成功!');
|
this.searchContractInfoList();
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
// 切换页码
|
changePageNum(page) {
|
this.pageNum = page;
|
this.searchContractInfoList();
|
},
|
// 切换每页条数
|
changePageSize(size) {
|
this.pageSize = size;
|
this.searchContractInfoList();
|
},
|
// 判断按钮权限信息
|
showButton(str) {
|
const pinia = buttonPinia();
|
return pinia.$state.buttonInfo.includes(str);
|
}
|
},
|
components: {
|
UploadFile,
|
LookFile
|
},
|
watch: {
|
asyncContract(bol) {
|
if(bol) {
|
this.getAllProjectData();
|
} else {
|
this.formContract = {
|
contracfileList: []
|
};
|
this.$refs.form.resetFields();
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import '../../style/layout-main.scss';
|
</style>
|