fix:合同&商品管理完成

This commit is contained in:
tt 2024-10-22 10:44:07 +08:00
parent e50987ce21
commit 748d1c51fd
4 changed files with 224 additions and 20 deletions

View File

@ -53,3 +53,18 @@ export function getContractListsApi() {
method: "get", method: "get",
}); });
} }
// 保存合同信息
export function postSubmitContractApi(data) {
return request({
url: `/admin/setting/savecontractsetting`,
method: "post",
data,
});
}
// 下载合同信息
export function postDownloadContractApi() {
return request({
url: `/admin/setting/getContractSetting`,
method: "get",
});
}

View File

@ -2,33 +2,90 @@
<div class="contract"> <div class="contract">
<div class="lay"> <div class="lay">
<div class="flex"> <div class="flex">
<el-button type="primary">境内合同</el-button> <el-button type="text">境内合同:</el-button>
<div class="word" v-if="contractObj.domestic"> <el-button type="primary" icon="el-icon-upload " @click="openDialog(1)">
文件:{{ contractObj.domestic }} 上传境内合同
</div> </el-button>
<el-button type="success" v-if="contractObj.domestic" <el-button
>下载境内合同</el-button type="success"
v-if="contractObj.domestic"
@click="downloadWord(1)"
> >
下载境内合同
</el-button>
</div> </div>
<div class="flex"> <div class="flex">
<el-button type="danger">境外合同</el-button> <el-button type="text">境外合同:</el-button>
<div class="word" v-if="contractObj.abroad"> <el-button
文件:{{ contractObj.abroad }} type="danger"
</div> icon="el-icon-s-promotion"
<el-button type="success" v-if="contractObj.abroad" @click="openDialog(2)"
>下载境外合同</el-button
> >
上传境外合同
</el-button>
<el-button
type="success"
v-if="contractObj.abroad"
@click="downloadWord(2)"
>
下载境外合同
</el-button>
</div> </div>
</div> </div>
<el-dialog
:visible.sync="dialogVisible"
@open="onOpen"
@close="onClose"
:title="dialogTitle"
>
<el-form ref="elForm" :model="formData" size="medium" label-width="120px">
<el-form-item label="上传" prop="trip_info" required>
<el-upload
ref="field105"
action=""
:before-upload="wordBeforeUpload"
:http-request="handlesAvatarSuccess"
:on-success="handleWordSuccess"
:on-error="handleUploadError"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:limit="1"
:file-list="fieldFileList"
accept=".pdf,.docx,.xlsx"
>
<el-button size="small" type="primary" icon="el-icon-upload"
>点击上传</el-button
>
</el-upload>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">确定</el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getContractListsApi } from "@/api/admin"; import {
getContractListsApi,
postSubmitContractApi,
postDownloadContractApi,
} from "@/api/admin";
import { getToken } from "@/utils/auth";
export default { export default {
data() { data() {
return { return {
contractObj: {}, contractObj: {},
dialogVisible: false,
dialogTitle: "",
fieldFileList: [],
formData: {
domestic: "",
abroad: "",
},
uploadPercent: 0,
}; };
}, },
created() { created() {
@ -39,7 +96,138 @@ export default {
const res = await getContractListsApi(); const res = await getContractListsApi();
this.contractObj = res.data; this.contractObj = res.data;
}, },
onSubmit() {}, async downloadWord(type) {
const res = await postDownloadContractApi();
if (res.error === 0) {
let blob_url = type === 1 ? res.data.domestic : res.data.abroad;
const extension = blob_url.substring(blob_url.lastIndexOf("."));
let txt = (type === 1 ? "境内合同" : "境外合同") + extension;
const url = window.URL.createObjectURL(new Blob([blob_url]));
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", txt);
document.body.appendChild(link);
link.click();
}
console.log(res, "下载合同");
},
onOpen() {},
onClose() {
this.$refs["elForm"].resetFields();
this.$refs.field105.uploadFiles = []; //
this.fieldFileList = [];
this.formData = {
domestic: "",
abroad: "",
};
},
close() {
console.log("1111", this.$refs.field105.uploadFiles);
this.dialogVisible = false;
this.$refs.field105.uploadFiles = []; //
},
openDialog(num) {
this.dialogTitle = num === 1 ? "境内合同" : "境外合同";
this.dialogVisible = true;
},
async handelConfirm() {
const isDomestic = this.dialogTitle === "境内合同";
const fileField = isDomestic ? "domestic" : "abroad";
const errorMessage = `请上传${isDomestic ? "境内" : "境外"}合同`;
if (!this.formData[fileField]) {
return this.$message.error(errorMessage);
}
const res = await postSubmitContractApi(this.formData);
if (res.error === 0) {
this.$message.success("上传成功");
this.getList();
}
this.close();
console.log(res, "wwww");
},
async handlesAvatarSuccess(file) {
try {
var formdata = new FormData();
formdata.append("file", file.file);
const res = await this.$axios.post("/admin/upload/index", formdata, {
headers: {
"Content-type": "multipart/form-data",
"X-Token": getToken(),
},
});
console.log(res, "收拾收拾");
if (res.error === 0) {
file.onSuccess(res);
}
} catch (error) {
console.log(file, "error--handlesAvatarSuccess");
let uid = file.file.uid;
let idx = this.$refs.field105.uploadFiles.findIndex(
(item) => item.uid === uid
);
this.$refs.field105.uploadFiles.splice(idx, 1);
this.$message.error(`上传失败`);
}
},
handleWordSuccess(res, file, fileList, index) {
console.log(res, file, fileList, "成功了");
if (res) {
const isDomestic = this.dialogTitle === "境内合同";
const fileUrl = `${window.location.protocol}//${window.location.host}${res.data}`;
isDomestic
? (this.formData.domestic = fileUrl)
: (this.formData.abroad = fileUrl);
this.fieldFileList = [
{
name: file.name,
uid: file.uid,
url: fileUrl,
},
];
this.$message.success("上传成功");
}
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}`);
},
handleRemove(file, fileList) {
console.log(file, fileList, "handleRemove");
this.formData.abroad = "";
this.formData.domestic = "";
this.fieldFileList.map((item, index) => {
if (item.uid === file.uid) {
this.fieldFileList.splice(index, 1);
}
});
},
handleUploadError(err, file) {
this.$message.error(`上传失败: ${file.name}`);
console.log(this.fieldFileList, "失败了");
this.fieldFileList.map((item, index) => {
if (item.uid === file.uid) {
this.fieldFileList.splice(index, 1);
}
});
},
wordBeforeUpload(file) {
const isRightType = [
"application/pdf",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
].includes(file.type);
const isRightSize = file.size / 1024 / 1024 < 2;
if (!isRightType) {
this.$message.error("只允许上传 PDF、DOCX、XLSX 格式的文件");
}
if (!isRightSize) {
this.$message.error("文件大小超过 2MB");
}
return isRightType && isRightSize;
},
}, },
}; };
</script> </script>

View File

@ -94,7 +94,7 @@
width="60" width="60"
prop="night" prop="night"
></el-table-column> ></el-table-column>
<el-table-column <!-- <el-table-column
align="type" align="type"
label="详细行程" label="详细行程"
width="180" width="180"
@ -105,7 +105,7 @@
scope.row.trip_info scope.row.trip_info
}}</span> }}</span>
</template> </template>
</el-table-column> </el-table-column> -->
<el-table-column width="180px" align="center" label="创建时间"> <el-table-column width="180px" align="center" label="创建时间">
<template slot-scope="scope"> <template slot-scope="scope">
@ -364,9 +364,10 @@ export default {
handleWordSuccess(res, file, fileList, index) { handleWordSuccess(res, file, fileList, index) {
console.log(res, file, fileList, "成功了"); console.log(res, file, fileList, "成功了");
if (res) { if (res) {
this.formData.trip_info = fileList // this.formData.trip_info = fileList
.map((item) => item.url || item.response.url) // .map((item) => item.url || item.response.url)
.join(","); // .join(",");
this.formData.trip_info = `${window.location.protocol}//${window.location.host}${res.data}`;
this.fieldFileList = [ this.fieldFileList = [
{ {
name: file.name, name: file.name,

View File

@ -40,7 +40,7 @@ module.exports = {
"/dev-api": { "/dev-api": {
// 接口地址 以 api开头的都走下面的配置 // 接口地址 以 api开头的都走下面的配置
// target: 'https://www.szjinao.cn', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2 // target: 'https://www.szjinao.cn', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
target: 'http://192.168.0.100:8787', // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2 target: "http://hex.jipinq.cn", // 代理目标地址为后端服务器地址 127.0.0.1 192.168.1.2
ws: true, // 是否支持 websocket 请求 支持 ws: true, // 是否支持 websocket 请求 支持
changeOrigin: true, // 是否启用跨域 changeOrigin: true, // 是否启用跨域
pathRewrite: { pathRewrite: {