YZProjectCloud/yanzhu-ui-app/miniprogram/pageage/mobile_attendance/attendance/add/index.js

84 lines
1.9 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 } from "../../../../api/project.js";
Page({
/**
* 页面的初始数据
*/
data: {
projectUserInfo: {},
projectUserInfo: {},
projectId: "",
projectName: "",
initData: {},
type: "",
cfgData: null,
arrSel: "in",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (!getToken()) {
wx.redirectTo({
url: "../../../pages/login/login",
});
}
const proUserInfo = getUserInfo();
// 根据当前时间设置arrSel的值14点前为in14点后为out
const now = new Date();
const arrSel = now.getHours() < 14 ? "in" : "out";
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,
arrSel: arrSel,
});
if (options.id) {
this.loadData(options.id);
} else {
app.toast("参数错误!");
this.returnToPage();
}
//todo 14点前 arrSel=in,之后arrSel=out
},
loadData(id) {
try {
let cfgData = wx.getStorageSync("editAttCfg");
if (cfgData) {
this.setData({
cfgData: cfgData,
});
} else {
app.toast("参数错误!");
this.returnToPage();
}
} catch (e) {
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",
});
},
});