import request from '../../../util/http' import apiUrl from '../../../util/apiUrl' var app = getApp(); Page({ data: { listShow:false,//是否有多个客户 noCustomerList:false, unSetModal:false,//未设置服务者提醒 unSetBtn: [ { text: '现在关联', extClass: 'buttonBold' }, { text: '暂不' }, ], editModalShow:false,//编辑弹框 customerName:'',//编辑客户姓名输入 buttonFooter:[ { text: '取消' }, { text: '确定', extClass: 'buttonBold' }, ], bindModalShow:false,//关联雇主弹框 bindCode:'', bindName:'', customerList:[ ], emReNo:''//编辑信息的雇佣关系编号 }, onLoad() { // this.initCustomerList(); }, onShow(){ this.initCustomerList(); }, initCustomerList(){ let params={ "servantId":app.globalData.userInfo.id, "pageNo": 1, "pageSize": 100, } request.httpServicePost(apiUrl.findByServantIdListPath,params).then(data=>{ console.log(data); if(data.dataList.length==0){ this.setData({ listShow:false, noCustomerList:true, unSetModal:true, }); }else{ this.setData({ listShow:true, noCustomerList:false, unSetModal:false, customerList:data.dataList }); // my.alert({ // content:JSON.stringify(data.dataList) // }); } }).catch(e=>{ console.log(e); }) }, editCustomer(e){ console.log(e); this.setData({ editModalShow:true, // customerName:e.target.dataset.emName, emReNo:e.target.dataset.emReNo, }); }, onModalClose(e){ console.log(e.target); if(e.target.dataset.index==0){ this.setData({ editModalShow: false, }); }else{ // 保存客户姓名 this.editEmployerSubmit(); } }, // 编辑雇主提交 editEmployerSubmit(){ let params={ "employerName":this.data.customerName, "employRelationNo": this.data.emReNo, } request.httpServicePost(apiUrl.updateEmployerNamePath,params).then(data=>{ console.log(data); this.setData({ editModalShow: false, }); my.showToast({ content: '修改成功', }); // 修改成功后刷新页面 this.initCustomerList(); }).catch(e=>{ console.log(e); }) }, bindKeyInput(e) { this.setData({ customerName: e.detail.value, }); console.log(this.data.customerName); }, bindCodeInput(e) { this.setData({ bindCode: e.detail.value, }); console.log(this.data.bindCode); }, bindNameInput(e) { this.setData({ bindName: e.detail.value, }); }, // 添加新客户 bindNewCustomer(){ this.setData({ bindModalShow: true, bindCode:'', bindName:'' }); }, onBindModalClose(e){ console.log(e.target); if(e.target.dataset.index==0){ this.setData({ bindModalShow: false, }); }else{ // 关联雇主 if(this.data.bindCode==''){ my.alert({ content:'请输入关联码' }); }else if(this.data.bindName==''){ my.alert({ content:'请输入雇主称呼' }); }else{ this.bindNow(); } } }, // 进入工作台 enterServantCenter(e){ let emReNo=e.target.dataset.emReNo; my.navigateTo({ url: '../servantCenter/servantCenter?emReNo='+emReNo }); }, bindNow(){ let params={ "servantId":app.globalData.userInfo.id, "employerName":this.data.bindName, "employIdentifier": this.data.bindCode, } request.httpServicePost(apiUrl.relationEmployerPath,params).then(data=>{ console.log(data); this.setData({ bindModalShow: false, }); my.showToast({ content: '关联成功', }); // 关联成功后刷新页面 this.initCustomerList(); }).catch(e=>{ console.log(e); }) }, enterServantCenter(e){ let emReNo=e.target.dataset.emReNo; my.navigateTo({ url: '../servantCenter/servantCenter?emReNo='+emReNo }); }, // 点击设置按钮 onSetButtonClick(e){ console.log(e.target); if(e.target.dataset.index==0){ this.setData({ unSetModal: false, bindModalShow:true, bindCode:'', bindName:'' }); }else{ this.setData({ unSetModal: false }); } }, // 切换角色 switchRole(){ my.navigateTo({ url: '../../common/selectRole/selectRole' }); } });