123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- import request from '../../../util/http'
- import apiUrl from '../../../util/apiUrl1'
- import util from '../../../util/util'
- import moment from 'moment'
- var app = getApp();
- Page({
- data: {
- tips:true,
- servantlist:[],
- },
- onLoad() {
- this.getservantlist("SN000002");
- },
- ///加载绑定数据
- getservantlist(subjectType){
- request.httpServiceGet(apiUrl.servantappletservicePath,{subjectType:subjectType}).then(data=>{
- //console.log(data);
- let servantlist = data;
- var that = this;
- for(let i=0;i<servantlist.length;i++){
- //添加是否展示tab
- if(i==0){
- servantlist[i].show=true;
- }
- else{
- servantlist[i].show=false;
- }
- if(i==(servantlist.length-1)) {
- servantlist[i].button="完成";
- }else{
- servantlist[i].button="下一步";
- }
- servantlist[i].index=i+1;
- //给每个题目添加编号
- let t=1;
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- servantlist[i].subjectList[j].index=t;
- t++;
- }
- }
- this.setData({
- servantlist: servantlist
- });
- });
- },
- //提交数据
- dailytasksdeit(){
- let employRelationNo = app.globalData.employRelationNo;
- let servantselectedlist=[];
- for(let i=0;i<this.data.servantlist.length;i++){
- for(let j=0;j<this.data.servantlist[i].subjectList.length;j++){
- let answerstr='';
- for(let t=0;t<this.data.servantlist[i].subjectList[j].answer.length;t++){
- if(this.data.servantlist[i].subjectList[j].answer[t].isChoose){
- answerstr += this.data.servantlist[i].subjectList[j].answer[t].answer +',';
- }
- }
- //console.log(answerstr);
- if(answerstr.length>0||this.data.servantlist[i].subjectList[j].customAnswer.length>0){
- answerstr=answerstr.substring(0,answerstr.length - 1);
- servantselectedlist.push({answer: [answerstr],customAnswer: this.data.servantlist[i].subjectList[j].customAnswer,subjectId: this.data.servantlist[i].subjectList[j].subjectId});
- }
- }
- }
- //console.log(servantselectedlist);
- request.httpServicePost(apiUrl.insertNewservantappletservicePath,{employRelationNo:employRelationNo,subjectList:servantselectedlist,subjectType:"SN000002"}).then(data=>{
- my.alert({
- title: '提示',
- content: '设置完成',
- buttonText: '确定',
- success: () => {
- my.navigateBack();
- }
- } );
- });
- },
- //选择问题 多选
- answerselected(e){
- let checkedlist=e.detail.value;
- let servantlist=this.data.servantlist;
- //先做清除
- for(let i=0;i<servantlist.length;i++){
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
- servantlist[i].subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- }
- //添加选中
- for(let i=0;i<servantlist.length;i++){
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
- for(let u=0;u<checkedlist.length;u++){
- if(checkedlist[u]==servantlist[i].subjectList[j].answer[t].answer){
- servantlist[i].subjectList[j].answer[t].isChoose=1;
- }
- }
- }
- }
- }
- }
- this.setData({
- servantlist: servantlist
- })
- },
- //问题选择单选
- answerselectedSingle(e){
- let checkedlist=e.detail.value;
- let servantlist=this.data.servantlist;
- //先做清除
- for(let i=0;i<servantlist.length;i++){
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
- servantlist[i].subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- }
- //添加选中
- for(let i=0;i<servantlist.length;i++){
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servantlist[i].subjectList[j].answer.length;t++){
- for(let u=0;u<checkedlist.length;u++){
- if(checkedlist[u]==servantlist[i].subjectList[j].answer[t].answer){
- servantlist[i].subjectList[j].answer[t].isChoose=1;
- }
- else {
- servantlist[i].subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- }
- }
- }
- this.setData({
- servantlist: servantlist
- })
- },
- //自定义问题
- customanswer(e){
- console.log(e.target.dataset.id);
- let servantlist=this.data.servantlist;
- for(let i=0;i<servantlist.length;i++){
- for(let j=0;j<servantlist[i].subjectList.length;j++){
- if(servantlist[i].subjectList[j].subjectId==e.target.dataset.id){
- servantlist[i].subjectList[j].customAnswer = e.detail.value;
- break;
- }
- }
- }
- this.setData({
- servantlist: servantlist
- })
- },
- //切换tab
- loadclasslistadd(e){
- let nowsubtypeNo=e.target.dataset.id;
- let servantlist=this.data.servantlist;
- //1.先清除
- let t=0;
- for(let i=0;i<servantlist.length;i++){
- servantlist[i].show=false;
- if(servantlist[i].subtypeNo==nowsubtypeNo){
- t=i;
- }
- }
- servantlist[t+1].show=true;
- this.setData({
- servantlist: servantlist
- })
- },
-
- //切换tab
- loadclasslist(e){
- let nowsubtypeNo=e.target.dataset.id;
- let servantlist=this.data.servantlist;
- //1.先清除
- let t=0;
- for(let i=0;i<servantlist.length;i++){
- servantlist[i].show=false;
- if(servantlist[i].subtypeNo==nowsubtypeNo){
- t=i;
- }
- }
- servantlist[t-1].show=true;
- this.setData({
- servantlist: servantlist
- })
- },
- closeTip(){
- this.setData({
- tips: false
- })
- },
- toservantdetail(){
- my.navigateTo({
- url: '../servantdetail/servantdetail'
- });
- },
- });
|