editServant.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. this.initServantInfo();
  61. },
  62. onShow(){
  63. },
  64. initServantInfo(){
  65. let relationInfo=app.globalData.relationInfo;
  66. console.log(relationInfo);
  67. let workDayId=relationInfo.servantTaskPeriod.workDayId;
  68. this.setData({
  69. servantName:relationInfo.servantName,
  70. serviceModelType:relationInfo.servantType,
  71. workSelectedClassList:workDayId.split(',')
  72. });
  73. if(relationInfo.servantType=='2'){
  74. this.setData({
  75. serviceModelName:'钟点工',
  76. index:0
  77. });
  78. }else if(relationInfo.servantType=='3'){
  79. this.setData({
  80. serviceModelName:'住家保姆',
  81. index:1
  82. });
  83. }else if(relationInfo.servantType=='4'){
  84. this.setData( {
  85. serviceModelName:'白班保姆',
  86. index:2
  87. });
  88. }else if(relationInfo.servantType=='5'){
  89. this.setData({
  90. serviceModelName:'月嫂',
  91. index:3
  92. });
  93. }else{
  94. this.setData({
  95. serviceModelName:'钟点工',
  96. index:0
  97. });
  98. }
  99. // 选中的工作日
  100. let workDayList=[];
  101. if(workDayId.indexOf('0')!=-1){
  102. workDayList.push({workDayZh:'周日',
  103. index:'0',
  104. });
  105. }
  106. if(workDayId.indexOf('1')!=-1){
  107. workDayList.push({workDayZh:'周一',
  108. index:'1',
  109. });
  110. }
  111. if(workDayId.indexOf('2')!=-1){
  112. workDayList.push( {workDayZh:'周二',
  113. index:'2',
  114. });
  115. }
  116. if(workDayId.indexOf('3')!=-1){
  117. workDayList.push( {workDayZh:'周三',
  118. index:'3',
  119. });
  120. }
  121. if(workDayId.indexOf('4')!=-1){
  122. workDayList.push( {workDayZh:'周四',
  123. index:'4',
  124. });
  125. }
  126. if(workDayId.indexOf('5')!=-1){
  127. workDayList.push( {workDayZh:'周五',
  128. index:'5',
  129. });
  130. }
  131. if(workDayId.indexOf('6')!=-1){
  132. workDayList.push( {workDayZh:'周六',
  133. index:'6',
  134. });
  135. }
  136. this.setData({
  137. workSelectedList:workDayList
  138. })
  139. },
  140. bindServantInput(e){
  141. this.setData({
  142. servantName: e.detail.value,
  143. });
  144. },
  145. bindPickerChange(e) {
  146. console.log('picker发送选择改变,携带值为', e.detail.value);
  147. let index=e.detail.value;
  148. let type=((this.data.serviceModelList)[index]).type;
  149. let value=((this.data.serviceModelList)[index]).text;
  150. this.setData({
  151. serviceModelName: value,
  152. serviceModelType:type
  153. });
  154. },
  155. toggleWorkTime(e){
  156. let id=e.target.dataset.id;
  157. let zh=e.target.dataset.zh;
  158. let isNew=this.data.workSelectedList.every(item=>{return id!=item.index});
  159. if(isNew){
  160. let newArr=this.data.workSelectedList;
  161. let obj={
  162. index:id,
  163. workDayZh:zh
  164. }
  165. newArr.push(obj);
  166. let newArrClass=this.data.workSelectedClassList;
  167. newArrClass.push(id);
  168. this.setData({
  169. workSelectedList:newArr,
  170. workSelectedClassList:newArrClass
  171. })
  172. }else{
  173. let spliceIndex='';
  174. this.data.workSelectedList.forEach((item,index)=> {
  175. if(item.index==id){
  176. console.log(item,index);
  177. spliceIndex=index;
  178. return;
  179. }
  180. })
  181. let newArr=this.data.workSelectedList;
  182. let newArrClass=this.data.workSelectedClassList;
  183. newArr.splice(spliceIndex,1);
  184. newArrClass.splice(newArrClass.indexOf(id),1);
  185. this.setData({
  186. workSelectedList:newArr,
  187. workSelectedClassList:newArrClass
  188. })
  189. }
  190. },
  191. createServant(){
  192. if(this.data.servantName==''){
  193. my.alert({
  194. content:'请输入服务者姓名'
  195. });
  196. }else if(this.data.serviceModelName=='请选择'){
  197. my.alert({
  198. content:'请选择该服务者的工种'
  199. });
  200. }else if(this.data.workSelectedList.length==0){
  201. my.alert({
  202. content:'请选择该服务者的工作时间'
  203. });
  204. }else{
  205. // 创建服务者,提交后台
  206. this.submitServant();
  207. }
  208. },
  209. submitServant(){
  210. let params={
  211. "employRelationNo": app.globalData.relationInfo.employRelationNo,
  212. "servantName": this.data.servantName,
  213. "servantType": this.data.serviceModelType,
  214. "taskPeriods": this.data.workSelectedList,
  215. "userType": "1"
  216. }
  217. request.httpServicePost(apiUrl.updateEmployerRelationPath,params).then(data=>{
  218. console.log(data);
  219. // 编辑成功跳转到保姆工作站
  220. my.showToast({
  221. content: '编辑成功',
  222. });
  223. // app.globalData.employRelationNo=app.globalData.relationInfo.employRelationNo;
  224. // let emReNo=app.globalData.relationInfo.employRelationNo;
  225. // my.navigateTo({
  226. // url: '../customerCenter/customerCenter?emReNo='+emReNo
  227. // });
  228. my.navigateBack({
  229. delta: 1
  230. });
  231. }).catch(e=>{
  232. console.log(e);
  233. })
  234. }
  235. });