123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- 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,
- servanteditlist:[],
- },
- onLoad(subtypeNo) {
- this.loadpage(subtypeNo);
- },
- loadpage(subtypeNo){
- let employRelationNo = app.globalData.employRelationNo;
- let params = {employRelationNo:employRelationNo}
- request.httpServiceGet(apiUrl.getSubjectWhenEdit, params).then(data => {
- if (data.length > 0) {
- //加载全部的类别
- let subjectList={};
- for(let i=0;i<data.length;i++){
- if(data[i].subtypeNo==subtypeNo.subtypeNo){
- subjectList=data[i];
- console.log(subjectList);
- }
- }
- this.setData({
- servanteditlist: subjectList
- });
- } else {
- this.setData({
- servanteditlist: []
- });
- }
- }).catch(e => {
- console.log(e);
- })
- },
- //提交数据
- dailytasksdeit(){
- let employRelationNo = app.globalData.employRelationNo;
- let servantselectedlist=[];
- for(let j=0;j<this.data.servanteditlist.subjectList.length;j++){
- let answerstr='';
- for(let t=0;t<this.data.servanteditlist.subjectList[j].answer.length;t++){
- if(this.data.servanteditlist.subjectList[j].answer[t].isChoose){
- answerstr += this.data.servanteditlist.subjectList[j].answer[t].answer +',';
- }
- }
- //console.log(answerstr);
- if(answerstr.length>0||this.data.servanteditlist.subjectList[j].customAnswer.length>0){
- answerstr=answerstr.substring(0,answerstr.length - 1);
- servantselectedlist.push({answer: [answerstr],customAnswer: this.data.servanteditlist.subjectList[j].customAnswer,subjectId: this.data.servanteditlist.subjectList[j].subjectId});
- }
- }
- //console.log(servantselectedlist);
- request.httpServicePost(apiUrl.updateServantLove,{employRelationNo:employRelationNo,subjectList:servantselectedlist,subjectType:"SN000002"}).then(data=>{
- my.alert({
- title: '提示',
- content: '设置完成',
- buttonText: '确定',
- success: () => {
- my.navigateBack();
- }
- } );
- });
- },
- //选择问题 多选
- answerselected(e){
- let checkedlist=e.detail.value;
- let servanteditlist=this.data.servanteditlist;
- //先做清除
- for(let j=0;j<servanteditlist.subjectList.length;j++){
- if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
- servanteditlist.subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- //添加选中
- for(let j=0;j<servanteditlist.subjectList.length;j++){
- if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
- for(let u=0;u<checkedlist.length;u++){
- if(checkedlist[u]==servanteditlist.subjectList[j].answer[t].answer){
- servanteditlist.subjectList[j].answer[t].isChoose=1;
- }
- }
- }
- }
- }
- this.setData({
- servanteditlist: servanteditlist
- })
- },
- //问题选择单选
- answerselectedSingle(e){
- let checkedlist=e.detail.value;
- let servanteditlist=this.data.servanteditlist;
- //先做清除
- for(let j=0;j<servanteditlist.subjectList.length;j++){
- if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
- servanteditlist.subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- //添加选中
- for(let j=0;j<servanteditlist.subjectList.length;j++){
- if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
- for(let t=0;t<servanteditlist.subjectList[j].answer.length;t++){
- for(let u=0;u<checkedlist.length;u++){
- if(checkedlist[u]==servanteditlist.subjectList[j].answer[t].answer){
- servanteditlist.subjectList[j].answer[t].isChoose=1;
- }
- else {
- servanteditlist.subjectList[j].answer[t].isChoose=0;
- }
- }
- }
- }
- }
- this.setData({
- servanteditlist: servanteditlist
- })
- },
- //自定义问题
- customanswer(e){
- console.log(e.target.dataset.id);
- let servanteditlist=this.data.servanteditlist;
- for(let j=0;j<servanteditlist.subjectList.length;j++){
- if(servanteditlist.subjectList[j].subjectId==e.target.dataset.id){
- servanteditlist.subjectList[j].customAnswer = e.detail.value;
- break;
- }
- }
- this.setData({
- servanteditlist: servanteditlist
- })
- },
- closeTip(){
- this.setData({
- tips: false
- })
- },
- toservantdetail(){
- my.navigateTo({
- url: '../servantdetail/servantdetail'
- });
- },
- });
|