刘翔宇-旅管家 3 years ago
parent 938fc5d2f2
commit 9995d26cdd

@ -2,8 +2,8 @@
ENV = 'development' ENV = 'development'
# base api # base api
#VUE_APP_DOMIAN=http://192.168.60.99:9003/ VUE_APP_DOMIAN=http://192.168.60.99:9003/
VUE_APP_DOMIAN=http://hdcontract.ali251.langye.net/ #VUE_APP_DOMIAN=http://hdcontract.ali251.langye.net/
VUE_APP_BASE_API = '' VUE_APP_BASE_API = ''
VUE_APP_UPLOAD=http://hdcontract.ali251.langye.net/api/admin/upload-file VUE_APP_UPLOAD=http://hdcontract.ali251.langye.net/api/admin/upload-file

@ -1,330 +1,348 @@
<template> <template>
<div> <div>
<Modal v-model="isShow" title="附件" footer-hide :width="64"> <Modal v-model="isShow" title="附件" footer-hide :width="64">
<Button v-if="role === 1 || role === 0" type="primary" shape="circle" icon="ios-add" @click="add" <Button v-if="role === 1 || role === 0" type="primary" shape="circle" icon="ios-add" @click="add"></Button>
>新增</Button
>
<Table <Table style="margin-top: 10px" :height="320" :data="detail.attachment" :columns="columns">
style="margin-top: 10px"
:height="320"
:data="detail.attachment"
:columns="columns"
>
</Table> </Table>
</Modal> </Modal>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from "@/utils/auth"; import {
import { show, save, store } from "@/api/propertyPlan"; getToken
export default { } from "@/utils/auth";
props: { import {
role: Number show,
}, save,
data() { store
return { } from "@/api/propertyPlan";
fileList: [], export default {
action: process.env.VUE_APP_UPLOAD, props: {
key: 1, role: Number
isShowModal: false, },
isShow: false, data() {
id: "", return {
type: "", fileList: [],
action: process.env.VUE_APP_UPLOAD,
key: 1,
isShowModal: false,
isShow: false,
id: "",
type: "",
detail: {}, detail: {},
columns: [ columns: [{
{ key: "file",
key: "file", title: "文件(点击下载)",
title: "文件(点击下载)", width: 200,
width: 200, render: (h, {
render: (h, { row }) => { row
return h( }) => {
"a", return h(
{ "a", {
attrs: { download: row.file.original_name, href: row.file.url }, attrs: {
}, download: row.file.original_name,
row.file.original_name href: row.file.url
); },
},
row.file.original_name
);
},
}, },
}, {
{ key: "content",
key: "content", title: "内容",
title: "内容", minWidth: 220,
minWidth: 220, align: "left",
align: "left", },
}, {
{ key: "date",
key: "date", title: "日期",
title: "日期", width: 160,
width: 160, },
}, {
{ key: "operate",
key: "operate", title: "操作",
title: "操作", width: 100,
width: 100, align: "left",
align: "left", render: (h, {
render: (h, { row }) => { row
if (this.role == 0 || this.role == 1) }) => {
return h("Poptip", { if (this.role == 0 || this.role == 1)
props: { return h("Poptip", {
transfer: true, props: {
confirm: true, transfer: true,
title: "确认要删除吗", confirm: true,
}, title: "确认要删除吗",
scopedSlots: { },
default: () => { scopedSlots: {
return h( default: () => {
"Button", return h(
{ "Button", {
props: { props: {
ghost: true, ghost: true,
size: "small", size: "small",
type: "error", type: "error",
}, },
},
"删除"
);
}, },
"删除" },
); on: {
}, ["on-ok"]: (_) => {
}, let attachments = this.detail.attachment
on: { .filter((i) => i.id !== row.id)
["on-ok"]: (_) => { .map((i) => {
let attachments = this.detail.attachment return {
.filter((i) => i.id !== row.id) file: i.file.id,
.map((i) => { date: i.date,
return { content: i.content,
file: i.file.id, };
date: i.date, });
content: i.content, save({
}; ...this.detail,
}); attachment_list: attachments,
save({ content_list: this.detail.content.map((i) => {
...this.detail, return {
attachment_list: attachments, title: i.title,
content_list: this.detail.content.map((i) => { content: i.content,
return { date: i.date,
title: i.title, };
content: i.content, }),
date: i.date, }).then((_) => {
}; this.$message({
}), type: "success",
}).then((_) => { message: "删除成功",
this.$message({ });
type: "success", this.getDetail();
message: "删除成功", });
}); },
this.getDetail(); },
}); });
}, },
},
});
}, },
}, ],
], };
};
},
methods: {
show() {
this.isShow = true;
},
hidden() {
this.isShow = false;
}, },
init() { methods: {
for (let key in this.form) { show() {
if (this.form[key] instanceof Array) { this.isShow = true;
this.form[key] = []; },
hidden() {
this.isShow = false;
},
init() {
for (let key in this.form) {
if (this.form[key] instanceof Array) {
this.form[key] = [];
} else {
this.form[key] = "";
}
}
this.$refs["dialog"].clearValidate();
},
setId(id) {
if (typeof id == "number") {
this.id = id;
} else { } else {
this.form[key] = ""; console.error("error typeof id: " + typeof id);
} }
} },
this.$refs["dialog"].clearValidate(); getId() {
}, return this.id;
setId(id) { },
if (typeof id == "number") { setType(type = "add") {
this.id = id; let types = ["add", "editor"];
} else { if (types.includes(type)) {
console.error("error typeof id: " + typeof id); this.type = type;
} } else {
}, console.warn("Unknown type: " + type);
getId() { }
return this.id; },
}, setForm(key = [], value = []) {
setType(type = "add") { if (key instanceof Array) {
let types = ["add", "editor"]; key.forEach((key, index) => {
if (types.includes(type)) { this.form[key] = value[index] ?? "";
this.type = type; });
} else { }
console.warn("Unknown type: " + type); if (typeof key === "string") {
} this.form[key] = value;
}, }
setForm(key = [], value = []) { if (!key) {
if (key instanceof Array) { this.init();
key.forEach((key, index) => { }
this.form[key] = value[index] ?? ""; },
async getDetail() {
const res = await show({
id: this.getId()
}); });
} this.detail = res;
if (typeof key === "string") { console.log(res);
this.form[key] = value; },
}
if (!key) {
this.init();
}
},
async getDetail() { async add() {
const res = await show({ id: this.getId() }); let form = {
this.detail = res; date: this.$moment(new Date()).format("YYYY-MM-DD"),
console.log(res); file: "",
}, content: "",
};
async add() { this.fileList = [];
let form = { const h = this.$createElement;
date: this.$moment(new Date()).format("YYYY-MM-DD"), this.$msgbox({
file: "", title: "新增附件",
content: "", message: h(
}; "el-form", {
const h = this.$createElement; key: ++this.key,
this.$msgbox({ props: {
title: "新增附件", model: form,
message: h( "label-width": "80px"
"el-form", }
{ key: ++this.key, props: { model: form, "label-width": "80px" } }, },
[ [
h("el-form-item", { h("el-form-item", {
props: { label: "文件", required: true }, props: {
scopedSlots: { label: "文件",
default: () => required: true
h( },
"el-upload", scopedSlots: {
{ default: () =>
props: { h(
action: this.action, "el-upload", {
"file-list": this.fileList, props: {
limit: 1, action: this.action,
headers: { "file-list": this.fileList,
Authorization: "Bearer " + getToken(), limit: 1,
}, headers: {
accept: Authorization: "Bearer " + getToken(),
".rar,.zip,.doc,.docx,.pdf,.jpg,.png,.gif,.xls,.xlsx", },
"on-success": (response, file, fileList) => { accept: ".rar,.zip,.doc,.docx,.pdf,.jpg,.png,.gif,.xls,.xlsx",
this.fileList = fileList; "on-success": (response, file, fileList) => {
form.file = response?.id; this.fileList = fileList;
}, form.file = response?.id;
"before-upload": (file) => { },
if (file.size / 1000 > 50 * 1024) { "before-upload": (file) => {
this.$message({ if (file.size / 1000 > 50 * 1024) {
type: "warning", this.$message({
message: "上传文件大小超过5M", type: "warning",
}); message: "上传文件大小超过5M",
return false; });
} return false;
}, }
"on-remove": (file, fileList) => { },
this.fileList = fileList; "on-remove": (file, fileList) => {
this.fileList = fileList;
},
}, },
}, },
}, [
[ h(
h( "el-button", {
"el-button", props: {
{ type: "primary",
props: { size: "small",
type: "primary", },
size: "small", slot: "trigger",
}, },
slot: "trigger", "选取文件"
}, ),
"选取文件" h(
), "div", {
h( class: "el-upload__tip",
"div", slot: "tip",
{ },
class: "el-upload__tip", "支持文件格式:.docx.xlsx.pdf.png.jpg\n单个文件不能超过50M"
slot: "tip", ),
]
),
},
}),
h("el-form-item", {
props: {
label: "内容"
},
scopedSlots: {
default: () =>
h("textarea", {
key: this.key,
class: "el-textarea__inner",
props: {
value: form.content
},
on: {
["input"]: (e) => {
form.content = e.target.value;
}, },
"支持文件格式:.docx.xlsx.pdf.png.jpg\n单个文件不能超过50M"
),
]
),
},
}),
h("el-form-item", {
props: { label: "内容" },
scopedSlots: {
default: () =>
h("textarea", {
key: this.key,
class: "el-textarea__inner",
props: { value: form.content },
on: {
["input"]: (e) => {
form.content = e.target.value;
}, },
}, }),
}), },
},
}),
]
),
showCancelButton: true,
confirmButtonText: "确定",
cancelButtonText: "取消",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
if (!form.file) {
this.$message({
type: "warning",
message: "请上传附件",
});
return;
}
instance.confirmButtonLoading = true;
instance.confirmButtonText = "保存中...";
this.detail.attachment_list = [
...this.detail.attachment?.map((i) => {
return { file: i.file.id, content: i.content, date: i.date };
}), }),
form, ]
]; ),
save(this.detail) showCancelButton: true,
.then((_) => { confirmButtonText: "确定",
cancelButtonText: "取消",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
if (!form.file) {
this.$message({ this.$message({
type: "success", type: "warning",
message: "保存成功", message: "请上传附件",
}); });
instance.confirmButtonLoading = false; return;
done(); }
this.getDetail(); instance.confirmButtonLoading = true;
this.fileList = []; instance.confirmButtonText = "保存中...";
}) this.detail.attachment_list = [
.catch((_) => { ...this.detail.attachment?.map((i) => {
instance.confirmButtonLoading = false; return {
}); file: i.file.id,
} else { content: i.content,
done(); date: i.date
} };
}, }),
}); form,
];
save(this.detail)
.then((_) => {
this.$message({
type: "success",
message: "保存成功",
});
instance.confirmButtonLoading = false;
done();
this.getDetail();
this.fileList = [];
})
.catch((_) => {
instance.confirmButtonLoading = false;
});
} else {
done();
}
},
});
},
}, },
}, watch: {
watch: { isShow(val) {
isShow(val) { if (val) {
if (val) { this.getDetail();
this.getDetail(); } else {
} else { this.id = "";
this.id = ""; }
this.fileList = []; },
}
}, },
}, created() {},
created() {}, };
};
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
::v-deep .el-input__inner { ::v-deep .el-input__inner {
text-align: left; text-align: left;
} }
</style> </style>

Loading…
Cancel
Save