dailytasks.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import request from '../../../util/http'
  2. import apiUrl from '../../../util/apiUrl'
  3. import apiUrl1 from '../../../util/apiUrl1'
  4. var app = getApp();
  5. Page({
  6. data: {
  7. allList: []
  8. },
  9. onLoad(options) {
  10. console.log(options);
  11. },
  12. onShow() {
  13. this.initDailyTaskList();
  14. },
  15. //数据加载
  16. initDailyTaskList() {
  17. let params = {
  18. }
  19. request.httpServiceGet(apiUrl.getDailyTaskList, params).then(data => {
  20. if (data.length > 0) {
  21. //添加选中的状态列
  22. let dailytasklist = data;
  23. var that = this;
  24. for(let i=0;i<dailytasklist.length;i++){
  25. for(let j=0;j<dailytasklist[i].TaskItems.length;j++){
  26. dailytasklist[i].TaskItems[j].checked=false;
  27. }
  28. }
  29. this.setData({
  30. allList: dailytasklist
  31. });
  32. } else {
  33. this.setData({
  34. allList: []
  35. });
  36. }
  37. }).catch(e => {
  38. console.log(e);
  39. })
  40. },
  41. //点击选中任务
  42. toggleWashinGandnursing(e) {
  43. let currentIndex= e.target.dataset.index;//类型ID
  44. let id = e.target.dataset.id;//选中当前ID
  45. let dailytasklist=this.data.allList;
  46. for(let i=0;i<dailytasklist.length;i++){
  47. if(dailytasklist[i].categoryId==currentIndex){
  48. for(let j=0;j<dailytasklist[i].TaskItems.length;j++){
  49. if(dailytasklist[i].TaskItems[j].id==id){
  50. if(dailytasklist[i].TaskItems[j].checked){
  51. dailytasklist[i].TaskItems[j].checked=false;
  52. }else{
  53. dailytasklist[i].TaskItems[j].checked=true;
  54. }
  55. }
  56. }
  57. }
  58. }
  59. this.setData({
  60. allList: dailytasklist
  61. });
  62. },
  63. //提交数据
  64. dailytasksdeit() {
  65. let employRelationNo = app.globalData.employRelationNo;
  66. let dailytasklist=[];
  67. for(let i=0;i<this.data.allList.length;i++){
  68. let itemIds='';
  69. for(let j=0;j<this.data.allList[i].TaskItems.length;j++){
  70. if(this.data.allList[i].TaskItems[j].checked){
  71. itemIds += '"'+this.data.allList[i].TaskItems[j].id+'"' +',';
  72. }
  73. }
  74. itemIds=itemIds.substring(0,itemIds.length - 1);
  75. dailytasklist.push({categoryId:this.data.allList[i].categoryId,itemIds:[itemIds]});
  76. }
  77. request.httpServicePost(apiUrl1.createDayTaskItem,{employRelationNo:employRelationNo,taskItems:dailytasklist}).then(data=>{
  78. my.alert({
  79. title: '提示',
  80. content: '保存完成',
  81. buttonText: '确定',
  82. success: () => {
  83. my.navigateBack();
  84. }
  85. } );
  86. });
  87. },
  88. });