fillWorkSelect.jsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
  2. <%@include file="/context/mytags.jsp" %>
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <title>填充排班</title>
  7. <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. .date-box {
  14. padding: 10px 10px;
  15. }
  16. .date-box h2 {
  17. margin-top: 20px;
  18. padding-bottom: 20px;
  19. }
  20. table {
  21. width: 100%;
  22. border-collapse: collapse;
  23. }
  24. table tr {
  25. display: -webkit-flex;
  26. display: flex;
  27. }
  28. table tr th,
  29. table tr td {
  30. padding: 10px;
  31. }
  32. #schedue tr th,
  33. #schedue tr td {
  34. flex: 1;
  35. padding: 10px 0;
  36. text-align: center;
  37. border: 1px solid #e1e8f6;
  38. }
  39. table tr th {
  40. background-color: #dddddd;
  41. }
  42. table tr td.active {
  43. background-color: #7087f4;
  44. color: #ffffff;
  45. }
  46. .select-all label {
  47. padding-left: 4px;
  48. cursor: pointer;
  49. margin: 0;
  50. vertical-align: middle;
  51. }
  52. .select-all input {
  53. display: inline-block;
  54. vertical-align: middle;
  55. margin-bottom: 2px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <!--排班时间 begin-->
  61. <div class="date-box">
  62. <p>请选择数据源:</p>
  63. <div>
  64. <input readonly type="hidden" id="userId"/>
  65. <input readonly type="hidden" id="carId"/>
  66. <div>排班人员:<input type="text" id="userName" readonly onclick="openUserSelect()"/><button style="font-size: 14px;margin-left: 0.5rem;" onclick="openUserSelect()" class="btu_element btu_brand_def">选择</button></div>
  67. <div style="margin-top: 0.5rem;">排班车辆:<input type="text" id="carName" readonly onclick="openCarSelect()"/><button style="font-size: 14px;margin-left: 0.5rem;" onclick="openCarSelect()" class="btu_element btu_brand_def">选择</button></div>
  68. </div>
  69. <p>请选择填充目标:</p>
  70. <div style="margin: 10px 0;">
  71. <button style="font-size: 14px;" onclick="checkAll(true)" id="checkAll" class="btu_element btu_brand_def">全选</button>
  72. <button style="font-size: 14px;" onclick="checkAll(false)" id="unCheckAll" class="btu_element btu_warning_def disabled">取消全选</button>
  73. </div>
  74. <table id="schedue"></table>
  75. </div>
  76. <!--排班时间 end-->
  77. </body>
  78. <script type="text/javascript">
  79. function openUserSelect(){
  80. $.dialog({
  81. content: 'url:publicpageController.do?userSelect&checkbox=true',
  82. zIndex: getzIndex(),
  83. title: '员工列表',
  84. lock: true,
  85. width: '1000px',
  86. height: '650px',
  87. opacity: 0.4,
  88. button: [
  89. {
  90. name: '确定', callback: function () {
  91. var iframe = this.iframe.contentWindow;
  92. if (iframe.getReason().length > 0) {
  93. var strData = eval(iframe.getReason());
  94. for (var key in strData[0]) {
  95. if (key == "strId") {
  96. $("#userId").val(strData[0][key]);
  97. } else if (key == "strName") {
  98. $('#userName').val(strData[0][key]);
  99. }
  100. }
  101. }
  102. }, focus: true
  103. },
  104. {
  105. name: '取消', callback: function () {
  106. }
  107. }
  108. ]
  109. }).zindex();
  110. }
  111. function openCarSelect(){
  112. if(${!empty workType && (workType == '16' || workType == '23' || workType == '25')}){
  113. tip("人员作业[垃圾厢房保洁作业、普扫作业、公厕保洁作业]禁止选择车辆!");
  114. }else{
  115. let contentUrl = "url:carController.do?nlist";
  116. // 判断作业类型是否是巡回保洁作业
  117. if(${!empty workType && workType == '25'}){
  118. contentUrl = "url:carController.do?nlist&carType=cleancyclic";
  119. }
  120. $.dialog({
  121. content: 'url:carController.do?nlist',
  122. zIndex: getzIndex(),
  123. title: '车辆列表',
  124. lock: true,
  125. width: '1000px',
  126. height: '650px',
  127. opacity: 0.4,
  128. button: [
  129. {
  130. name: '确定', callback: function () {
  131. var iframe = this.iframe.contentWindow;
  132. if (iframe.getReason().length > 0) {
  133. var strData = eval(iframe.getReason());
  134. for (var key in strData[0]) {
  135. if (key == "strId") {
  136. $("#carId").val(strData[0][key]);
  137. } else if (key == "strPlate") {
  138. $('#carName').val(strData[0][key]);
  139. }
  140. }
  141. }
  142. }, focus: true
  143. },
  144. {
  145. name: '取消', callback: function () {
  146. }
  147. }
  148. ]
  149. }).zindex();
  150. }
  151. }
  152. //编写自定义JS代码
  153. /*
  154. * 获取当天及之后的排班时间
  155. * @param month:指定的月份
  156. * @param dayCount:相对于今天的天数,形如:0,1,2.......
  157. */
  158. function getDateData(month, dayCount) {
  159. let yy, mm, dd;
  160. let d = new Date();
  161. let initDay = d.getFullYear() + '-' + month + '-01';
  162. d = new Date(initDay);
  163. d.setDate(d.getDate() + dayCount);
  164. yy = d.getFullYear();
  165. mm = (d.getMonth() + 1) > 9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1);
  166. dd = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
  167. return yy + "-" + mm + "-" + dd;
  168. }
  169. /*
  170. * 获取日期对应的星期名称
  171. * @param date:待转换日期,形如:'2018-04-11' 或 '2018-4-11'
  172. */
  173. function schedueByMonth(month) {
  174. let dates = [],
  175. weekData = [],
  176. weekDataFinal = [],
  177. d, m, w, weekNum, lastWeek, lastWeekDiff = [];
  178. let formatMonth = month > 9 ? month : '0' + month;
  179. for (let i = 0; i <= 31; i++) {
  180. d = getDateData(formatMonth, i);
  181. m = new Date(d).getMonth() + 1;
  182. if (m === month) {
  183. dates.push(d)
  184. }
  185. }
  186. w = new Date(dates[0]).getDay();
  187. if (w > 0) {
  188. for (let j = 0; j < w - 1; j++) {
  189. dates.unshift('')
  190. }
  191. } else if (w === 0) {
  192. for (let j = 0; j < 6; j++) {
  193. dates.unshift('')
  194. }
  195. }
  196. //dates分组:每组7天
  197. for (let i = 0; i < dates.length; i = i + 7) {
  198. weekDataFinal.push(dates.slice(i, i + 7));
  199. }
  200. //最后一行不够7个,则补齐
  201. lastWeek = weekDataFinal[weekDataFinal.length - 1];
  202. if (lastWeek.length < 7) {
  203. for (let k = 0; k < (7 - lastWeek.length); k++) {
  204. lastWeekDiff.push('')
  205. }
  206. lastWeek = lastWeek.concat(lastWeekDiff)
  207. weekDataFinal[weekDataFinal.length - 1] = lastWeek;
  208. }
  209. pendingWeekData(dates, weekDataFinal)
  210. }
  211. function pendingWeekData(dates, weekDataFinal) {
  212. let weekTitles = '<tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期日</td></tr>';
  213. let scheduDom = '',
  214. weeksDom = '',
  215. weekDom = '';
  216. weekDataFinal.forEach(function (item) {
  217. item.forEach(function (subItem) {
  218. let delDay = delWithDay(subItem);
  219. weekDom += '<td class="select-all" attr-date="' + subItem + '"> <label for="ob-' + delDay + '">' + delDay + '</label>';
  220. if (delDay) {
  221. weekDom += ' <input type="checkbox" name="scheduleDayCheckBox" value="'+(delDay > 9 ? delDay : "0" + delDay)+'" id="ob-' + delDay + '" > ';
  222. }
  223. weekDom += ' </td>';
  224. })
  225. weeksDom += '<tr>' + weekDom + '</tr>';
  226. weekDom = '';
  227. })
  228. scheduDom = weekTitles + weeksDom;
  229. $('#schedue').html(scheduDom);
  230. //加入业务数据
  231. // let date = ['2021-12-07', '2021-12-12', '2021-12-31']; //date为接口返回的排班时间,形如:['2019-12-07', '2019-12-12', '2019-12-28']
  232. // delWithSchedue(dates, date)
  233. }
  234. function delWithSchedue(dates, date) {
  235. let pesoDates = date; //date为接口返回的排班时间
  236. let index;
  237. if (pesoDates.length > 0) {
  238. pesoDates.forEach(function (item, index) {
  239. index = dates.indexOf(item)
  240. $('#schedue').find('td').eq(index + 7).addClass('active').click(function () {
  241. alert($(this).attr('attr-date'))
  242. })
  243. })
  244. }
  245. }
  246. function delWithDay(day) {
  247. if (day) {
  248. return new Date(day).getDate()
  249. } else {
  250. return ''
  251. }
  252. }
  253. //调用实例
  254. schedueByMonth(12)
  255. function getReason(){
  256. //填充排班
  257. //获取数据源
  258. let resArr=[],scheArr=[];
  259. // $('input[name="resourceCheckBox"]:checked').each(function(){
  260. // let checkedVal=$(this).val();
  261. //
  262. // resArr.push(checkedVal)
  263. // });
  264. // if(resArr.length == 0){
  265. // return ""
  266. // }
  267. const userId = $('#userId').val();
  268. const userName = $('#userName').val();
  269. const carId = $('#carId').val();
  270. const carName = $('#carName').val();
  271. if(userId === '' && userName === ''){
  272. tip('请选择排班员工!')
  273. // update-刘梦祥-2022年8月30日15:19:09(由于排班存在人员作业没有车辆,所以车辆信息不是必选选项)update-刘梦祥-2022年9月7日16:14:41(为了避免用户忘记选择排班车辆,故放开车辆非空判断并添加非人员作业判断条件)
  274. }else if(carId === '' && carName === '' && ${empty workType || (workType != '16' && workType != '23' && workType != '25')}){
  275. tip('请选择排班车辆!')
  276. }else{
  277. //获取填充目标
  278. $('input[name="scheduleDayCheckBox"]:checked').each(function(index){
  279. let checkedVal=$(this).val();
  280. scheArr.push({
  281. targetId:checkedVal,
  282. userId:userId,
  283. userName:userName,
  284. carId:carId,
  285. carName:carName
  286. })
  287. });
  288. return JSON.stringify(scheArr);
  289. }
  290. }
  291. //全选和取消全选点击事件
  292. function checkAll(flag){
  293. let ids = document.getElementsByName("scheduleDayCheckBox");
  294. for(let i=0;i<ids.length;i++){
  295. ids[i].checked=flag;
  296. }
  297. }
  298. </script>
  299. <style>
  300. .select-all{
  301. user-select: none;
  302. -moz-user-select: none;
  303. -ms-user-select: none;
  304. -webkit-user-select: none;
  305. }
  306. </style>