123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- import request from '../../../util/http'
- import apiUrl from '../../../util/apiUrl'
- var app = getApp();
- Page({
- data: {
- servantName:'',
- index:0,
- serviceModelList: [
- // {
- // type:'1',
- // text:'小时工'
- // },
- {
- type:'2',
- text:'钟点工'
- },
- {
- type:'3',
- text:'住家保姆'
- },
- {
- type:'4',
- text:'白班保姆'
- },
- {
- type:'5',
- text:'月嫂'
- }
-
- ],
- serviceModelName:'请选择',
- serviceModelType:'',
- workSelectedList:[],
- workSelectedClassList:[],
- workInitList:[
- {workDayZh:'周一',
- index:'1',
- },
- {workDayZh:'周二',
- index:'2',
- },
- {workDayZh:'周三',
- index:'3',
- },
- {workDayZh:'周四',
- index:'4',
- },
- {workDayZh:'周五',
- index:'5',
- },
- {workDayZh:'周六',
- index:'6',
- },
- {workDayZh:'周日',
- index:'0',
- }
- ]
- },
- onLoad(options) {
- console.log(options);
- this.initServantInfo();
- },
- onShow(){
- },
- initServantInfo(){
- let relationInfo=app.globalData.relationInfo;
- console.log(relationInfo);
- let workDayId=relationInfo.servantTaskPeriod.workDayId;
- this.setData({
- servantName:relationInfo.servantName,
- serviceModelType:relationInfo.servantType,
- workSelectedClassList:workDayId.split(',')
- });
- if(relationInfo.servantType=='2'){
- this.setData({
- serviceModelName:'钟点工',
- index:0
- });
- }else if(relationInfo.servantType=='3'){
- this.setData({
- serviceModelName:'住家保姆',
- index:1
- });
- }else if(relationInfo.servantType=='4'){
- this.setData( {
- serviceModelName:'白班保姆',
- index:2
- });
- }else if(relationInfo.servantType=='5'){
- this.setData({
- serviceModelName:'月嫂',
- index:3
- });
- }else{
- this.setData({
- serviceModelName:'钟点工',
- index:0
- });
- }
- // 选中的工作日
- let workDayList=[];
- if(workDayId.indexOf('0')!=-1){
- workDayList.push({workDayZh:'周日',
- index:'0',
- });
- }
- if(workDayId.indexOf('1')!=-1){
- workDayList.push({workDayZh:'周一',
- index:'1',
- });
- }
- if(workDayId.indexOf('2')!=-1){
- workDayList.push( {workDayZh:'周二',
- index:'2',
- });
- }
- if(workDayId.indexOf('3')!=-1){
- workDayList.push( {workDayZh:'周三',
- index:'3',
- });
- }
- if(workDayId.indexOf('4')!=-1){
- workDayList.push( {workDayZh:'周四',
- index:'4',
- });
- }
- if(workDayId.indexOf('5')!=-1){
- workDayList.push( {workDayZh:'周五',
- index:'5',
- });
- }
- if(workDayId.indexOf('6')!=-1){
- workDayList.push( {workDayZh:'周六',
- index:'6',
- });
- }
-
- this.setData({
- workSelectedList:workDayList
- })
- },
- bindServantInput(e){
- this.setData({
- servantName: e.detail.value,
- });
-
- },
- bindPickerChange(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value);
- let index=e.detail.value;
- let type=((this.data.serviceModelList)[index]).type;
- let value=((this.data.serviceModelList)[index]).text;
- this.setData({
- serviceModelName: value,
- serviceModelType:type
- });
-
- },
- toggleWorkTime(e){
- let id=e.target.dataset.id;
- let zh=e.target.dataset.zh;
- let isNew=this.data.workSelectedList.every(item=>{return id!=item.index});
- if(isNew){
- let newArr=this.data.workSelectedList;
- let obj={
- index:id,
- workDayZh:zh
- }
- newArr.push(obj);
- let newArrClass=this.data.workSelectedClassList;
- newArrClass.push(id);
- this.setData({
- workSelectedList:newArr,
- workSelectedClassList:newArrClass
- })
- }else{
- let spliceIndex='';
- this.data.workSelectedList.forEach((item,index)=> {
- if(item.index==id){
- console.log(item,index);
- spliceIndex=index;
- return;
- }
- })
- let newArr=this.data.workSelectedList;
- let newArrClass=this.data.workSelectedClassList;
- newArr.splice(spliceIndex,1);
- newArrClass.splice(newArrClass.indexOf(id),1);
- this.setData({
- workSelectedList:newArr,
- workSelectedClassList:newArrClass
- })
- }
-
-
- },
- createServant(){
- if(this.data.servantName==''){
- my.alert({
- content:'请输入服务者姓名'
- });
- }else if(this.data.serviceModelName=='请选择'){
- my.alert({
- content:'请选择该服务者的工种'
- });
- }else if(this.data.workSelectedList.length==0){
- my.alert({
- content:'请选择该服务者的工作时间'
- });
- }else{
- // 创建服务者,提交后台
- this.submitServant();
- }
- },
- submitServant(){
- let params={
- "employRelationNo": app.globalData.relationInfo.employRelationNo,
- "servantName": this.data.servantName,
- "servantType": this.data.serviceModelType,
- "taskPeriods": this.data.workSelectedList,
- "userType": "1"
- }
- request.httpServicePost(apiUrl.updateEmployerRelationPath,params).then(data=>{
- console.log(data);
- // 编辑成功跳转到保姆工作站
- my.showToast({
- content: '编辑成功',
- });
- // app.globalData.employRelationNo=app.globalData.relationInfo.employRelationNo;
- // let emReNo=app.globalData.relationInfo.employRelationNo;
- // my.navigateTo({
- // url: '../customerCenter/customerCenter?emReNo='+emReNo
- // });
-
- my.navigateBack({
- delta: 1
- });
- }).catch(e=>{
- console.log(e);
-
- })
- }
- });
|