servantsettings.js 6.1 KB

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