YZProjectCloud/yanzhu-ui-app/miniprogram/pageage/mobile_attendance/attendance_config/info/index.js

127 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { getToken, getUserInfo } from "../../../../utils/auth.js";
const app = getApp();
import {
getMobileAttendanceConfigById,
updateMobileAttendanceConfig,
} from "../../../../api/project.js";
Page({
/**
* 页面的初始数据
*/
data: {
projectUserInfo: {},
projectUserInfo: {},
projectId: "",
projectName: "",
initData: {},
type: "",
cfgData: null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (!getToken()) {
wx.redirectTo({
url: "../../../pages/login/login",
});
}
const proUserInfo = getUserInfo();
this.setData({
projectUserInfo: proUserInfo.projectUserInfo,
projectId: app.globalData.useProjectId,
projectName: app.globalData.useProjectName,
initData: {
id: app.globalData.useProjectId,
text: app.globalData.useProjectName,
},
type: options.type,
});
if (options.id) {
this.loadData(options.id);
} else {
app.toast("参数错误!");
this.returnToPage();
}
},
loadData(id) {
getMobileAttendanceConfigById(id).then((res) => {
if (res.code == 200) {
this.setData({
cfgData: res.data,
type: res.data.valid == 0 ? "cfg" : "",
});
} else {
app.toast("参数错误!");
this.returnToPage();
}
});
},
onProjectSelect(e) {
let projectId = e.detail.id;
let projectName = e.detail.text;
app.globalData.useProjectId = projectId;
app.globalData.useProjectName = projectName;
this.onLoad();
},
returnToPage() {
wx.redirectTo({
url: "../list/index",
});
},
doDelete() {
// 添加确认提示
wx.showModal({
title: "确认失效",
content: "确定要将此考勤配置设置为失效状态吗?",
confirmColor: "#FF0000",
success: (res) => {
if (res.confirm) {
// 用户点击确定,执行失效操作
this.performDelete();
}
},
});
},
performDelete() {
// 实现失效功能
if (this.data.cfgData) {
// 创建失效的数据副本
let updateData = Object.assign({}, this.data.cfgData);
// 设置为失效状态 (1表示失效0表示有效)
updateData.valid = 1;
updateMobileAttendanceConfig(updateData)
.then((res) => {
if (res.code == 200) {
app.toast("考勤配置已失效!");
// 返回列表页面并刷新
this.returnToPage();
} else {
app.toast("操作失败,请重试");
}
})
.catch((error) => {
console.error("失效操作出错:", error);
app.toast("操作失败,请重试");
});
}
},
doEdit() {
try {
wx.setStorageSync("editAttCfg", this.data.cfgData);
wx.redirectTo({
url: "../add/index?type=edit&id=" + this.data.cfgData.id,
});
} catch (e) {
app.toast("参数错误!");
this.returnToPage();
}
},
});