createServant.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import request from '../../../util/http'
  2. import apiUrl from '../../../util/apiUrl'
  3. var app = getApp();
  4. Page({
  5. data: {
  6. servantName:'',
  7. index:0,
  8. serviceModelList: [
  9. // {
  10. // type:'1',
  11. // text:'小时工'
  12. // },
  13. {
  14. type:'2',
  15. text:'钟点工'
  16. },
  17. {
  18. type:'3',
  19. text:'住家保姆'
  20. },
  21. {
  22. type:'4',
  23. text:'白班保姆'
  24. },
  25. {
  26. type:'5',
  27. text:'月嫂'
  28. }
  29. ],
  30. serviceModelName:'请选择',
  31. serviceModelType:'',
  32. workSelectedList:[],
  33. workSelectedClassList:[],
  34. workInitList:[
  35. {workDayZh:'周一',
  36. index:'1',
  37. },
  38. {workDayZh:'周二',
  39. index:'2',
  40. },
  41. {workDayZh:'周三',
  42. index:'3',
  43. },
  44. {workDayZh:'周四',
  45. index:'4',
  46. },
  47. {workDayZh:'周五',
  48. index:'5',
  49. },
  50. {workDayZh:'周六',
  51. index:'6',
  52. },
  53. {workDayZh:'周日',
  54. index:'0',
  55. }
  56. ]
  57. },
  58. onLoad(options) {
  59. console.log(options);
  60. },
  61. bindServantInput(e){
  62. this.setData({
  63. servantName: e.detail.value,
  64. });
  65. console.log(this.data.servantName);
  66. },
  67. bindPickerChange(e) {
  68. console.log('picker发送选择改变,携带值为', e.detail.value);
  69. let index=e.detail.value;
  70. let type=((this.data.serviceModelList)[index]).type;
  71. let value=((this.data.serviceModelList)[index]).text;
  72. this.setData({
  73. serviceModelName: value,
  74. serviceModelType:type
  75. });
  76. },
  77. toggleWorkTime(e){
  78. let id=e.target.dataset.id;
  79. let zh=e.target.dataset.zh;
  80. let isNew=this.data.workSelectedList.every(item=>{return id!=item.index});
  81. if(isNew){
  82. let newArr=this.data.workSelectedList;
  83. let obj={
  84. index:id,
  85. workDayZh:zh
  86. }
  87. newArr.push(obj);
  88. let newArrClass=this.data.workSelectedClassList;
  89. newArrClass.push(id);
  90. this.setData({
  91. workSelectedList:newArr,
  92. workSelectedClassList:newArrClass
  93. })
  94. }else{
  95. let spliceIndex='';
  96. this.data.workSelectedList.forEach((item,index)=> {
  97. if(item.index==id){
  98. console.log(item,index);
  99. spliceIndex=index;
  100. return;
  101. }
  102. })
  103. let newArr=this.data.workSelectedList;
  104. let newArrClass=this.data.workSelectedClassList;
  105. newArr.splice(spliceIndex,1);
  106. newArrClass.splice(newArrClass.indexOf(id),1);
  107. this.setData({
  108. workSelectedList:newArr,
  109. workSelectedClassList:newArrClass
  110. })
  111. }
  112. },
  113. createServant(){
  114. if(this.data.servantName==''){
  115. my.alert({
  116. content:'请输入服务者姓名'
  117. });
  118. }else if(this.data.serviceModelName=='请选择'){
  119. my.alert({
  120. content:'请选择该服务者的工种'
  121. });
  122. }else if(this.data.workSelectedList.length==0){
  123. my.alert({
  124. content:'请选择该服务者的工作时间'
  125. });
  126. }else{
  127. // 创建服务者,提交后台
  128. this.submitServant();
  129. }
  130. },
  131. submitServant(){
  132. let params={
  133. "employerId": app.globalData.userInfo.id,
  134. "servantName": this.data.servantName,
  135. "servantType": this.data.serviceModelType,
  136. "taskPeriods": this.data.workSelectedList,
  137. "userType": "1"
  138. }
  139. request.httpServicePost(apiUrl.createServantRelationPath,params).then(data=>{
  140. console.log(data);
  141. // 创建成功跳转到保姆工作站
  142. app.globalData.employRelationNo=data.employRelationNo;
  143. let emReNo=data.employRelationNo;
  144. my.navigateTo({
  145. url: '../customerCenter/customerCenter?emReNo='+emReNo
  146. });
  147. }).catch(e=>{
  148. console.log(e);
  149. })
  150. }
  151. });