servantsettings.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. ///加载绑定数据
  14. getservantlist(subjectType){
  15. request.httpServiceGet(apiUrl.servantappletservicePath,{subjectType:subjectType}).then(data=>{
  16. //console.log(data);
  17. let servantlist = data;
  18. var that = this;
  19. for(let i=0;i<servantlist.length;i++){
  20. if(i==0){
  21. servantlist[i].show=true;
  22. }
  23. else{
  24. servantlist[i].show=false;
  25. }
  26. if(i==(servantlist.length-1)) {
  27. servantlist[i].button="完成";
  28. }else{
  29. servantlist[i].button="下一步";
  30. }
  31. servantlist[i].index=i+1;
  32. }
  33. this.setData({
  34. servantlist: servantlist
  35. });
  36. });
  37. },
  38. //提交数据
  39. dailytasksdeit(){
  40. let employRelationNo = app.globalData.employRelationNo;
  41. let servantselectedlist=[];
  42. for(let i=0;i<this.data.servantlist.length;i++){
  43. for(let j=0;j<this.data.servantlist[i].subjectList.length;j++){
  44. let answerstr='';
  45. for(let t=0;t<this.data.servantlist[i].subjectList[j].answer.length;t++){
  46. if(this.data.servantlist[i].subjectList[j].answer[t].isChoose){
  47. answerstr += this.data.servantlist[i].subjectList[j].answer[t].answer +',';
  48. }
  49. }
  50. //console.log(answerstr);
  51. if(answerstr.length>0||this.data.servantlist[i].subjectList[j].customAnswer.length>0){
  52. answerstr=answerstr.substring(0,answerstr.length - 1);
  53. servantselectedlist.push({answer: [answerstr],customAnswer: this.data.servantlist[i].subjectList[j].customAnswer,subjectId: this.data.servantlist[i].subjectList[j].subjectId});
  54. }
  55. }
  56. }
  57. //console.log(servantselectedlist);
  58. request.httpServicePost(apiUrl.insertNewservantappletservicePath,{employRelationNo:employRelationNo,subjectList:servantselectedlist,subjectType:"SN000002"}).then(data=>{
  59. my.alert({
  60. title: '提示',
  61. content: '设置完成',
  62. buttonText: '确定',
  63. success: () => {
  64. my.navigateBack();
  65. }
  66. } );
  67. });
  68. },
  69. //选择问题 多选
  70. answerselected(e){
  71. let checkedlist=e.detail.value;
  72. let servantlist=this.data.servantlist;
  73. //先做清除
  74. for(let i=0;i<servantlist.length;i++){
  75. for(let j=0;j<servantlist[i].subjectList.length;j++){
  76. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  77. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  78. servantlist[i].subjectList[j].answer[t].isChoose=0;
  79. }
  80. }
  81. }
  82. }
  83. //添加选中
  84. for(let i=0;i<servantlist.length;i++){
  85. for(let j=0;j<servantlist[i].subjectList.length;j++){
  86. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  87. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  88. for(let u=0;u<checkedlist.length;u++){
  89. if(checkedlist[u]==servantlist[i].subjectList[j].answer[t].answer){
  90. servantlist[i].subjectList[j].answer[t].isChoose=1;
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. this.setData({
  98. servantlist: servantlist
  99. })
  100. },
  101. //问题选择单选
  102. answerselectedSingle(e){
  103. let checkedlist=e.detail.value;
  104. let servantlist=this.data.servantlist;
  105. //先做清除
  106. for(let i=0;i<servantlist.length;i++){
  107. for(let j=0;j<servantlist[i].subjectList.length;j++){
  108. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  109. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  110. servantlist[i].subjectList[j].answer[t].isChoose=0;
  111. }
  112. }
  113. }
  114. }
  115. //添加选中
  116. for(let i=0;i<servantlist.length;i++){
  117. for(let j=0;j<servantlist[i].subjectList.length;j++){
  118. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  119. for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
  120. for(let u=0;u<checkedlist.length;u++){
  121. if(checkedlist[u]==servantlist[i].subjectList[j].answer[t].answer){
  122. servantlist[i].subjectList[j].answer[t].isChoose=1;
  123. }
  124. else {
  125. servantlist[i].subjectList[j].answer[t].isChoose=0;
  126. }
  127. }
  128. }
  129. }
  130. }
  131. }
  132. this.setData({
  133. servantlist: servantlist
  134. })
  135. },
  136. //自定义问题
  137. customanswer(e){
  138. console.log(e.target.dataset.id);
  139. let servantlist=this.data.servantlist;
  140. for(let i=0;i<servantlist.length;i++){
  141. for(let j=0;j<servantlist[i].subjectList.length;j++){
  142. if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
  143. servantlist[i].subjectList[j].customAnswer = e.detail.value;
  144. break;
  145. }
  146. }
  147. }
  148. this.setData({
  149. servantlist: servantlist
  150. })
  151. },
  152. //切换tab
  153. loadclasslistadd(e){
  154. let nowsubtypeNo=e.target.dataset.id;
  155. let servantlist=this.data.servantlist;
  156. //1.先清除
  157. let t=0;
  158. for(let i=0;i<servantlist.length;i++){
  159. servantlist[i].show=false;
  160. if(servantlist[i].subtypeNo==nowsubtypeNo){
  161. t=i;
  162. }
  163. }
  164. servantlist[t+1].show=true;
  165. this.setData({
  166. servantlist: servantlist
  167. })
  168. },
  169. //切换tab
  170. loadclasslist(e){
  171. let nowsubtypeNo=e.target.dataset.id;
  172. let servantlist=this.data.servantlist;
  173. //1.先清除
  174. let t=0;
  175. for(let i=0;i<servantlist.length;i++){
  176. servantlist[i].show=false;
  177. if(servantlist[i].subtypeNo==nowsubtypeNo){
  178. t=i;
  179. }
  180. }
  181. servantlist[t-1].show=true;
  182. this.setData({
  183. servantlist: servantlist
  184. })
  185. },
  186. });