空管耐用品库存管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
8.2 KiB

6 months ago
<template>
<div>
<basic-container>
5 months ago
<avue-crud :option="option" v-model="form" :data="data" @row-del="rowDel" @on-load="onLoad"
:table-loading="loading" @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange"
@search-reset="searchReset" :page.sync="page">
</avue-crud>
4 months ago
<template slot="picture" slot-scope="scope">
<el-upload
class="avatar-uploader"
action="/api/upload"
:show-file-list="false"
list-type="picture-card"
:on-success="(res, file) => handleUploadSuccess(res, file, scope)"
:before-upload="beforeUpload"
:on-preview="handlePreview"
:headers="uploadHeaders"
>
<img v-if="scope.row.picture" :src="scope.row.picture" class="avatar" style="width:100%;height:100%;object-fit:contain;" />
<i v-else class="el-icon-plus"></i>
</el-upload>
</template>
6 months ago
</basic-container>
</div>
</template>
<script>
import { getList, add, remove, update, getCode } from "@/api/materials/list";
6 months ago
export default {
data() {
return {
4 months ago
form: {
imageUrl: "",
picture: "" // 用于存储接口返回的图片地址
},
6 months ago
selectionList: [],
query: {},
loading: true,
5 months ago
codeList: [],
6 months ago
page: {
pageSize: 10,
currentPage: 1,
total: 0,
6 months ago
},
option: {
height: "auto",
6 months ago
calcHeight: 30,
tip: false,
searchShow: true,
5 months ago
searchMenuSpan: 18,
6 months ago
border: true,
index: true,
selection: true,
viewBtn: true,
dialogClickModal: false,
menu: true,
selection: false,
printBtn: false,
refreshBtn: false,
gridBtn: false,
gridBackgroundImage: false,
gridSpan: false,
filterBtn: false,
columnBtn: false,
5 months ago
menuAlign: "center",
searchMenuPosition: "right",
addBtnIcon: " ",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
6 months ago
column: [
{
label: "物资名称",
5 months ago
prop: "materialName",
6 months ago
search: true,
headerAlign: "center",
align: "center",
6 months ago
},
{
5 months ago
label: "规格/型号",
5 months ago
prop: "model",
headerAlign: "center",
align: "center",
6 months ago
},
{
label: "类别",
prop: "materialCode",
type: "select",
headerAlign: "center",
align: "center",
dicData: [],
5 months ago
props: {
label: "label",
value: "value",
5 months ago
},
dataType: "string",
6 months ago
},
{
label: "单位",
5 months ago
prop: "unit",
headerAlign: "center",
align: "center",
6 months ago
},
5 months ago
{
label: "描述",
prop: "remark",
headerAlign: "center",
align: "center",
formatter: (row, column) => {
const value = row.remark;
if (value === null || value === undefined || value === "") {
return "无";
}
return value;
}
},
{
5 months ago
label: '图片',
prop: 'picture',
headerAlign: "center",
align: "center",
4 months ago
slot: true, // 使用自定义插槽
add: true, // 新增时显示
edit: true, // 编辑时显示
view: true, // 查看时显示
5 months ago
rules: [{
required: true,
message: "请上传图片",
4 months ago
trigger: "change"
}]
5 months ago
},
4 months ago
// {
// label: '图片',
// prop: 'picture',
// type: 'upload',
// headerAlign: "center",
// align: "center",
// loadText: "图片上传中,请稍等",
// span: 12,
// // propsHttp: { //配置请求接口返回的数据结构
// // url: 'picture', //路径地址
// // name: 'name', //图片名称
// // res: 'data' //返回数据层级结构
// // },
// tip: "只能上传jpg/png文件",
// rules: [{
// required: true,
// message: "请上传图片",
// trigger: "change",
// }],
// formatter: (row, column) => {
// const value = row.picture;
// if (value === null || value === undefined || value === "") {
// return "无"
// }
// return value;
// }
// },
],
6 months ago
},
data: [],
dialogLogVisible: false,
activeName: "first",
6 months ago
tableData: [],
};
},
mounted() {
this.tableData = this.ckTable;
this.fetchMaterialCode();
6 months ago
},
methods: {
4 months ago
fetchMaterialCode() {
getCode()
.then((res) => {
const dicData = res.data.result.map((item) => ({
label: item.name,
value: item.code,
}));
const targetColumn = this.option.column.find(
(col) => col.prop === "materialCode"
);
if (targetColumn) {
targetColumn.dicData = dicData;
}
})
.catch((error) => {
this.$message.error("加载类别数据失败,请刷新重试");
});
},
6 months ago
handleLog() {
this.dialogLogVisible = true;
6 months ago
},
handleTabClick(tab, event) {
console.log(tab, event);
if (this.activeName == "first") {
this.tableData = this.ckTable;
6 months ago
}
if (this.activeName == "second") {
this.tableData = this.rkTable;
6 months ago
}
if (this.activeName == "third") {
this.tableData = this.bfTable;
6 months ago
}
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
5 months ago
//新增
6 months ago
rowSave(row, done, loading) {
add(row).then(
() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!",
});
done();
},
(error) => {
window.console.log(error);
loading();
}
);
6 months ago
},
5 months ago
//修改
rowUpdate(row, index, done, loading) {
update(row).then(
() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!",
});
done(row);
},
(error) => {
window.console.log(error);
loading();
}
);
5 months ago
},
//删除
rowDel(row, index, done) {
6 months ago
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
6 months ago
})
.then(() => {
5 months ago
return remove(row.id.toString());
6 months ago
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!",
6 months ago
});
5 months ago
done();
})
.catch((action) => {
if (action !== "cancel") {
5 months ago
this.$message({
type: "error",
message: "操作失败",
5 months ago
});
}
6 months ago
});
},
onLoad(page, params = {}) {
this.loading = true;
getList(
page.currentPage,
page.pageSize,
Object.assign(params, this.query)
).then((res) => {
this.data = res.data.result.list;
this.loading = false;
this.page.total = res.data.result.total;
5 months ago
// this.selectionClear();
});
this.loading = false;
},
},
6 months ago
};
</script>