servantsettings.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import request from '../../../util/http'
  2. import apiUrl from '../../../util/apiUrl1'
  3. import util from '../../../util/util'
  4. import moment from 'moment'
  5. var app = getApp();
  6. Page({
  7. data: {
  8. servantlist:[],
  9. },
  10. onLoad() {
  11. this.getservantlist("SN000002");
  12. },
  13. getservantlist(subjectType){
  14. request.httpServiceGet(apiUrl.servantappletservicePath,{subjectType:subjectType}).then(data=>{
  15. //console.log(data);
  16. this.setData({
  17. servantlist: data
  18. });
  19. });
  20. },
  21. dailytasksdeit(){
  22. let employRelationNo = app.globalData.employRelationNo;
  23. let servantselectedlist=[];
  24. for(let i=0;i<this.data.servantlist.length;i++){
  25. for(let j=0;j<this.data.servantlist[i].subjectList.length;j++){
  26. let answerstr='';
  27. for(let t=0;t<this.data.servantlist[i].subjectList[j].answer.length;t++){
  28. if(this.data.servantlist[i].subjectList[j].answer[t].isChoose){
  29. answerstr += this.data.servantlist[i].subjectList[j].answer[t].answer+',';
  30. }
  31. }
  32. //console.log(answerstr);
  33. servantselectedlist.push({answer: [answerstr],customAnswer: this.data.servantlist[i].subjectList[j].subject,subjectId: this.data.servantlist[i].subjectList[j].subjectId});
  34. }
  35. }
  36. //console.log(servantselectedlist);
  37. request.httpServicePost(apiUrl.insertNewservantappletservicePath,{employRelationNo:employRelationNo,subjectList:servantselectedlist,subjectType:"SN000002"}).then(data=>{
  38. my.alert({
  39. title: data,
  40. });
  41. });
  42. },
  43. answerselected(e){
  44. //console.log(e.target.dataset.id);
  45. //console.log(e.detail.value);
  46. let checkedlist=e.detail.value;
  47. let servantlist=this.data.servantlist;
  48. //先做清除
  49. for(let i=0;i<servantlist.length;i++){
  50. for(let j=0;j<servantlist[i].subjectList.length;j++){
  51. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  52. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  53. servantlist[i].subjectList[j].answer[t].isChoose=0;
  54. }
  55. }
  56. }
  57. }
  58. //添加选中
  59. for(let i=0;i<servantlist.length;i++){
  60. for(let j=0;j<servantlist[i].subjectList.length;j++){
  61. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  62. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  63. for(let u=0;u<checkedlist.length;u++){
  64. if(checkedlist[u]==servantlist[i].subjectList[j].answer[t].answer){
  65. servantlist[i].subjectList[j].answer[t].isChoose=1;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. this.setData({
  73. servantlist: servantlist
  74. })
  75. },
  76. customanswer(e){
  77. console.log(e.target.dataset.id);
  78. let servantlist=this.data.servantlist;
  79. for(let i=0;i<servantlist.length;i++){
  80. for(let j=0;j<servantlist[i].subjectList.length;j++){
  81. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  82. servantlist[i].subjectList[j].customAnswer = e.detail.value;
  83. break;
  84. }
  85. }
  86. }
  87. this.setData({
  88. servantlist: servantlist
  89. })
  90. },
  91. });