servantedit.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. tips:true,
  9. servanteditlist:[],
  10. },
  11. onLoad(subtypeNo) {
  12. this.loadpage(subtypeNo);
  13. },
  14. loadpage(subtypeNo){
  15. let employRelationNo = app.globalData.employRelationNo;
  16. let params = {employRelationNo:employRelationNo}
  17. request.httpServiceGet(apiUrl.getEmployerSubjectWhenEdit, params).then(data => {
  18. if (data.length > 0) {
  19. //加载全部的类别
  20. let subjectList={};
  21. for(let i=0;i<data.length;i++){
  22. if(data[i].subtypeNo==subtypeNo.subtypeNo){
  23. subjectList=data[i];
  24. console.log(subjectList);
  25. }
  26. }
  27. this.setData({
  28. servanteditlist: subjectList
  29. });
  30. } else {
  31. this.setData({
  32. servanteditlist: []
  33. });
  34. }
  35. }).catch(e => {
  36. console.log(e);
  37. })
  38. },
  39. //提交数据
  40. dailytasksdeit(){
  41. let employRelationNo = app.globalData.employRelationNo;
  42. let servantselectedlist=[];
  43. for(let j=0;j<this.data.servanteditlist.subjectList.length;j++){
  44. let answerstr='';
  45. for(let t=0;t<this.data.servanteditlist.subjectList[j].answer.length;t++){
  46. if(this.data.servanteditlist.subjectList[j].answer[t].isChoose){
  47. answerstr += this.data.servanteditlist.subjectList[j].answer[t].answer +',';
  48. }
  49. }
  50. //console.log(answerstr);
  51. if(answerstr.length>0||this.data.servanteditlist.subjectList[j].customAnswer.length>0){
  52. answerstr=answerstr.substring(0,answerstr.length - 1);
  53. servantselectedlist.push({answer: [answerstr],customAnswer: this.data.servanteditlist.subjectList[j].customAnswer,subjectId: this.data.servanteditlist.subjectList[j].subjectId});
  54. }
  55. }
  56. //console.log(servantselectedlist);
  57. request.httpServicePost(apiUrl.updateEmployerLove,{employRelationNo:employRelationNo,subjectList:servantselectedlist,subjectType:"SN000002"}).then(data=>{
  58. my.alert({
  59. title: '提示',
  60. content: '设置完成',
  61. buttonText: '确定',
  62. success: () => {
  63. my.navigateBack();
  64. }
  65. } );
  66. });
  67. },
  68. //选择问题 多选
  69. answerselected(e){
  70. let checkedlist=e.detail.value;
  71. let servanteditlist=this.data.servanteditlist;
  72. //先做清除
  73. for(let j=0;j<servanteditlist.subjectList.length;j++){
  74. if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
  75. for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
  76. servanteditlist.subjectList[j].answer[t].isChoose=0;
  77. }
  78. }
  79. }
  80. //添加选中
  81. for(let j=0;j<servanteditlist.subjectList.length;j++){
  82. if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
  83. for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
  84. for(let u=0;u<checkedlist.length;u++){
  85. if(checkedlist[u]==servanteditlist.subjectList[j].answer[t].answer){
  86. servanteditlist.subjectList[j].answer[t].isChoose=1;
  87. }
  88. }
  89. }
  90. }
  91. }
  92. this.setData({
  93. servanteditlist: servanteditlist
  94. })
  95. },
  96. //问题选择单选
  97. answerselectedSingle(e){
  98. let checkedlist=e.detail.value;
  99. let servanteditlist=this.data.servanteditlist;
  100. //先做清除
  101. for(let j=0;j<servanteditlist.subjectList.length;j++){
  102. if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
  103. for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
  104. servanteditlist.subjectList[j].answer[t].isChoose=0;
  105. }
  106. }
  107. }
  108. //添加选中
  109. for(let j=0;j<servanteditlist.subjectList.length;j++){
  110. if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
  111. for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
  112. for(let u=0;u<checkedlist.length;u++){
  113. if(checkedlist[u]==servanteditlist.subjectList[j].answer[t].answer){
  114. servanteditlist.subjectList[j].answer[t].isChoose=1;
  115. }
  116. else {
  117. servanteditlist.subjectList[j].answer[t].isChoose=0;
  118. }
  119. }
  120. }
  121. }
  122. }
  123. this.setData({
  124. servanteditlist: servanteditlist
  125. })
  126. },
  127. //自定义问题
  128. customanswer(e){
  129. console.log(e.target.dataset.id);
  130. let servanteditlist=this.data.servanteditlist;
  131. for(let j=0;j<servanteditlist.subjectList.length;j++){
  132. if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
  133. servanteditlist.subjectList[j].customAnswer = e.detail.value;
  134. break;
  135. }
  136. }
  137. this.setData({
  138. servanteditlist: servanteditlist
  139. })
  140. },
  141. closeTip(){
  142. this.setData({
  143. tips: false
  144. })
  145. },
  146. toservantdetail(){
  147. my.navigateTo({
  148. url: '../servantdetail/servantdetail'
  149. });
  150. },
  151. });