attendance_dutynew.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <div>
  3. <div style="padding:15px 0;">
  4. <div style="float:right;">
  5. <el-button type="primary" @click="get_excel_file">导出排班表</el-button>
  6. <el-button type="primary" @click="tolead_get_excel_file">导入排班表</el-button>
  7. </div>
  8. <div class="schedule_list">
  9. 班次:
  10. <span :style="'background:' + color[item.id] + '; color:#fff;'" v-for="(item, index) in schedule_list" :key="index">{{ item.name }}</span>
  11. <div><el-date-picker value-format="yyyy-MM" v-model="month_val" type="month" format="yyyy-MM" placeholder="选择月份"></el-date-picker></div>
  12. </div>
  13. <div style="clear:both;"></div>
  14. </div>
  15. <el-scrollbar v-loading="loading" wrap-class="column-wrapper scrollable-items-container" :native="false" style="height: 500px;">
  16. <div style="">
  17. <!-- 排班表头 -->
  18. <table id="schedule_table_header" style="width:100%;" class="schedule_table" cellspacing="0" cellpadding="0" @mouseleave="schedule_set_show = false">
  19. <tr>
  20. <td width="120" style="width:120px;">姓名</td>
  21. <td
  22. width="50"
  23. :style="'position: relative; width:' + td_width + 'px;'"
  24. @mouseenter="hover_head_index = schedule_index"
  25. @mouseleave="hover_head_index = -1"
  26. @contextmenu.prevent="show_schedule_set"
  27. v-for="(schedule, schedule_index) in table_header_list"
  28. :key="schedule_index"
  29. >
  30. <div>{{ schedule.name }}</div>
  31. <div style="font-size:12px;">{{ schedule.id }}</div>
  32. <el-card class="box-card" v-if="schedule_set_show && schedule_index == hover_head_index" style="position: absolute; width:200px; z-index:6; right:0;">
  33. <el-tabs v-model="activeName">
  34. <el-tab-pane label="选择班次" name="first">
  35. <span
  36. @click="set_schedule_one(item, -1, schedule_index)"
  37. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:block; margin:15px; padding:5px;'"
  38. v-for="(item, index1) in schedule_list"
  39. :key="index1"
  40. >
  41. {{ item.name }}
  42. </span>
  43. <span
  44. @click="set_schedule_one({ id: 0, name: '休息' }, -1, schedule_index)"
  45. style="background:#eee; cursor: pointer; color:#666; display:block; margin:15px; padding:5px;'"
  46. >
  47. 休息
  48. </span>
  49. </el-tab-pane>
  50. <el-tab-pane label="选择排班" name="second" v-if="false">
  51. <div style="padding:15px 5px; text-align: left;" @click="set_schedule_list(work_date_list, -1, schedule_index)">
  52. <div style="display: inline;" v-for="(item, index) in work_date_list" :key="index">
  53. <span v-if="index > 0" style="padding:0px">-></span>
  54. <span
  55. :class="{ work_not: item.id == 0 }"
  56. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:inline-block; padding:2px 5px; margin-bottom:5px;'"
  57. >
  58. {{ item.name }}
  59. </span>
  60. </div>
  61. </div>
  62. </el-tab-pane>
  63. </el-tabs>
  64. </el-card>
  65. </td>
  66. </tr>
  67. </table>
  68. <!-- 人员排班信息 -->
  69. <table class="schedule_table" cellspacing="0" cellpadding="0" @mouseleave="schedule_set_show = false">
  70. <tr v-for="(row, index) in tableData" :key="index">
  71. <td
  72. width="120"
  73. style="position: relative; width:120px;"
  74. @contextmenu.prevent="show_schedule_set"
  75. @mouseleave="
  76. schedule_set_show = false;
  77. hover_name_index = -1;
  78. "
  79. @mouseenter="hover_name_index = index"
  80. >
  81. {{ row.employee_name }}
  82. <el-card class="box-card" v-if="schedule_set_show && index == hover_name_index" style="position: absolute; width:200px; left:0; z-index:2;">
  83. <el-tabs v-model="activeName">
  84. <el-tab-pane label="选择班次" name="first">
  85. <span
  86. @click="set_schedule_one(item, index, -1)"
  87. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:block; margin:15px; padding:5px;'"
  88. v-for="(item, index1) in schedule_list"
  89. :key="index1"
  90. >
  91. {{ item.name }}
  92. </span>
  93. <span
  94. @click="set_schedule_one({ id: 0, name: '休息' }, index, -1)"
  95. style="background:#eee; cursor: pointer; color:#666; display:block; margin:15px; padding:5px;'"
  96. >
  97. 休息
  98. </span>
  99. </el-tab-pane>
  100. <el-tab-pane label="选择排班" name="second" v-if="false">
  101. <div style="padding:15px 5px; text-align: left;" @click="set_schedule_list(work_date_list, index, -1)">
  102. <div style="display: inline;" v-for="(item, index) in work_date_list" :key="index">
  103. <span v-if="index > 0" style="padding:0px">-></span>
  104. <span
  105. :class="{ work_not: item.id == 0 }"
  106. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:inline-block; padding:2px 5px; margin-bottom:5px;'"
  107. >
  108. {{ item.name }}
  109. </span>
  110. </div>
  111. </div>
  112. </el-tab-pane>
  113. </el-tabs>
  114. </el-card>
  115. </td>
  116. <td
  117. :data-count-key="'class-count-' + schedule.day + '-sid-' + schedule.id"
  118. style="position: relative;"
  119. @contextmenu.prevent="show_schedule_set"
  120. width="50"
  121. @mouseleave="table_hover = [-1, -1]"
  122. @mouseenter="td_hover(index, schedule_index)"
  123. :style="{width:td_width + 'px',background:color[schedule.id] ? color[schedule.id]:'#ccc',color:'#fff'}"
  124. :class="{ schedule_none: schedule.id == 0, td_hover: table_hover[0] == index || schedule_index == table_hover[1] }"
  125. v-for="(schedule, schedule_index) in row.schedule_list"
  126. :key="schedule_index"
  127. >
  128. <span v-if="schedule.name == 0">休息</span>
  129. <span v-else>{{ schedule.name }}</span>
  130. <el-card
  131. class="box-card"
  132. v-if="schedule_set_show && table_hover[0] == index && schedule_index == table_hover[1]"
  133. style="position: absolute; width:200px; right:0; z-index:2;"
  134. >
  135. <el-tabs v-model="activeName">
  136. <el-tab-pane label="选择班次" name="first">
  137. <span
  138. @click="set_schedule_one(item, index, schedule_index)"
  139. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:block; margin:15px; padding:5px;'"
  140. v-for="(item, index1) in schedule_list"
  141. :key="index1"
  142. >
  143. {{ item.name }}
  144. </span>
  145. <span
  146. @click="set_schedule_one({ id: 0, name: '休息' }, index, schedule_index)"
  147. style="background:#eee; cursor: pointer; color:#666; display:block; margin:15px; padding:5px;'"
  148. >
  149. 休息
  150. </span>
  151. </el-tab-pane>
  152. <el-tab-pane label="选择排班" name="second">
  153. <div style="padding:15px 5px; text-align: left;" @click="set_schedule_list(work_date_list, index, schedule_index)">
  154. <div style="display: inline;" v-for="(item, index) in work_date_list" :key="index">
  155. <span v-if="index > 0" style="padding:0px">-></span>
  156. <span
  157. :class="{ work_not: item.id == 0 }"
  158. :style="'background:' + color[item.id] + '; cursor: pointer; color:#fff; display:inline-block; padding:2px 5px; margin-bottom:5px;'"
  159. >
  160. {{ item.name }}
  161. </span>
  162. </div>
  163. </div>
  164. </el-tab-pane>
  165. </el-tabs>
  166. </el-card>
  167. </td>
  168. </tr>
  169. </table>
  170. <!-- 下面的班次表格 -->
  171. <div style="height: 46px;"></div>
  172. <table class="schedule_table" cellspacing="0" cellpadding="0">
  173. <tr>
  174. <td width="220">班次</td>
  175. <td width="80" v-for="(item, index) in table_header_list" :key="index">
  176. <div>{{ item.name }}</div>
  177. <div style="font-size:12px;">{{ item.id }}</div>
  178. <!-- <div style="font-size:12px;">{{item.week}}</div> -->
  179. </td>
  180. </tr>
  181. <tr v-for="(item, index) in schedule_count" :key="index">
  182. <td :style="'background:' + color[item.id] + '; color:#fff; padding:2px 5px;'">
  183. <span>{{ item.name }}</span>
  184. </td>
  185. <td v-for="(schedule, schedule_index) in item.count_list" :key="schedule_index">
  186. <span v-if="schedule.num == 0">休息</span>
  187. <span v-else>{{ schedule.num }}</span>
  188. </td>
  189. </tr>
  190. </table>
  191. </div>
  192. </el-scrollbar>
  193. <!-- 导入排班表 -->
  194. <el-dialog width="600px" title="Excel管理" append-to-body :visible.sync="dialogExcelVisible" :close-on-click-modal="false">
  195. <div style="padding:0 50px;">
  196. <div class="align-center" style="margin-bottom:20px;">
  197. <p>温馨提示:</p>
  198. <p>1、导入之前请点击“下载模板”按钮下载模板文件;</p>
  199. <p>2、填写排班信息到Excel电子表中;</p>
  200. <p>3、点击“Excel文件导入”上传填写好的电子表;</p>
  201. <p>4、支持上传大小500KB以内的Excel文件。</p>
  202. <p></p>
  203. </div>
  204. <div class="align-center" style="margin-bottom:20px; float:left; margin-left:10px;"><el-button type="primary" @click="downloadTemplate" plain>下载模板</el-button></div>
  205. <div class="align-center" style="margin-bottom:20px; float:left; margin-left:10px;">
  206. <el-upload
  207. :on-success="uploadFileEnd"
  208. :headers="{ 'J-Token': $getToken() }"
  209. :data="{ group_id: group_id }"
  210. list-type="text"
  211. name="file"
  212. :action="$serveAd + '/ad/group/import_schedule'"
  213. :show-file-list="false"
  214. >
  215. <el-button type="primary">Excel导入</el-button>
  216. </el-upload>
  217. </div>
  218. <div style="clear:both;"></div>
  219. </div>
  220. </el-dialog>
  221. </div>
  222. </template>
  223. <script>
  224. import moment from 'moment';
  225. export default {
  226. name: 'attendance_duty',
  227. watch: {
  228. month_val(n, o) {
  229. this.get_group_info(this.group_id);
  230. },
  231. table_hover(n, o) {
  232. this.schedule_set_show = false;
  233. }
  234. },
  235. data() {
  236. return {
  237. employId: '',
  238. listType: [],
  239. uplife: '',
  240. td_width: 0,
  241. dialogExcelVisible: false,
  242. save_duty_loading: false,
  243. table_header_list: [],
  244. hover_head_index: -1,
  245. hover_name_index: -1,
  246. work_date_list: [],
  247. schedule_set_show: false,
  248. activeName: 'first',
  249. loading: false,
  250. group_id: 0,
  251. month_val: moment().format('YYYY-MM'),
  252. color: [],
  253. table_hover: [-1, -1],
  254. schedule_list: [], // 班次列表
  255. schedule_count: [], // 班次下面的时间统计
  256. oldTabelData: [],
  257. tableData: [
  258. {
  259. employee_id: 113,
  260. employee_name: '张三',
  261. schedule_list: []
  262. }
  263. ]
  264. };
  265. },
  266. created() {
  267. (this.listType = []), this.aasd();
  268. },
  269. methods: {
  270. aasd() {},
  271. uploadFileEnd(response, file, fileList) {
  272. this.dialogExcelVisible = false;
  273. window.location.href;
  274. if (response.code == 1) {
  275. this.$message.success(response.msg);
  276. } else {
  277. this.$message.error(response.msg);
  278. }
  279. },
  280. // 下载模板 导出排班表
  281. downloadTemplate() {
  282. let self = this;
  283. var params = {
  284. group_id: self.group_id,
  285. month: self.month_val
  286. };
  287. this.$axiosKq('get', '/ad/group/export_schedule', params).then(res => {
  288. if (res.data.code == 1) {
  289. const url = res.data.data;
  290. window.location.href = url;
  291. }
  292. });
  293. },
  294. //导入排班表
  295. tolead_get_excel_file() {
  296. this.dialogExcelVisible = true;
  297. },
  298. // 导出排班表
  299. get_excel_file() {
  300. let self = this;
  301. var params = {
  302. group_id: self.group_id,
  303. month: self.month_val
  304. };
  305. this.$axiosKq('get', '/ad/group/export_schedule', params).then(res => {
  306. if (res.data.code == 1) {
  307. const url = res.data.data;
  308. window.location.href = url;
  309. }
  310. });
  311. },
  312. td_hover(i, o) {
  313. this.table_hover = [i, o];
  314. },
  315. // 更改全不数据
  316. set_schedule_list(item, row, col) {
  317. let j = 0;
  318. let self = this;
  319. let l = 0;
  320. let listType=[];
  321. if (row >= 0 && col >= 0) {
  322. let list=this.tableData[row].schedule_list
  323. let employId=this.tableData[row].employee_id
  324. for (let i in list) {
  325. if (i >= col) {
  326. listType.push({schedule_id: item[0].id, employee_id: employId, date: list[i].day})
  327. l++;
  328. list[i].name = item[j].name;
  329. list[i].id = item[j].id;
  330. if (j == item.length - 1) {
  331. j = 0;
  332. } else {
  333. j++;
  334. }
  335. }
  336. }
  337. }
  338. this.listType=listType;
  339. this.schedule_set_show = false;
  340. this.table_hover = [-1, -1];
  341. self.$nextTick(() => {
  342. self.set_schedule_count();
  343. });
  344. this.hover_name_index = -1;
  345. this.hover_head_index = -1;
  346. },
  347. // 保存修改
  348. send_schedule() {
  349. let self = this;
  350. this.$axiosKq('post', '/ad/group/update_schedule', { group_id: this.group_id, data: JSON.stringify(self.listType)}).then(res => {
  351. self.$emit('saved');
  352. if (res.data.code == 1) {
  353. self.listType = [];
  354. self.$message.success(res.data.msg);
  355. } else {
  356. self.$message.error(res.data.msg);
  357. }
  358. });
  359. },
  360. // 更改单条数据
  361. set_schedule_one(item, row, col) {
  362. let self = this;
  363. let date = '';
  364. if (row >= 0 && col >= 0) {
  365. this.tableData[row].schedule_list[col].name = item.name;
  366. this.tableData[row].schedule_list[col].id = item.id;
  367. this.employId = this.tableData[row].employee_id;
  368. date = this.tableData[row].schedule_list[col].day;
  369. }
  370. if (row == -1 && col >= 0) {
  371. for (let i in this.tableData) {
  372. this.tableData[i].schedule_list[col].name = item.name;
  373. this.tableData[i].schedule_list[col].id = item.id;
  374. this.employId = this.tableData[i].employee_id;
  375. date = this.tableData[i].schedule_list[col].day;
  376. }
  377. }
  378. if (row >= 0 && col == -1) {
  379. for (let i in this.tableData[row].schedule_list) {
  380. this.tableData[row].schedule_list[i].name = item.name;
  381. this.tableData[row].schedule_list[i].id = item.id;
  382. this.employId = this.tableData[row].employee_id;
  383. date = this.tableData[row].schedule_list[i].day;
  384. }
  385. }
  386. this.getnewList();
  387. this.schedule_set_show = false;
  388. this.table_hover = [-1, -1];
  389. self.$nextTick(() => {
  390. self.set_schedule_count();
  391. });
  392. },
  393. getnewList() {
  394. let self = this;
  395. this.$axiosKq('get', '/ad/group/schedule', { group_id: self.group_id, month: self.month_val }).then(res => {
  396. if (res.data.code == 1) {
  397. let { data = {} } = res.data;
  398. self.oldTabelData = data.table_data;
  399. for (let i = 0; i < this.tableData.length; i++) {
  400. if (this.tableData[i].employee_id == self.oldTabelData[i].employee_id) {
  401. for (let k = 0; k < this.tableData[i].schedule_list.length; k++) {
  402. if (this.tableData[i].schedule_list[k].id == self.oldTabelData[i].schedule_list[k].id) {
  403. } else {
  404. this.listType.push({
  405. schedule_id: this.tableData[i].schedule_list[k].id,
  406. employee_id: this.tableData[i].employee_id,
  407. date: this.tableData[i].schedule_list[k].day
  408. });
  409. }
  410. }
  411. }
  412. }
  413. }
  414. });
  415. },
  416. show_schedule_set() {
  417. this.activeName = 'first';
  418. this.schedule_set_show = true;
  419. },
  420. set_schedule_count() {
  421. const self = this;
  422. let count_list = [];
  423. this.schedule_count = [];
  424. let schedule = [];
  425. for (var i = 0; i < this.tableData.length; i++) {
  426. schedule.push({});
  427. schedule[i] = this.tableData[i].schedule_list;
  428. }
  429. for (let i in this.schedule_list) {
  430. // attendance_setting_ids
  431. count_list = [];
  432. for (let k in schedule[0]) {
  433. // table_header
  434. count_list.push({ num: document.querySelectorAll('[data-count-key=' + 'class-count-' + schedule[0][k].day + '-sid-' + this.schedule_list[i].id + ']').length });
  435. }
  436. this.schedule_count.push({
  437. id: this.schedule_list[i].id,
  438. name: this.schedule_list[i].name,
  439. count_list: count_list
  440. });
  441. }
  442. },
  443. // 加载排班表数据
  444. get_group_info(id) {
  445. let self = this;
  446. self.group_id = id;
  447. self.loading = true;
  448. this.$axiosKq('get', '/ad/group/schedule', { group_id: id, month: self.month_val }).then(res => {
  449. if (res.status == 200) {
  450. self.loading = false;
  451. let { data = {} } = res.data;
  452. self.oldTabelData = data.table_data;
  453. self.schedule_list = data.schedules; //班次信息 班次名称 打卡时间段
  454. self.work_date_list = data.schedules; // 选择排班
  455. let color = ['#1E90FF','#FF69B4','#FF5656','#8470FF','#3CB371','#FF9600','#0055FF','#7BC6FF','#FF08A0','#FFCC00'];
  456. for (let i in self.schedule_list) {
  457. self.color[self.schedule_list[i].id] = color[i % color.length];
  458. }
  459. self.color[0] = '#ffffff';
  460. self.tableData = data.table_data; // 表格主体 渲染排班表
  461. let week = [];
  462. for (var i = 0; i < data.week.length; i++) {
  463. week.push({});
  464. week[i].id = data.week[i];
  465. week[i].name = data.header[i].split('-')[2];
  466. }
  467. self.table_header_list = week; // 表头
  468. self.$nextTick(() => {
  469. self.set_schedule_count();
  470. self.td_width = (document.getElementById('schedule_table_header').offsetWidth - 120) / self.table_header_list.length;
  471. });
  472. }
  473. });
  474. }
  475. }
  476. };
  477. </script>
  478. <style scoped>
  479. .schedule_list span {
  480. display: inline-block;
  481. margin: 5px;
  482. background-color: #ccc;
  483. padding: 2px 5px;
  484. border-radius: 3px;
  485. }
  486. .schedule_table {
  487. border-left: 1px solid #ccc;
  488. border-bottom: 1px solid #ccc;
  489. }
  490. .schedule_table td {
  491. border-right: 1px solid #ccc;
  492. cursor: default;
  493. border-top: 1px solid #ccc;
  494. text-align: center;
  495. padding: 0;
  496. height: 50px;
  497. width: 46px;
  498. }
  499. .schedule_none {
  500. color: #666 !important;
  501. }
  502. .schedule_table td:hover {
  503. background-color: #8891f9 !important;
  504. color: #fff;
  505. }
  506. .td_hover {
  507. background-color: #c3d5f9 !important;
  508. color: #fff !important;
  509. }
  510. .work_not {
  511. color: #666 !important;
  512. background-color: #ccc !important;
  513. }
  514. .work_date_not {
  515. color: #f00;
  516. }
  517. </style>