taskreminder.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. var util = require('../../../util/util.js')
  2. import request from '../../../util/http'
  3. import apiUrl1 from '../../../util/apiUrl1'
  4. import apiUrl from '../../../util/apiUrl'
  5. var app = getApp();
  6. Page({
  7. data: {
  8. showchangetime: false,
  9. nowselectTime: util.formatDate(new Date()),
  10. datelist: [{ title: "周日", date: 0, cssName: '', id: 1, day: 0 },{ title: "周一", date: 0, cssName: '', id: 2, day: 0 }, { title: "周二", date: 0, cssName: '', id: 3, day: 0 }, { title: "周三", date: 0, cssName: '', id: 4, day: 0 }, { title: "周四", date: 0, cssName: '', id: 5, day: 0 }, { title: "周五", date: 0, cssName: '', id: 6, day: 0 }, { title: "周六", date: 0, cssName: '', id: 7, day: 0 }],
  11. isreminds: true,
  12. showcancelbox: false,
  13. cancellist: [{ value: '1', label: '任务太多', checked: true }, { value: '2', label: '我不会', checked: false }, { value: '3', label: '任务不详细', checked: false }],
  14. taskList: [],
  15. servantName: '',//保姆姓名
  16. weekday: '',//日前
  17. servantTypeValue: '',//保姆工种,
  18. cost: "",
  19. taskId: "",
  20. incompleteReason: 1,
  21. buttonsText: [
  22. { text: '取消' },
  23. { text: '确认选择', extClass: 'buttonBold' },
  24. ],
  25. },
  26. onLoad() {
  27. //加载选中的时间
  28. let that=this;
  29. that.getWeekStartDate(this.data.nowselectTime);
  30. that.setnowweek();
  31. this.selectDayTaskItem();
  32. //this.selectDayTaskCost();
  33. this.homelist();//计算家庭数量
  34. },
  35. setnowweek(){
  36. let data = this.data.datelist;
  37. for(let i=0;i<7;i++){
  38. if(this.data.weekdateday[i]==this.data.nowDay){
  39. data[i].date=this.data.weekdate[i];
  40. data[i].day=this.data.weekdateday[i];
  41. data[i].cssName='tik-week-item-select'
  42. }
  43. else{
  44. data[i].date=this.data.weekdate[i];
  45. data[i].day=this.data.weekdateday[i];
  46. data[i].cssName=''
  47. }
  48. }
  49. this.setData({
  50. datelist: data,
  51. servantName: app.globalData.servantInfo.employerName,
  52. weekday: app.globalData.servantInfo.servantTaskPeriod.workDay,
  53. servantTypeValue: app.globalData.servantInfo.servantType
  54. });
  55. },
  56. showcancel(e) {
  57. this.setData({
  58. showcancelbox: true,
  59. taskId: e.target.dataset.id
  60. });
  61. console.log(this.data.taskId);
  62. },
  63. showyes(e) {
  64. console.log(e.target.dataset.id);
  65. let id = e.target.dataset.id;
  66. request.httpServicePost(apiUrl1.servantTaskSubmitPath, { id: id, state: 1 }).then(data => {
  67. my.alert({
  68. title: '提示',
  69. content: '提交完成',
  70. buttonText: '确定',
  71. success: () => {
  72. this.selectDayTaskItem();
  73. }
  74. });
  75. });
  76. },
  77. dateAdd: function (startDate, days) {
  78. startDate = new Date(startDate);
  79. startDate = +startDate + days * 1000 * 60 * 60 * 24;
  80. startDate = new Date(startDate);
  81. //var nextStartDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1) + "-" + startDate.getDate();
  82. return startDate.getDate();
  83. },
  84. datedayAdd: function (startDate, days) {
  85. startDate = new Date(startDate);
  86. startDate = +startDate + days * 1000 * 60 * 60 * 24;
  87. startDate = new Date(startDate);
  88. var nextStartDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1) + "-" + startDate.getDate();
  89. return nextStartDate;
  90. },
  91. //获取本周的开始日期
  92. getWeekStartDate(nowday) {
  93. let that = this;
  94. this.now = new Date(nowday);
  95. this.nowYear = this.now.getFullYear(); //当前年
  96. this.nowMonth = this.now.getMonth(); //当前月
  97. this.nowDay = this.now.getDate(); //当前日
  98. this.setData({
  99. nowDay: this.nowDay
  100. });//保存当前日
  101. this.nowDayOfWeek = this.now.getDay(); //今天是本周的第几天
  102. let dateStart = util.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek));
  103. let weekdateday = [this.dateAdd(dateStart, 0), this.dateAdd(dateStart, 1), this.dateAdd(dateStart, 2), this.dateAdd(dateStart, 3), this.dateAdd(dateStart, 4), this.dateAdd(dateStart, 5), this.dateAdd(dateStart, 6)];
  104. let weekdate = [this.datedayAdd(dateStart, 0), this.datedayAdd(dateStart, 1), this.datedayAdd(dateStart, 2), this.datedayAdd(dateStart, 3), this.datedayAdd(dateStart, 4), this.datedayAdd(dateStart, 5), this.datedayAdd(dateStart, 6)];
  105. this.setData({
  106. weekdate: weekdate,
  107. weekdateday: weekdateday
  108. })
  109. },
  110. changeWeekTime(e) {
  111. //切换选中的样式
  112. let weeklist=this.data.datelist;
  113. let selectedtabid=e.target.dataset.id;
  114. for(let i=0;i<weeklist.length;i++){
  115. if(weeklist[i].id==selectedtabid){
  116. weeklist[i].cssName="tik-week-item-select";
  117. }else{
  118. weeklist[i].cssName="";
  119. }
  120. }
  121. //设置当前选中的时间
  122. this.setData({
  123. nowselectTime:e.target.dataset.value,
  124. datelist:weeklist
  125. });
  126. this.selectDayTaskItem();
  127. //this.selectDayTaskCost();
  128. },
  129. showtime(){
  130. this.setData({
  131. showchangetime: true,
  132. });
  133. },
  134. //日历选中
  135. handleSelect(e) {
  136. this.setData({
  137. nowselectTime:util.formatDate(e[0]),
  138. showchangetime:false,
  139. nowDay:new Date(util.formatDate(e[0])).getDay()
  140. });
  141. this.getWeekStartDate(util.formatDate(e[0]));
  142. this.setnowweek();
  143. this.selectDayTaskItem();
  144. //this.selectDayTaskCost();
  145. },
  146. // 查询保姆每日任务
  147. selectDayTaskItem() {
  148. let params = {
  149. "employRelationNo": app.globalData.employRelationNo,
  150. "date": this.data.nowselectTime
  151. }
  152. request.httpServiceGet(apiUrl1.selectDayTaskItemPath, params).then(data => {
  153. // 未设置任务
  154. if (data.servantTasks.length == 0) {
  155. this.setData({
  156. isreminds: false,
  157. workDay: true,
  158. isremindscose:false
  159. });
  160. } else {
  161. //判断是否是休息日
  162. if(data.workDay){
  163. // 今天有任务
  164. this.setData({
  165. taskList: data,
  166. isreminds: true,
  167. workDay: true,
  168. isremindscose:true
  169. });
  170. }else{ //今天休息
  171. this.setData({
  172. workDay: false,
  173. isremindscose:false
  174. });
  175. }
  176. }
  177. }
  178. ).catch(e => {
  179. console.log(e);
  180. })
  181. },
  182. //今日花销合计
  183. bindKeyInput(e) {
  184. let costval=e.detail.value;
  185. if ((/^[0-9]*$/.test(e.detail.value))) {
  186. this.setData({
  187. cost: costval,
  188. costvalue:costval
  189. });
  190. }else{
  191. this.setData({
  192. cost: costval,
  193. costvalue:null
  194. });
  195. }
  196. },
  197. //提交保姆今日花销
  198. createServant() {
  199. let employRelationNo = app.globalData.employRelationNo;
  200. let date = this.data.nowselectTime;
  201. let cost = this.data.cost;
  202. request.httpServicePost(apiUrl1.insertDailyCostPath, { employRelationNo: employRelationNo, spendDate: date, cost: cost }).then(data => {
  203. my.alert({
  204. title: '提示',
  205. content: '提交完成',
  206. buttonText: '确定',
  207. success: () => {
  208. my.navigateBack();
  209. }
  210. });
  211. });
  212. },
  213. swiperChange(e) {
  214. console.log(e.detail.value);
  215. this.setData({
  216. incompleteReason: e.detail.value,
  217. });
  218. },
  219. switchList(){
  220. my.navigateTo({
  221. url: '../myCustomerList/myCustomerList'
  222. });
  223. },
  224. //计算家庭数量
  225. homelist(){
  226. let params={
  227. "servantId":app.globalData.userInfo.id,
  228. "pageNo": 1,
  229. "pageSize": 100,
  230. }
  231. request.httpServicePost(apiUrl.findByServantIdListPath,params).then(data=>{
  232. console.log('多个家庭:'+data);
  233. if(data.dataList.length>1){
  234. this.setData({
  235. homecssname:true
  236. });
  237. }else{
  238. this.setData({
  239. homecssname:false
  240. });
  241. }
  242. }).catch(e=>{
  243. console.log(e);
  244. })
  245. },
  246. hidecnacelbox() {
  247. this.setData({
  248. showcancelbox: false
  249. });
  250. },
  251. //确定提交任务
  252. confirmbox() {
  253. let id = this.data.taskId;
  254. let incompleteReason = this.data.incompleteReason;
  255. request.httpServicePost(apiUrl1.servantTaskSubmitPath, { id: id, state: 2, incompleteReason: incompleteReason }).then(data => {
  256. my.alert({
  257. title: '提示',
  258. content: '提交完成',
  259. buttonText: '确定',
  260. success: () => {
  261. this.setData({
  262. showcancelbox: false
  263. });
  264. this.selectDayTaskItem();
  265. }
  266. });
  267. });
  268. },
  269. onReasonModalClick(e){
  270. if(e.target.dataset.index==0){
  271. this.setData({
  272. showcancelbox: false
  273. });
  274. }else{
  275. this.confirmbox();
  276. }
  277. }
  278. });