qms/src/mixins/basic-page.js

220 lines
5.9 KiB
JavaScript
Raw Normal View History

2023-01-06 10:03:31 +08:00
/*
* @Author: zwq
* @Date: 2022-08-24 11:19:43
2023-07-11 17:01:39 +08:00
* @LastEditors: zhp
* @LastEditTime: 2023-07-11 11:03:11
2023-01-06 10:03:31 +08:00
* @Description:
*/
export default {
data() {
/* eslint-disable */
return {
urlOptions: {
getDataListURL: '',
deleteURL: '',
statusUrl: '',
2023-05-11 16:22:07 +08:00
exportURL: ''
2023-01-06 10:03:31 +08:00
},
tableData: [],
listQuery: {
limit: 10,
page: 1,
total: 1,
},
dataListLoading: false,
2023-06-30 16:29:32 +08:00
addOrEditTitle: '',
2023-01-06 10:03:31 +08:00
addOrUpdateVisible: false,
2023-06-30 16:29:32 +08:00
searchsTitle: '',
searchsVisible: false,
2023-01-06 10:03:31 +08:00
}
},
created() {
},
2023-07-11 17:01:39 +08:00
mounted() {
2023-07-07 16:32:42 +08:00
this.getDataList()
2023-01-06 10:03:31 +08:00
},
methods: {
// 获取数据列表
getDataList() {
this.dataListLoading = true;
this.$http
.get(this.urlOptions.getDataListURL, {
params: this.listQuery,
})
.then(({ data: res }) => {
this.dataListLoading = false;
if (res.code !== 0) {
this.tableData = [];
this.listQuery.total = 0;
return this.$message.error(res.msg);
}
this.tableData = res.data.list;
this.listQuery.total = res.data.total;
})
.catch(() => {
this.dataListLoading = false;
2023-05-24 16:40:29 +08:00
})
2023-01-06 10:03:31 +08:00
},
// 每页数
sizeChangeHandle(val) {
this.listQuery.limit = val;
this.listQuery.page = 1;
this.getDataList();
},
// 当前页
currentChangeHandle(val) {
this.listQuery.page = val;
this.getDataList();
},
// 新增 / 修改
addOrUpdateHandle(id) {
this.addOrUpdateVisible = true;
this.$nextTick(() => {
this.$refs.addOrUpdate.init(id);
});
},
2023-06-30 16:29:32 +08:00
// 条件搜索
searchsHandle() {
this.searchsVisible = true;
this.$nextTick(() => {
this.$refs.searchsRef.init();
});
},
2023-01-06 10:03:31 +08:00
cancel(id) {
this.$refs["popover-" + id].showPopper = false;
},
//改变状态
changeStatus(id) {
this.$http
.post(this.urlOptions.statusUrl, { id })
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg);
}
this.$refs["popover-" + id].showPopper = false;
this.$message({
message: this.$t("prompt.success"),
type: "success",
duration: 500,
onClose: () => {
this.getDataList();
},
});
})
.catch(() => { });
},
//tableBtn点击
handleClick(val) {
if (val.type === "edit") {
this.addOrUpdateVisible = true;
this.addOrEditTitle = "编辑";
this.$nextTick(() => {
this.$refs.addOrUpdate.init(val.data.id);
});
2023-05-12 13:43:45 +08:00
} else if (val.type === "delete") {
this.deleteHandle(val.data.id, val.data.name,val.data._pageIndex)
} else if (val.type === "change") {
this.changeStatus(val.data.id)
} else {
this.otherMethods(val)
2023-01-06 10:03:31 +08:00
}
},
2023-05-12 13:43:45 +08:00
// 删除
deleteHandle(id, name,index) {
this.$confirm(`确定对${name?'[名称='+name+']':'[序号='+index+']'}进行删除操作?`, "提示", {
2023-01-06 10:03:31 +08:00
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
this.$http.delete(this.urlOptions.deleteURL, { data: [id] }).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.getDataList();
},
});
} else {
this.$message.error(data.msg);
}
});
})
.catch(() => { });
},
//search-bar点击
buttonClick(val) {
switch (val.btnName) {
case "search":
this.listQuery.xm1 = val.xm1;
this.listQuery.xm2 = val.xm2;
this.listQuery.page = 1;
this.getDataList();
break;
case "add":
this.addOrEditTitle = '新增'
this.addOrUpdateVisible = true;
this.addOrUpdateHandle()
break;
default:
console.log(val)
}
},
handleCancel() {
this.$refs.addOrUpdate.formClear()
this.addOrUpdateVisible = false
this.addOrEditTitle = ''
},
2023-06-30 16:29:32 +08:00
searchsCancel(){
this.$refs.searchsRef.formClear()
this.searchsVisible = false
this.searchsTitle = ''
},
2023-01-06 10:03:31 +08:00
handleConfirm() {
this.$refs.addOrUpdate.dataFormSubmit()
},
2023-06-30 16:29:32 +08:00
searchsConfirm(){
this.$refs.searchsRef.dataFormSubmit()
},
2023-01-06 10:03:31 +08:00
successSubmit() {
this.handleCancel()
this.getDataList()
},
2023-06-30 16:29:32 +08:00
searchsSubmit(obj){
this.listQuery = {...this.listQuery,...obj}
this.searchsCancel()
this.getDataList()
},
2023-01-06 10:03:31 +08:00
// 导出
exportHandle(name) {
this.$http
2023-05-11 16:22:07 +08:00
.get(this.urlOptions.exportURL, { responseType: "blob" })
2023-01-06 10:03:31 +08:00
.then(({ data: res }) => {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = year + "-" + month + "-" + strDate;
const blob = new Blob([res]);
const downloadElement = document.createElement("a");
const href = window.URL.createObjectURL(blob); // 创建下载的链接
downloadElement.href = href;
downloadElement.download = `${name + currentdate}.xls`; // 下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); // 点击下载
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href);
})
.catch(() => { });
}
}
2023-05-11 16:22:07 +08:00
}