servantedit.js 5.1 KB

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