1.命名规范
- mod 修改
- del 刪除
- sel 获取多个
- get 获取单个
以 item结尾
searchItem 搜素按钮
addItem 添加按钮
addItem() {
this.editFormVisible = true;
//清空之前表单中的数据
this.$refs.editForm.resetFields
}
modItem 修改按钮
modItem(row) {
// 显示弹出框
this.editFormVisible = true;
// 根据row中的主键构造入参
let para = {
majorId: row.majorId
};
// 使用后台提供的get接口获取 单条数据 并填充到editForm中
majorGet(para).then(res => {
let data = res.data.result;
//赋值
// this.utilCommen.getFormValue(this.editForm, data);
this.editForm = data
});
},
selItem 获取多个数据(刷新页面获取)
//获取分页数据
selItem() {
let param = this.searchInfo;
param.pageIndex = this.currentPage;
param.pageSize = this.pageSize;
majorPage(param).then(res => {
this.total = res.data.result.total;
this.majorList = res.data.result.records;
});
},
getItem 获取单个数据(页面刷新获取)
2.命名规则
a.搜索 searchInfo 对象里面的数据为搜索的字段
searchInfo: {
majorNo: "",
majorName: "",
majorGovName: "",
majorYear: ""
}
b.修改或者添加的字段对象里面属于需要填写的数据
editForm: {
campusUseFlag: "",
chargeLevel: "",
enrollFlag: "",
graduateFlag: "",
majorGovName: "",
majorLevel: "",
majorName: "",
majorNo: "",
majorType: "",
majorYear: "",
note: ""
}
3.addInfo和 modInfo
//提交 判断主键 是否存在 如果存在则是修改操作 否则是添加操作
submitInfo() {
this.editFormLoading = true;
//如果有editForm.userId 为假 则 是addInfo 否则 modInfo
if (!this.editForm.majorId) {
//添加
this.addInfo();
} else {
//修改
this.modInfo();
}
},
//点击修改数据
modInfo() {
//必填项都有 valid则返回true 进行后台校验 参数为editForm
this.$refs.editForm.validate(valid => {
if (valid) {
let param = this.editForm;
majorMod(param)
.then(res => {
let data = res.data;
if (data.returnFlag == "0") {
this.$notify.success("修改成功");
this.utilCommen.resetForm(this.searchInfo);
this.selItem();
this.editFormVisible = false;
} else {
this.$notify.error(data.returnMsg);
}
this.editFormLoading = false;
})
.catch(error => {
this.$message.error(error);
this.editFormLoading = false;
});
} else {
this.editFormLoading = false;
}
});
},
//点击添加
addInfo() {
//输入框校验
this.$refs.editForm.validate(valid => {
if (valid) {
let param = this.editForm;
majorAdd(param)
.then(res => {
let data = res.data;
if (data.returnFlag == "0") {
this.$notify.success("添加成功");
this.utilCommen.resetForm(this.searchInfo);
this.selItem();
this.editFormVisible = false;
} else {
this.$notify.error(data.returnMsg);
}
this.editFormLoading = false;
})
.catch(error => {
this.$message.error(error);
this.editFormLoading = false;
});
} else {
this.editFormLoading = false;
}
});
},
//删除
delItem(row) {
this.$confirm("确认删除吗?", "提示", { type: "warning" }).then(() => {
let params = { majorId: row.majorId };
majorDel(params)
.then(res => {
console.log(res);
let data = res.data;
if (data.returnFlag == 0) {
this.$notify.success("删除成功");
this.selItem();
} else {
this.$notify.error(data.returnMsg);
}
})
.catch(error => {
this.$message.error(error);
});
});
},
3.excel导出
//导出员工的excel
exportItem() {
// 防止反复点击Excel
this.excelLoading = true;
setTimeout(() => {
this.excelLoading = false;
}, 3000);
let param = this.searchInfo;
window.location.href =
majorExcelDownload +
"?params=" +
encodeURI(encodeURI(JSON.stringify(param)));
api文档中设置地址
### 写给自己看的