空管耐用品库存管理前端
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.

282 lines
7.2 KiB

5 months ago
<template>
<div>
<basic-container>
4 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>
5 months ago
</basic-container>
</div>
</template>
<script>
import { getList, add, remove, update, getCode } from "@/api/materials/list";
4 months ago
import { upload } from "@/api/materials/index";
5 months ago
export default {
data() {
return {
selectionList: [],
query: {},
loading: true,
4 months ago
codeList: [],
5 months ago
page: {
pageSize: 10,
currentPage: 1,
total: 0,
5 months ago
},
option: {
height: "auto",
5 months ago
calcHeight: 30,
tip: false,
searchShow: true,
4 months ago
searchMenuSpan: 18,
5 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,
4 months ago
menuAlign: "center",
searchMenuPosition: "right",
addBtnIcon: " ",
viewBtnIcon: " ",
delBtnIcon: " ",
editBtnIcon: " ",
5 months ago
column: [
{
label: "物资名称",
5 months ago
prop: "materialName",
5 months ago
search: true,
headerAlign: "center",
align: "center",
5 months ago
},
{
5 months ago
label: "规格/型号",
5 months ago
prop: "model",
headerAlign: "center",
align: "center",
5 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",
5 months ago
},
{
label: "单位",
5 months ago
prop: "unit",
headerAlign: "center",
align: "center",
5 months ago
},
4 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;
}
},
4 months ago
{
4 months ago
label: '图片',
prop: 'picture',
4 months ago
type: 'upload',
4 months ago
headerAlign: "center",
align: "center",
4 months ago
loadText: "图片上传中,请稍等",
span: 12,
action: process.env.VUE_APP_BASE_API + '/materials/upload', // 替换为实际上传接口地址
// propsHttp: { //配置请求接口返回的数据结构
// url: 'picture', //路径地址
// name: 'name', //图片名称
// res: 'data' //返回数据层级结构
// },
tip: "只能上传jpg/png文件",
4 months ago
rules: [{
required: true,
message: "请上传图片",
4 months ago
trigger: "change",
}],
formatter: (row, column) => {
const value = row.picture;
if (value === null || value === undefined || value === "") {
return "无"
}
return value;
},
onSuccess: (res, file, fileList) => {
// 上传成功后将图片路径赋值给表单
this.form.picture = res.data;
}
4 months ago
},
],
5 months ago
},
data: [],
dialogLogVisible: false,
activeName: "first",
5 months ago
tableData: [],
};
},
mounted() {
this.tableData = this.ckTable;
this.fetchMaterialCode();
5 months ago
},
methods: {
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("加载类别数据失败,请刷新重试");
});
},
5 months ago
handleLog() {
this.dialogLogVisible = true;
5 months ago
},
handleTabClick(tab, event) {
console.log(tab, event);
if (this.activeName == "first") {
this.tableData = this.ckTable;
5 months ago
}
if (this.activeName == "second") {
this.tableData = this.rkTable;
5 months ago
}
if (this.activeName == "third") {
this.tableData = this.bfTable;
5 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
//新增
5 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();
}
);
5 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) {
5 months ago
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
5 months ago
})
.then(() => {
5 months ago
return remove(row.id.toString());
5 months ago
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!",
5 months ago
});
5 months ago
done();
})
.catch((action) => {
if (action !== "cancel") {
5 months ago
this.$message({
type: "error",
message: "操作失败",
5 months ago
});
}
5 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;
},
},
5 months ago
};
</script>