servantsettings.js 6.3 KB

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