| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 |
- var app = getApp();
- var calendarSignData;
- var date;
- var calendarSignDay;
- var is_qd;
- // 引入SDK核心类
- var QQMapWX = require('../../lib/qqmap-wx-jssdk.js');
- // 实例化API核心类
- var qqmapsdk = new QQMapWX({
- //秘钥key
- key: 'VIWBZ-I456G-D5JQP-ICQKE-SKMYS-44BMR',
- });
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- latitude: '',
- longitude: '',
- clockHours: '',
- clockMinute: '',
- flag: false,
- timer: null,
- hoursColock: '',
- // 当前位置坐标坐标
- posObj: {
- latitude: null,
- longitude: null,
- },
- markers: [
- {
- iconPath: './../../../images/weatherImg/qiandao.png',
- id: 1,
- name: '打卡地点',
- latitude: null,
- longitude: null,
- width: 30,
- height: 30,
- callout: {
- content: '打卡地点',
- color: '#ffffff',
- fontSize: 13,
- borderRadius: 20,
- bgColor: '#009ad6',
- textAlign: 'center',
- padding: 8,
- display: 'ALWAYS',
- },
- },
- ],
- // 判断是上班打卡还是下班打卡(true为上班打卡,false为下班打卡)
- startOrenDFlag: 0,
- showBtnFlag: true, // 判断是否是中心人员(是否需要打卡)
- // 批量操作相关
- showBatchModal: false, // 是否显示批量操作弹窗
- batchSignType: 0, // 批量操作类型:0-签到,1-签退
- batchModalTitle: '', // 弹窗标题
- batchModalButtonText: '', // 弹窗按钮文本
- // 部门和人员选择
- departments: [], // 部门列表
- departmentNames: [], // 部门名称列表
- selectedDepartmentIndex: '', // 选中的部门索引
- selectedDepartmentId: '', // 选中的部门ID
- users: [], // 人员列表
- userList: [], // 人员名称列表
- selectedUserId: [], // 选中的人员ID数组
- selectedUserNames: [], // 选中的人员姓名数组
- // 权限控制
- buttonNodes: [], // 按钮权限节点
- },
- //页面跳转
- nav(e) {
- ////console.log("路径", e.currentTarget.dataset.url)
- var url = e.currentTarget.dataset.url;
- wx.navigateTo({
- url: url,
- });
- },
- // 显示批量操作弹窗
- showBatchModal(e) {
- this.setData({
- showBatchModal: true,
- batchSignType: 0, // 默认批量上班签到
- batchModalTitle: '批量上班签到',
- batchModalButtonText: '签到',
- selectedDepartmentIndex: '',
- selectedDepartmentId: '',
- selectedUserId: [],
- selectedUserNames: [],
- users: [],
- userList: []
- });
- // 获取部门列表
- this.getDepartments();
- },
- // 批量签到类型选择事件
- bindBatchTypeChange(e) {
- const type = parseInt(e.detail.value); // 将字符串转换为数字
- this.setData({
- batchSignType: type,
- batchModalTitle: type === 0 ? '批量上班签到' : '批量下班签到',
- batchModalButtonText: type === 0 ? '签到' : '签退'
- });
- },
- // 隐藏批量操作弹窗
- hideBatchModal() {
- this.setData({
- showBatchModal: false
- });
- },
- // 获取部门列表
- getDepartments() {
- var that = this;
- var token = wx.getStorageSync('token');
-
- wx.showLoading({
- title: '加载部门中...',
- mask: true
- });
-
- wx.request({
- url: app.globalData.httpsUrlServer + '/sysdepartment/selectDepartmentByPageListpara?stateid=2',
- method: 'post',
- data: {data: {
- current: 1,
- fDeptname: "",
- size: 1000
- }},
- dataType: 'json',
- header: {
- 'Content-Type': 'application/json;charset=UTF-8',
- token: token,
- fSource: 1,
- },
- success: function (res) {
- wx.hideLoading();
- if (res.statusCode == 200 && res.data.status == 200) {
- console.log('部门列表:', res.data.data.data);
- var departments = res.data.data.data || [];
- // 注意:work_order_info中的字段名是fDeptname和fDeptid,需要检查实际API返回的字段名
- var formattedDepartments = departments.map(dept => ({
- fDepartmentid: dept.fDeptid || dept.fDepartmentid,
- fDepartmentname: dept.fDeptname || dept.fDepartmentname
- }));
- var departmentNames = formattedDepartments.map(dept => dept.fDepartmentname);
- that.setData({
- departments: formattedDepartments,
- departmentNames: departmentNames
- });
- }
- },
- fail: function (err) {
- wx.hideLoading();
- console.error('获取部门列表失败:', err);
- wx.showToast({
- title: '获取部门失败',
- icon: 'none'
- });
- }
- });
- },
- // 获取人员列表
- getUsers(departmentId) {
- if (!departmentId) return;
-
- var that = this;
- var token = wx.getStorageSync('token');
-
- wx.showLoading({
- title: '加载人员中...',
- mask: true
- });
-
- wx.request({
- url: app.globalData.httpsUrlServer + '/sysuseraccount/selectUserAccountAppByPageList',
- method: 'post',
- data: {data: {
- current: 1,
- size: 9999,
- fDeptid: departmentId
- }},
- dataType: 'json',
- header: {
- 'Content-Type': 'application/json;charset=UTF-8',
- token: token,
- fSource: 1,
- },
- success: function (res) {
- wx.hideLoading();
- if (res.statusCode == 200 && res.data.status == 200) {
- var users = res.data.data.data || [];
- console.log('人员列表:', users);
- // 注意:需要检查实际API返回的字段名是否与预期一致
- var formattedUsers = users.map(user => ({
- fExpandint1: user.fUserid || user.fExpandint1,
- fRealname: user.fUsername || user.fRealname,
- fDepartmentid: user.fDeptid || user.fDepartmentid
- }));
- console.log('格式化后的人员列表:', formattedUsers);
- that.setData({
- users: formattedUsers,
- userList: formattedUsers
- });
- }
- },
- fail: function (err) {
- wx.hideLoading();
- console.error('获取人员列表失败:', err);
- wx.showToast({
- title: '获取人员失败',
- icon: 'none'
- });
- }
- });
- },
- // 部门选择事件
- bindDepartmentChange(e) {
- const index = e.detail.value;
- const departmentId = this.data.departments[index].fDepartmentid;
- this.setData({
- selectedDepartmentIndex: index,
- selectedDepartmentId: departmentId,
- // 重置人员选择
- selectedUserId: [],
- selectedUserNames: []
- });
- // 获取该部门下的人员列表
- this.getUsers(departmentId);
- },
- // 人员选择事件
- bindUserCheckboxChange(e) {
- // 注意:e.detail.value返回的是字符串数组
- console.log('选中的用户ID字符串数组:', e.detail.value);
- const selectedUserIdsStr = e.detail.value;
- // 根据用户ID字符串找到对应的用户信息
- const selectedUsers = this.data.users.filter(user =>
- selectedUserIdsStr.includes(user.fExpandint1.toString())
- );
- console.log('选中的用户信息:', selectedUsers);
- const selectedUserIds = selectedUsers.map(user => user.fExpandint1);
- const selectedUserNames = selectedUsers.map(user => user.fRealname);
- console.log('选中的用户ID数组:', selectedUserIds);
- console.log('选中的用户姓名数组:', selectedUserNames);
- this.setData({
- selectedUserId: selectedUserIds,
- selectedUserNames: selectedUserNames
- });
- },
- // 确认批量签到/签退
- confirmBatchSign() {
- const that = this;
- const { batchSignType, selectedUserId, selectedUserNames, markers, posObj } = this.data;
-
- if (selectedUserId.length === 0) {
- wx.showToast({
- title: '请选择人员',
- icon: 'none',
- duration: 2000
- });
- return;
- }
-
- wx.showLoading({
- title: '处理中...',
- mask: true
- });
-
- const timeStamp = new Date().getTime();
- // 构造请求数据 - 根据selectedUserId的长度创建数组
- const data = [];
- const positionName = markers[0].name;
- const latitude = posObj.latitude;
- const longitude = posObj.longitude;
-
- // 遍历selectedUserId数组,为每个用户创建一个数据对象
- for (let i = 0; i < selectedUserId.length; i++) {
- data.push({
- fExpand1: positionName, // 当前位置名称
- fWorktime: timeStamp, // 当前时间戳
- fX: latitude, // 当前纬度
- fY: longitude, // 当前经度
- fExpandint1: selectedUserId[i], // 单个用户ID
- fRealname: selectedUserNames[i] // 单个用户姓名
- });
- }
-
- // 根据操作类型选择API接口
- const url = batchSignType === 0
- ? app.globalData.httpsUrlServer + '/tbaseemployeeworkrecords/batchSignIn'
- : app.globalData.httpsUrlServer + '/tbaseemployeeworkrecords/batchSignOut';
-
- // 调用API
- console.log(url, data)
- app.postReq(url, data, (res) => {
- wx.hideLoading();
- if (res.message === '请求成功') {
- wx.showToast({
- title: batchSignType === 0 ? '批量签到成功' : '批量签退成功',
- icon: 'success',
- duration: 2000
- });
- // 隐藏弹窗
- that.hideBatchModal();
- } else {
- wx.showToast({
- title: res.message || '操作失败',
- icon: 'none',
- duration: 2000
- });
- }
- }, (err) => {
- wx.hideLoading();
- wx.showToast({
- title: '网络错误',
- icon: 'none',
- duration: 2000
- });
- console.error('批量操作失败:', err);
- });
- },
- // 签到事件
- openSetting() {
- var that = this;
- if (!that.data.posObj.longitude || !that.data.posObj.longitude) {
- wx.openSetting({
- success(res) {
- ////console.log(res.authSetting)
- if (res.authSetting['scope.userLocation']) {
- that.getLocation();
- }
- },
- });
- } else {
- wx.showModal({
- title: '提示',
- content: '已经获取位置信息,是否签到',
- success(res) {
- if (res.confirm) {
- wx.showLoading({
- title: '打卡中...',
- mark: 'true',
- });
- var timeStamp = new Date().getTime();
- if (that.data.startOrenDFlag == 0) {
- var url =
- app.globalData.httpsUrlServer +
- '/tbaseemployeeworkrecords/signIn';
- } else if (that.data.startOrenDFlag == 1) {
- var url =
- app.globalData.httpsUrlServer +
- '/tbaseemployeeworkrecords/signOut';
- }
- var data = {
- fExpand1: that.data.markers[0].name, // 当前位置名称
- fWorktime: timeStamp, // 当前时间戳
- fX: that.data.posObj.latitude, // 当前坐标
- fY: that.data.posObj.longitude,
- };
- app.postReq(url, data, (res) => {
- if (res.message == '请求成功') {
- // wx.hideLoading();
- wx.showToast({
- title: '打卡成功!', // 标题
- icon: 'success', // 图标类型,默认success
- duration: 1500, // 提示窗停留时间,默认1500ms
- mark: 'true',
- });
- that.getSelectCurrentUserIsSgin();
- }
- });
- } else if (res.cancel) {
- ////console.log("取消打卡")
- }
- },
- });
- }
- },
- // 获取位置信息
- getLocation() {
- wx.showLoading({
- title: '加载中',
- mark: true,
- });
- var that = this;
- wx.getLocation({
- type: 'gcj02',
- success(res) {
- that.data.markers[0].latitude = res.latitude;
- that.data.markers[0].longitude = res.longitude;
- that.setData({
- markers: that.data.markers,
- posObj: {
- latitude: res.latitude,
- longitude: res.longitude,
- },
- });
- qqmapsdk.reverseGeocoder({
- location: {
- latitude: res.latitude,
- longitude: res.longitude,
- },
- success: function (res) {
- //获取当前地址成功
- that.data.markers[0].callout.content = res.result.address;
- that.data.markers[0].name = res.result.address;
- that.setData({
- markers: that.data.markers,
- });
- },
- fail: function (res) {
- ////console.log('获取当前地址失败');
- },
- });
- wx.hideLoading();
- },
- });
- },
- // 查询当前登录人员是否有上班打卡记录
- getSelectCurrentUserIsSgin() {
- wx.showLoading({
- title: '加载中',
- mark: true,
- });
- var that = this;
- var url =
- app.globalData.httpsUrlServer +
- '/tbaseemployeeworkrecords/selectCurrentUserIsSgin';
- app.getReq(url, (res) => {
- // 0 未打卡,1 已打上班卡 2 已打下班卡
- if (res.message == '请求成功') {
- that.setData({
- startOrenDFlag: res.data,
- });
- wx.hideLoading();
- }
- });
- },
- // 上下班时间
- hoursColock() {
- var myDate = new Date();
- this,
- setData({
- hoursColock: myDate.getHours(),
- });
- },
- // 当前时间
- getTime() {
- var myDate = new Date();
- myDate.getHours(); //获取当前小时数(0-23)
- myDate.getMinutes(); //获取当前分钟数(0-59)
- var hour1 = this.zhiPan(myDate.getHours());
- var hour2 = this.zhiPan(myDate.getMinutes());
- this.setData({
- clockHours: hour1,
- clockMinute: hour2,
- });
- },
- zhiPan(timezhi) {
- if (timezhi < 10) {
- return '0' + timezhi;
- } else {
- return timezhi;
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function () {
- var that = this;
- if (wx.getStorageSync('position')) {
- var show = wx.getStorageSync('position');
- if (show == '公园') {
- this.setData({
- showBtnFlag: true,
- });
- } else {
- this.setData({
- showBtnFlag: false,
- });
- }
- }
- //当前点数
- that.data.timer = setInterval(function () {
- that.getTime();
- if (that.data.flag) {
- that.setData({
- flag: false,
- });
- } else {
- that.setData({
- flag: true,
- });
- }
- }, 1000);
- //获取当前位置及位置名称
- that.getLocation();
- // 查询当前登录人员是否有上班打卡记录
- that.getSelectCurrentUserIsSgin();
- // 获取权限控制按钮节点
- this.getButtonNodes();
- wx.hideLoading();
- },
- // 获取权限控制按钮节点
- getButtonNodes() {
- // 获取缓存中的按钮节点数据
- const buttonNodes = wx.getStorageSync('buttonNodes') || [];
- // 筛选出与考勤相关的数据并提取fFunctioncode
- const attendanceButtons = buttonNodes
- .filter(node => node.parentFFunctioncode === 'attendanceManagement' && node.fFunctioncode)
- .map(node => node.fFunctioncode);
- this.setData({
- buttonNodes: attendanceButtons
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- // wx.removeStorageSync("calendarSignData")
- // wx.removeStorageSync("calendarSignDay")
- clearInterval(this.data.timer);
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {},
- });
|