Bez popisu

onDuty.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. var app = getApp();
  2. var calendarSignData;
  3. var date;
  4. var calendarSignDay;
  5. var is_qd;
  6. // 引入SDK核心类
  7. var QQMapWX = require('../../lib/qqmap-wx-jssdk.js');
  8. // 实例化API核心类
  9. var qqmapsdk = new QQMapWX({
  10. //秘钥key
  11. key: 'VIWBZ-I456G-D5JQP-ICQKE-SKMYS-44BMR',
  12. });
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. latitude: '',
  19. longitude: '',
  20. clockHours: '',
  21. clockMinute: '',
  22. flag: false,
  23. timer: null,
  24. hoursColock: '',
  25. // 当前位置坐标坐标
  26. posObj: {
  27. latitude: null,
  28. longitude: null,
  29. },
  30. markers: [
  31. {
  32. iconPath: './../../../images/weatherImg/qiandao.png',
  33. id: 1,
  34. name: '打卡地点',
  35. latitude: null,
  36. longitude: null,
  37. width: 30,
  38. height: 30,
  39. callout: {
  40. content: '打卡地点',
  41. color: '#ffffff',
  42. fontSize: 13,
  43. borderRadius: 20,
  44. bgColor: '#009ad6',
  45. textAlign: 'center',
  46. padding: 8,
  47. display: 'ALWAYS',
  48. },
  49. },
  50. ],
  51. // 判断是上班打卡还是下班打卡(true为上班打卡,false为下班打卡)
  52. startOrenDFlag: 0,
  53. showBtnFlag: true, // 判断是否是中心人员(是否需要打卡)
  54. // 批量操作相关
  55. showBatchModal: false, // 是否显示批量操作弹窗
  56. batchSignType: 0, // 批量操作类型:0-签到,1-签退
  57. batchModalTitle: '', // 弹窗标题
  58. batchModalButtonText: '', // 弹窗按钮文本
  59. // 部门和人员选择
  60. departments: [], // 部门列表
  61. departmentNames: [], // 部门名称列表
  62. selectedDepartmentIndex: '', // 选中的部门索引
  63. selectedDepartmentId: '', // 选中的部门ID
  64. users: [], // 人员列表
  65. userList: [], // 人员名称列表
  66. selectedUserId: [], // 选中的人员ID数组
  67. selectedUserNames: [], // 选中的人员姓名数组
  68. // 权限控制
  69. buttonNodes: [], // 按钮权限节点
  70. },
  71. //页面跳转
  72. nav(e) {
  73. ////console.log("路径", e.currentTarget.dataset.url)
  74. var url = e.currentTarget.dataset.url;
  75. wx.navigateTo({
  76. url: url,
  77. });
  78. },
  79. // 显示批量操作弹窗
  80. showBatchModal(e) {
  81. this.setData({
  82. showBatchModal: true,
  83. batchSignType: 0, // 默认批量上班签到
  84. batchModalTitle: '批量上班签到',
  85. batchModalButtonText: '签到',
  86. selectedDepartmentIndex: '',
  87. selectedDepartmentId: '',
  88. selectedUserId: [],
  89. selectedUserNames: [],
  90. users: [],
  91. userList: []
  92. });
  93. // 获取部门列表
  94. this.getDepartments();
  95. },
  96. // 批量签到类型选择事件
  97. bindBatchTypeChange(e) {
  98. const type = parseInt(e.detail.value); // 将字符串转换为数字
  99. this.setData({
  100. batchSignType: type,
  101. batchModalTitle: type === 0 ? '批量上班签到' : '批量下班签到',
  102. batchModalButtonText: type === 0 ? '签到' : '签退'
  103. });
  104. },
  105. // 隐藏批量操作弹窗
  106. hideBatchModal() {
  107. this.setData({
  108. showBatchModal: false
  109. });
  110. },
  111. // 获取部门列表
  112. getDepartments() {
  113. var that = this;
  114. var token = wx.getStorageSync('token');
  115. wx.showLoading({
  116. title: '加载部门中...',
  117. mask: true
  118. });
  119. wx.request({
  120. url: app.globalData.httpsUrlServer + '/sysdepartment/selectDepartmentByPageListpara?stateid=2',
  121. method: 'post',
  122. data: {data: {
  123. current: 1,
  124. fDeptname: "",
  125. size: 1000
  126. }},
  127. dataType: 'json',
  128. header: {
  129. 'Content-Type': 'application/json;charset=UTF-8',
  130. token: token,
  131. fSource: 1,
  132. },
  133. success: function (res) {
  134. wx.hideLoading();
  135. if (res.statusCode == 200 && res.data.status == 200) {
  136. console.log('部门列表:', res.data.data.data);
  137. var departments = res.data.data.data || [];
  138. // 注意:work_order_info中的字段名是fDeptname和fDeptid,需要检查实际API返回的字段名
  139. var formattedDepartments = departments.map(dept => ({
  140. fDepartmentid: dept.fDeptid || dept.fDepartmentid,
  141. fDepartmentname: dept.fDeptname || dept.fDepartmentname
  142. }));
  143. var departmentNames = formattedDepartments.map(dept => dept.fDepartmentname);
  144. that.setData({
  145. departments: formattedDepartments,
  146. departmentNames: departmentNames
  147. });
  148. }
  149. },
  150. fail: function (err) {
  151. wx.hideLoading();
  152. console.error('获取部门列表失败:', err);
  153. wx.showToast({
  154. title: '获取部门失败',
  155. icon: 'none'
  156. });
  157. }
  158. });
  159. },
  160. // 获取人员列表
  161. getUsers(departmentId) {
  162. if (!departmentId) return;
  163. var that = this;
  164. var token = wx.getStorageSync('token');
  165. wx.showLoading({
  166. title: '加载人员中...',
  167. mask: true
  168. });
  169. wx.request({
  170. url: app.globalData.httpsUrlServer + '/sysuseraccount/selectUserAccountAppByPageList',
  171. method: 'post',
  172. data: {data: {
  173. current: 1,
  174. size: 9999,
  175. fDeptid: departmentId
  176. }},
  177. dataType: 'json',
  178. header: {
  179. 'Content-Type': 'application/json;charset=UTF-8',
  180. token: token,
  181. fSource: 1,
  182. },
  183. success: function (res) {
  184. wx.hideLoading();
  185. if (res.statusCode == 200 && res.data.status == 200) {
  186. var users = res.data.data.data || [];
  187. console.log('人员列表:', users);
  188. // 注意:需要检查实际API返回的字段名是否与预期一致
  189. var formattedUsers = users.map(user => ({
  190. fExpandint1: user.fUserid || user.fExpandint1,
  191. fRealname: user.fUsername || user.fRealname,
  192. fDepartmentid: user.fDeptid || user.fDepartmentid
  193. }));
  194. console.log('格式化后的人员列表:', formattedUsers);
  195. that.setData({
  196. users: formattedUsers,
  197. userList: formattedUsers
  198. });
  199. }
  200. },
  201. fail: function (err) {
  202. wx.hideLoading();
  203. console.error('获取人员列表失败:', err);
  204. wx.showToast({
  205. title: '获取人员失败',
  206. icon: 'none'
  207. });
  208. }
  209. });
  210. },
  211. // 部门选择事件
  212. bindDepartmentChange(e) {
  213. const index = e.detail.value;
  214. const departmentId = this.data.departments[index].fDepartmentid;
  215. this.setData({
  216. selectedDepartmentIndex: index,
  217. selectedDepartmentId: departmentId,
  218. // 重置人员选择
  219. selectedUserId: [],
  220. selectedUserNames: []
  221. });
  222. // 获取该部门下的人员列表
  223. this.getUsers(departmentId);
  224. },
  225. // 人员选择事件
  226. bindUserCheckboxChange(e) {
  227. // 注意:e.detail.value返回的是字符串数组
  228. console.log('选中的用户ID字符串数组:', e.detail.value);
  229. const selectedUserIdsStr = e.detail.value;
  230. // 根据用户ID字符串找到对应的用户信息
  231. const selectedUsers = this.data.users.filter(user =>
  232. selectedUserIdsStr.includes(user.fExpandint1.toString())
  233. );
  234. console.log('选中的用户信息:', selectedUsers);
  235. const selectedUserIds = selectedUsers.map(user => user.fExpandint1);
  236. const selectedUserNames = selectedUsers.map(user => user.fRealname);
  237. console.log('选中的用户ID数组:', selectedUserIds);
  238. console.log('选中的用户姓名数组:', selectedUserNames);
  239. this.setData({
  240. selectedUserId: selectedUserIds,
  241. selectedUserNames: selectedUserNames
  242. });
  243. },
  244. // 确认批量签到/签退
  245. confirmBatchSign() {
  246. const that = this;
  247. const { batchSignType, selectedUserId, selectedUserNames, markers, posObj } = this.data;
  248. if (selectedUserId.length === 0) {
  249. wx.showToast({
  250. title: '请选择人员',
  251. icon: 'none',
  252. duration: 2000
  253. });
  254. return;
  255. }
  256. wx.showLoading({
  257. title: '处理中...',
  258. mask: true
  259. });
  260. const timeStamp = new Date().getTime();
  261. // 构造请求数据 - 根据selectedUserId的长度创建数组
  262. const data = [];
  263. const positionName = markers[0].name;
  264. const latitude = posObj.latitude;
  265. const longitude = posObj.longitude;
  266. // 遍历selectedUserId数组,为每个用户创建一个数据对象
  267. for (let i = 0; i < selectedUserId.length; i++) {
  268. data.push({
  269. fExpand1: positionName, // 当前位置名称
  270. fWorktime: timeStamp, // 当前时间戳
  271. fX: latitude, // 当前纬度
  272. fY: longitude, // 当前经度
  273. fExpandint1: selectedUserId[i], // 单个用户ID
  274. fRealname: selectedUserNames[i] // 单个用户姓名
  275. });
  276. }
  277. // 根据操作类型选择API接口
  278. const url = batchSignType === 0
  279. ? app.globalData.httpsUrlServer + '/tbaseemployeeworkrecords/batchSignIn'
  280. : app.globalData.httpsUrlServer + '/tbaseemployeeworkrecords/batchSignOut';
  281. // 调用API
  282. console.log(url, data)
  283. app.postReq(url, data, (res) => {
  284. wx.hideLoading();
  285. if (res.message === '请求成功') {
  286. wx.showToast({
  287. title: batchSignType === 0 ? '批量签到成功' : '批量签退成功',
  288. icon: 'success',
  289. duration: 2000
  290. });
  291. // 隐藏弹窗
  292. that.hideBatchModal();
  293. } else {
  294. wx.showToast({
  295. title: res.message || '操作失败',
  296. icon: 'none',
  297. duration: 2000
  298. });
  299. }
  300. }, (err) => {
  301. wx.hideLoading();
  302. wx.showToast({
  303. title: '网络错误',
  304. icon: 'none',
  305. duration: 2000
  306. });
  307. console.error('批量操作失败:', err);
  308. });
  309. },
  310. // 签到事件
  311. openSetting() {
  312. var that = this;
  313. if (!that.data.posObj.longitude || !that.data.posObj.longitude) {
  314. wx.openSetting({
  315. success(res) {
  316. ////console.log(res.authSetting)
  317. if (res.authSetting['scope.userLocation']) {
  318. that.getLocation();
  319. }
  320. },
  321. });
  322. } else {
  323. wx.showModal({
  324. title: '提示',
  325. content: '已经获取位置信息,是否签到',
  326. success(res) {
  327. if (res.confirm) {
  328. wx.showLoading({
  329. title: '打卡中...',
  330. mark: 'true',
  331. });
  332. var timeStamp = new Date().getTime();
  333. if (that.data.startOrenDFlag == 0) {
  334. var url =
  335. app.globalData.httpsUrlServer +
  336. '/tbaseemployeeworkrecords/signIn';
  337. } else if (that.data.startOrenDFlag == 1) {
  338. var url =
  339. app.globalData.httpsUrlServer +
  340. '/tbaseemployeeworkrecords/signOut';
  341. }
  342. var data = {
  343. fExpand1: that.data.markers[0].name, // 当前位置名称
  344. fWorktime: timeStamp, // 当前时间戳
  345. fX: that.data.posObj.latitude, // 当前坐标
  346. fY: that.data.posObj.longitude,
  347. };
  348. app.postReq(url, data, (res) => {
  349. if (res.message == '请求成功') {
  350. // wx.hideLoading();
  351. wx.showToast({
  352. title: '打卡成功!', // 标题
  353. icon: 'success', // 图标类型,默认success
  354. duration: 1500, // 提示窗停留时间,默认1500ms
  355. mark: 'true',
  356. });
  357. that.getSelectCurrentUserIsSgin();
  358. }
  359. });
  360. } else if (res.cancel) {
  361. ////console.log("取消打卡")
  362. }
  363. },
  364. });
  365. }
  366. },
  367. // 获取位置信息
  368. getLocation() {
  369. wx.showLoading({
  370. title: '加载中',
  371. mark: true,
  372. });
  373. var that = this;
  374. wx.getLocation({
  375. type: 'gcj02',
  376. success(res) {
  377. that.data.markers[0].latitude = res.latitude;
  378. that.data.markers[0].longitude = res.longitude;
  379. that.setData({
  380. markers: that.data.markers,
  381. posObj: {
  382. latitude: res.latitude,
  383. longitude: res.longitude,
  384. },
  385. });
  386. qqmapsdk.reverseGeocoder({
  387. location: {
  388. latitude: res.latitude,
  389. longitude: res.longitude,
  390. },
  391. success: function (res) {
  392. //获取当前地址成功
  393. that.data.markers[0].callout.content = res.result.address;
  394. that.data.markers[0].name = res.result.address;
  395. that.setData({
  396. markers: that.data.markers,
  397. });
  398. },
  399. fail: function (res) {
  400. ////console.log('获取当前地址失败');
  401. },
  402. });
  403. wx.hideLoading();
  404. },
  405. });
  406. },
  407. // 查询当前登录人员是否有上班打卡记录
  408. getSelectCurrentUserIsSgin() {
  409. wx.showLoading({
  410. title: '加载中',
  411. mark: true,
  412. });
  413. var that = this;
  414. var url =
  415. app.globalData.httpsUrlServer +
  416. '/tbaseemployeeworkrecords/selectCurrentUserIsSgin';
  417. app.getReq(url, (res) => {
  418. // 0 未打卡,1 已打上班卡 2 已打下班卡
  419. if (res.message == '请求成功') {
  420. that.setData({
  421. startOrenDFlag: res.data,
  422. });
  423. wx.hideLoading();
  424. }
  425. });
  426. },
  427. // 上下班时间
  428. hoursColock() {
  429. var myDate = new Date();
  430. this,
  431. setData({
  432. hoursColock: myDate.getHours(),
  433. });
  434. },
  435. // 当前时间
  436. getTime() {
  437. var myDate = new Date();
  438. myDate.getHours(); //获取当前小时数(0-23)
  439. myDate.getMinutes(); //获取当前分钟数(0-59)
  440. var hour1 = this.zhiPan(myDate.getHours());
  441. var hour2 = this.zhiPan(myDate.getMinutes());
  442. this.setData({
  443. clockHours: hour1,
  444. clockMinute: hour2,
  445. });
  446. },
  447. zhiPan(timezhi) {
  448. if (timezhi < 10) {
  449. return '0' + timezhi;
  450. } else {
  451. return timezhi;
  452. }
  453. },
  454. /**
  455. * 生命周期函数--监听页面加载
  456. */
  457. onLoad: function () {
  458. var that = this;
  459. if (wx.getStorageSync('position')) {
  460. var show = wx.getStorageSync('position');
  461. if (show == '公园') {
  462. this.setData({
  463. showBtnFlag: true,
  464. });
  465. } else {
  466. this.setData({
  467. showBtnFlag: false,
  468. });
  469. }
  470. }
  471. //当前点数
  472. that.data.timer = setInterval(function () {
  473. that.getTime();
  474. if (that.data.flag) {
  475. that.setData({
  476. flag: false,
  477. });
  478. } else {
  479. that.setData({
  480. flag: true,
  481. });
  482. }
  483. }, 1000);
  484. //获取当前位置及位置名称
  485. that.getLocation();
  486. // 查询当前登录人员是否有上班打卡记录
  487. that.getSelectCurrentUserIsSgin();
  488. // 获取权限控制按钮节点
  489. this.getButtonNodes();
  490. wx.hideLoading();
  491. },
  492. // 获取权限控制按钮节点
  493. getButtonNodes() {
  494. // 获取缓存中的按钮节点数据
  495. const buttonNodes = wx.getStorageSync('buttonNodes') || [];
  496. // 筛选出与考勤相关的数据并提取fFunctioncode
  497. const attendanceButtons = buttonNodes
  498. .filter(node => node.parentFFunctioncode === 'attendanceManagement' && node.fFunctioncode)
  499. .map(node => node.fFunctioncode);
  500. this.setData({
  501. buttonNodes: attendanceButtons
  502. });
  503. },
  504. /**
  505. * 生命周期函数--监听页面初次渲染完成
  506. */
  507. onReady: function () {},
  508. /**
  509. * 生命周期函数--监听页面显示
  510. */
  511. onShow: function () {},
  512. /**
  513. * 生命周期函数--监听页面隐藏
  514. */
  515. onHide: function () {},
  516. /**
  517. * 生命周期函数--监听页面卸载
  518. */
  519. onUnload: function () {
  520. // wx.removeStorageSync("calendarSignData")
  521. // wx.removeStorageSync("calendarSignDay")
  522. clearInterval(this.data.timer);
  523. },
  524. /**
  525. * 页面相关事件处理函数--监听用户下拉动作
  526. */
  527. onPullDownRefresh: function () {},
  528. /**
  529. * 页面上拉触底事件的处理函数
  530. */
  531. onReachBottom: function () {},
  532. /**
  533. * 用户点击右上角分享
  534. */
  535. onShareAppMessage: function () {},
  536. });