bonus-ui/src/views/material/ma/supplier/index.vue

858 lines
29 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
<el-form-item label="厂家编号" prop="supplierCode">
<el-input
v-model="queryParams.supplierCode"
placeholder="请输入厂家编号"
clearable
maxlength="64"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="厂家名称" prop="supplierName">
<el-input
v-model="queryParams.supplierName"
placeholder="请输入厂家名称"
clearable
maxlength="128"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="联系人" prop="contactPerson">
<el-input
v-model="queryParams.contactPerson"
placeholder="请输入联系人"
clearable
maxlength="64"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="联系电话" prop="contactPhone">
<el-input
v-model="queryParams.contactPhone"
placeholder="请输入联系电话"
clearable
maxlength="32"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 120px;">
<el-option label="启用" :value="1" />
<el-option label="停用" :value="0" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['machinery:type:add']"
>新增</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
>导出
</el-button>
</el-col>
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="houseList" ref="multipleTable" row-key="supplierId">
<!-- <el-table-column type="selection" width="55" align="center" :reserve-selection="true" /> -->
<el-table-column label="序号" align="center" width="80" type="index">
<template slot-scope="scope">
<span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
</template>
</el-table-column>
<!-- <el-table-column label="厂家ID" align="center" prop="supplierId" width="100" sortable/> -->
<el-table-column label="厂家编号" align="center" prop="supplierCode" sortable/>
<el-table-column label="厂家名称" align="center" prop="supplierName" sortable/>
<el-table-column label="联系人" align="center" prop="contactPerson" sortable/>
<el-table-column label="联系电话" align="center" prop="contactPhone" sortable/>
<el-table-column label="地址" align="center" prop="address" sortable/>
<el-table-column label="资质/执照编号" align="center" prop="qualification" sortable/>
<el-table-column label="状态" align="center" prop="status" width="100">
<template slot-scope="{ row }">
<el-tag size="small" type="success" v-if="row.status === 1">启用</el-tag>
<el-tag size="small" type="info" v-else>停用</el-tag>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" sortable/>
<el-table-column label="创建时间" align="center" prop="createTime" sortable/>
<el-table-column label="更新时间" align="center" prop="updateTime" sortable/>
<el-table-column label="操作" align="center" width="180">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['machinery:type:edit']"
>
编辑
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['machinery:type:del']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 新增或修改弹窗 -->
<el-dialog :title="title" :visible.sync="showHouse" width="1000px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px" >
<el-row>
<el-col :span="12">
<el-form-item label="厂家编号" prop="supplierCode" >
<el-input
v-model="form.supplierCode"
placeholder="请输入厂家编号"
maxlength="64"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="厂家名称" prop="supplierName" >
<el-input
v-model="form.supplierName"
placeholder="请输入厂家名称"
maxlength="128"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="联系人" prop="contactPerson" >
<el-input
v-model="form.contactPerson"
placeholder="请输入联系人"
maxlength="64"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系电话" prop="contactPhone">
<el-input
v-model="form.contactPhone"
placeholder="请输入联系电话"
maxlength="32"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="厂家地址" prop="address">
<el-input
v-model="form.address"
placeholder="请输入厂家地址"
maxlength="255"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="资质/执照编号" prop="qualification">
<el-input
v-model="form.qualification"
placeholder="请输入资质信息或执照编号"
maxlength="255"
/>
</el-form-item>
</el-col>
</el-row>
<el-row >
<el-col :span="12">
<el-form-item label="状态" prop="status">
<el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
<el-option label="启用" :value="1" />
<el-option label="停用" :value="0" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="备注" prop="remark">
<el-input
type="textarea"
:rows="6"
placeholder="请输入备注"
v-model="form.remark"
maxlength="255"
show-word-limit
>
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="营业执照" style="display: none">
<el-upload
class = "upload-demo"
action="#"
:file-list="businessLicenseListTemp"
:show-file-list="true"
:auto-upload="false"
:key="uploadKey"
list-type="picture-card"
accept=".png, .jpg, .jpeg, .pdf"
:on-change="handleChangeBusinessList"
:class="{ disabled: uploadDisabled }"
:on-preview="picturePreview"
:on-remove="handleRemoveElectricianImgList"
>
<!-- 文件格式下载,图片格式预览 -->
<div slot="file" slot-scope="{file}">
<img v-if="isImage(file)" class="el-upload-list__item-thumbnail" :src="file.url" alt="">
<div v-else class="picture-card-container" >
<img class="picture-card" :src="urlTemp" alt="">
<p class="file-name">{{ file.name }}</p>
</div>
<span class="el-upload-list__item-actions">
<span v-if="updataIf(file)" class="el-upload-list__item-delete" @click="handleDownload(file)">
<i class="el-icon-download" />
</span>
<span v-else class="el-upload-list__item-preview" @click="picturePreview(file)">
<i class="el-icon-zoom-in" />
</span>
<span class="el-upload-list__item-delete" @click="handleRemoveElectricianImgList(file)">
<i class="el-icon-delete" />
</span>
</span>
</div>
<i class="el-icon-plus avatar-uploader-icon" ></i>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 图片查看弹窗 -->
<el-dialog :visible.sync="dialogVisible" width="600px" height="600px" >
<img width="100%" height="500px" :src="dialogImageUrl" />
</el-dialog>
</div>
</template>
<script>
import { getListFacturer,getFacturerDetail,editFacturer,addFacturer,delFacturer,deleteFile } from "@/api/ma/supplier";
import { imgUpLoadThree, fileUpLoad } from '@/api/system/upload'
import { downloadFile,downloadFileData } from '@/utils/download'
import { getToken } from '@/utils/auth'
import {Base64} from 'js-base64'
import { forEach } from 'jszip';
export default {
name: "supplier",
data() {
return {
uploadKey: Date.now(),
// 遮罩层
loading: false,
loadingTwo: false,
// 是否显示项目部Id
showName: false,
// 是否显示施工预警信息
showWarn: false,
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
showHouse: false,
// 总条数
total: 0,
totalTwo : 0,
// 施工记录表格数据
houseList: [],
maxLength:100,//已选列表上限,防止数据过多请求报错
keeperDataRange:[],
// 班组人员表格数据
teamList: [],
teamTempList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
supplierCode: undefined,
supplierName: undefined,
contactPerson: undefined,
contactPhone: undefined,
status: undefined
},
// 查询参数
queryTeam: {
pageNum: 1,
pageSize: 10,
name: undefined,
sex: undefined,
teamId: undefined,
},
fileList:[],
businessLicenseFileList:[],
businessLicenseListTemp:[],
delBusinessFileIdList:[],
modelIdTemp:undefined,
base64Data:undefined,
//图片查看弹窗
dialogImageUrl: '',
dialogVisible: false,
// 表单参数
form: {},
// 表单校验
rules: {
supplierName: [
{
required: true,
message: "厂家名称不能为空",
trigger: "blur"
}
],
contactPhone: [
{
required: false,
message: "请输入联系电话",
trigger: "blur"
}
],
status: [
{
required: true,
message: "请选择状态",
trigger: "change"
}
]
},
//上传
upload: {
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + '/file/upload'
},
};
},
computed: {
//图片上传1张后隐藏上传框
uploadDisabled() {
return this.businessLicenseListTemp.length > 2
},
},
created() {
this.getList();
},
methods: {
//提交时循环fileList 获取raw文件
async getFileData() {
const fileTwo = []
this.businessLicenseListTemp.forEach(item => {
if (item?.hasOwnProperty('raw')) {
fileTwo.push(item.raw)
}
})
return { fileTwo }
},
// 图片上传
async imgUpLoadTwoAll(param) {
param.type = 'ma'
imgUpLoadThree(param)
.then((res) => {
if (res.code == 200) {
let obj = {'name':res.data.name,'url':res.data.url}
console.log('obj',obj)
this.businessLicenseFileList.push(obj);
} else {
// this.$msgError(res.msg)
this.$modal.msgError(res.msg)
}
})
.catch((error) => {
// this.$msgError(error)
this.$modal.msgError(error)
})
},
//上传组件-图片查看
picturePreview(file) {
this.dialogImageUrl = file.url;
const parts = file.name.split('.');
const extension = parts.pop();
if(extension === 'pdf'){
const windowName = file.name;
window.open(file.url,windowName)
}else{
this.dialogVisible = true
}
},
handleRemoveElectricianImgList(file, fileList) {
let sum = 0
this.businessLicenseListTemp.forEach((item, index) => {
if (item.uid == file.uid) {
sum = index
}
})
this.businessLicenseListTemp.splice(sum, 1)
if(file.status=='success'){
this.delBusinessFileIdList.push(file.url);
}
console.log('delBusinessFileIdList',this.delBusinessFileIdList)
},
isImage(file){
this.urlTemp = require('@/assets/file.png');
if(this.updataIf(file)){
return false
}else{
return true
}
},
// 判断文件类型,图片预览,文件下载
updataIf(e) {
if (e.fileName) {
const parts = e.fileName.split('.');
const extension = parts.pop();
if (extension === 'png' || extension === 'jpeg' || extension === 'jpg') {
return false
} else {
return true
}
} else {
const parts = e.name.split('.');
const extension = parts.pop();
if (extension === 'png' || extension === 'jpeg' || extension === 'jpg') {
return false
} else {
return true
}
}
},
handleDownload(file) {
console.log(file)
if(file.status === 'ready'){
downloadFile({ fileName: file.name, fileData: file.raw, fileType: 'application/vnd.ms-excel;charset=utf-8' })
}else if(file.status === 'success'){
downloadFileData( { fileName: file.name, fileUrl: file.url } )
// downloadFileData({ fileName: file.name,fileUrl:file.url })
}
},
handleChangeBusinessList(file, fileList) {
const fileListTemp = fileList.filter(item => {
return item.uid != file.uid
});
const parts = file.name.split('.');
const extension = parts.pop();
if(fileList.length > 3){
this.$message.warning('最多上传3张营业执照')
fileList = fileList.filter(item => {
return item.uid != file.uid
})
}else if(!(extension === 'pdf' || extension === 'png' || extension === 'jpg' || extension === 'jpeg')){
this.$message.warning('文件格式不正确')
fileList = fileList.filter(item => {
return item.uid != file.uid
})
}else if(file.size > 1024 * 1024 * 10){
this.$message.warning('文件大小不能超过10Mb')
fileList = fileList.filter(item => {
return item.uid != file.uid
})
}else if(file.name.length > 40){
this.$message.warning('文件名长度不能超过40个字符')
fileList = fileList.filter(item => {
return item.uid != file.uid
})
}else if(fileListTemp.some(item =>item.name === file.name)){
this.$message.warning('文件名重复')
fileList = fileList.filter(item => {
return item.uid != file.uid
})
}
fileList.forEach(file=>{
if(extension === 'pdf'){
this.urlTemp = require('../../../../assets/file.png');
}
});
this.businessLicenseListTemp = fileList;
},
async getList() {
this.loading = true;
getListFacturer(this.queryParams).then(response => {
this.houseList = (response && response.data && response.data.rows) ? response.data.rows : [];
this.total = (response && response.data && typeof response.data.total !== 'undefined') ? response.data.total : 0;
this.loading = false;
});
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.uploadKey = Date.now();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[];
this.businessLicenseFileList=[];
this.showHouse = true
this.title = '新增'
},
handleUpdate(row){
this.reset()
this.uploadKey = Date.now();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[];
this.businessLicenseFileList=[];
const supplierId = row.supplierId;
this.modelIdTemp = row.supplierId;
getFacturerDetail(supplierId).then((response) => {
this.form = response.data;
if(response.data.bmFileInfos!=null){
this.businessLicenseListTemp = response.data.bmFileInfos;
this.businessLicenseListTemp.forEach(item=>{
if(item.name.includes('/')){
const fileNameWithTimestamp = item.name.split('/').pop();
const parts = fileNameWithTimestamp.split('_');
const fileType = item.name.split('.').pop();
const mainFileName = parts.slice(0, parts.length - 1).join('_');
item.name = mainFileName + '.' +fileType;
}
})
}else{
this.businessLicenseListTemp = [];
}
this.showHouse = true
this.title = '修改'
})
},
// 表单重置
reset() {
this.form = {};
this.resetForm("form");
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.queryParams.supplierCode = undefined;
this.queryParams.supplierName = undefined;
this.queryParams.contactPerson = undefined;
this.queryParams.contactPhone = undefined;
this.queryParams.status = undefined;
this.handleQuery();
},
//** 提交按钮 */
submitForm() {
this.$refs["form"].validate(async valid => {
if (valid) {
if (this.form.supplierId != undefined) {
const reqData = new FormData();
if(this.businessLicenseListTemp.length!=0){
await this.getImaUploadEdit(),
await this.editFacturerTemp(this.form);
await this.deleteFile();
}else{
await this.editFacturerTemp(this.form);
await this.deleteFile();
}
} else {
if(this.businessLicenseListTemp.length!=0){
await this.getImaUpload(),
await this.addFacturerTemp(this.form);
}else{
await this.addFacturerTemp(this.form);
}
}
}
});
this.uploadKey = Date.now();
},
async getImaUpload(){
this.businessLicenseFileList = []
const reqData = new FormData()
const {fileTwo} = await this.getFileData()
let res = await imgUpLoadThree(fileTwo);
console.log('res',res)
if (res.code === 200) {
res.data.forEach(item=>{
let objTwo = { 'name': item.name, 'url': item.url,'modelId': null, 'fileType':4, 'taskType':9};
this.businessLicenseFileList.push(objTwo);
})
} else {
this.$modal.msgError(res.msg);
}
},
async getImaUploadEdit(){
this.businessLicenseFileList = []
const {fileTwo} = await this.getFileData()
console.log('fileTwo',fileTwo)
this.businessLicenseListTemp.forEach(item=>{
if(item.status=='success'){
let objThree = { 'name': item.name, 'url': item.url,'modelId': this.modelIdTemp, 'fileType':4, 'taskType':9};
this.businessLicenseFileList.push(objThree);
}
})
if(fileTwo.length!=0){
let res = await imgUpLoadThree(fileTwo);
if (res.code === 200) {
res.data.forEach(item=>{
let objTwo = { 'name': item.name, 'url': item.url,'modelId': this.modelIdTemp, 'fileType':4, 'taskType':9};
this.businessLicenseFileList.push(objTwo);
})
} else {
this.$modal.msgError(res.msg);
}
}
},
async addFacturerTemp(form){
this.form.bmFileInfos=this.businessLicenseFileList
addFacturer(form).then(response => {
this.$modal.msgSuccess("新增成功");
this.showHouse = false;
this.getList();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[];
this.businessLicenseFileList=[];
});
},
async editFacturerTemp(form){
this.form.bmFileInfos=this.businessLicenseFileList
editFacturer(form).then(response => {
this.$modal.msgSuccess("修改成功");
this.showHouse = false;
this.getList();
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[];
this.businessLicenseFileList=[];
});
},
async deleteFile(){
if(this.delBusinessFileIdList.length>0){
this.delBusinessFileIdList.forEach(async item=>{
const urlcode = Base64.encode(item)
const urlen = encodeURIComponent(urlcode)
await deleteFile(urlen);
})
}
},
async convertToBase64(data) {
const url = data;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('网络响应不正常');
}
const blob = await response.blob();
const reader = new FileReader();
reader.onloadend = () => {
this.base64Data = reader.result; // 获取 Base64 数据并存储
};
reader.readAsDataURL(blob); // 将 Blob 读取为 Data URL
} catch (error) {
console.error('获取文件失败:', error);
}
},
// 取消按钮
cancel() {
this.showHouse = false;
this.delBusinessFileIdList=[];
this.businessLicenseListTemp=[]
this.businessLicenseFileList=[];
this.uploadKey = Date.now();
this.reset();
},
/** 删除按钮操作 */
handleDelete(row) {
const supplierId = row.supplierId
this.$modal
.confirm('是否确认删除数据项?')
.then(function () {
return delFacturer(supplierId)
})
.then(() => {
this.$modal.msgSuccess('删除成功')
this.getList()
})
.catch(() => {})
},
handleExport() {
this.download('/material/wh_house_info/export', {
...this.queryParams
}, `仓库管理_${new Date().getTime()}.xlsx`)
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
}
};
</script>
<style lang="scss" scoped>
.uploadImg {
padding-top: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.deviceCode {
margin-top: 10px;
padding-bottom: 20px;
font-size: 18px;
}
::v-deep.el-table .fixed-width .el-button--mini {
width: 60px !important;
margin-bottom: 10px;
}
//隐藏图片上传框的css
::v-deep.disabled {
.el-upload--picture-card {
display: none;
}
}
::v-deep .el-upload-list--picture-card{
display: flex;
}
::v-deep .el-upload-list__item {
margin-bottom: 20px;
overflow: revert;
}
::v-deep .el-upload-list__item-actions{
overflow:hidden;
}
.upload-demo{
display: flex;
}
.el-upload-list__item-thumbnail{
height: 145px!important;
}
.picture-card-container{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.picture-card{
width: 100%;
height: 100%;
object-fit:cover;
justify-content: center;
// border: 1px solid #ddd;
// border-radius: 4px;
}
.file-name{
width: 90%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
position: absolute;
bottom: -35px;
margin-top: 8px;
text-align: center;
font-size: 12px;
color:#333;
z-index: 999999;
}
.file-overlay{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-size: 20px;
}
</style>