AttendanceRuleModal.vue 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. <template>
  2. <j-modal title="排班" :width="1000" :visible="visible" @ok="saves()" :fullscreen="true" switchFullscreen @cancel="handleCancel">
  3. <a-spin :spinning="confirmLoading">
  4. <!-- <a-form :form="form">
  5. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="*上班类型">
  6. <a-radio-group v-model="types">
  7. <a-radio value="1">固定时间上下班</a-radio>
  8. <a-radio value="2">按班次上下班</a-radio>
  9. <a-radio value="3">自由上下班</a-radio>
  10. </a-radio-group>
  11. </a-form-item>
  12. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="*上班时间" v-if="types==1">
  13. <a-time-picker showTime format='HH:mm' v-model="startDate">
  14. <div slot="addon" style="width:100%;overflow:hidden">
  15. <div style="width:50%;float:left;border-right:solid 1px ;text-align:center">
  16. <div style="padding-top:10%;padding-bottom:10%">
  17. <span style="width:100%;">时</span>
  18. </div>
  19. </div>
  20. <div style="width:50%;float:right;text-align:center">
  21. <div style="padding-top:10%;padding-bottom:10%">
  22. <span style="width:100%;">分</span>
  23. </div>
  24. </div>
  25. </div>
  26. </a-time-picker>
  27. </a-form-item>
  28. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="*下班时间" v-if="types==1">
  29. <a-time-picker showTime format='HH:mm' v-model="endDate">
  30. <div slot="addon" style="width:100%;overflow:hidden">
  31. <div style="width:50%;float:left;border-right:solid 1px ;text-align:center">
  32. <div style="padding-top:10%;padding-bottom:10%">
  33. <span style="width:100%;">时</span>
  34. </div>
  35. </div>
  36. <div style="width:50%;float:right;text-align:center">
  37. <div style="padding-top:10%;padding-bottom:10%">
  38. <span style="width:100%;">分</span>
  39. </div>
  40. </div>
  41. </div>
  42. </a-time-picker>
  43. </a-form-item>
  44. </a-form> -->
  45. <!-- <a-form-item v-if="types!=2" label="*打卡人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
  46. <a-tag v-for='(user,i) in selectUsers' :key="user.id" closable @close="tagBtnCloseFunc(user)">{{user.realname}}
  47. </a-tag>
  48. </a-form-item> -->
  49. <div v-if="types=='2'">
  50. <div class='month'>
  51. <ul>
  52. <!--点击会触发pickpre函数,重新刷新当前日期 @click(vue v-on:click缩写) -->
  53. <li class='arrow'>
  54. <a-popconfirm title="是否保存?" ok-text="是" cancel-text="否"
  55. @confirm="yes(1)"
  56. @cancel="no(1)"
  57. >
  58. <a-button type="primary" >上个月</a-button></a-popconfirm>
  59. </li>
  60. <li class='year-month'>
  61. <span class='choose-year'>{{ currentYear }}年</span>
  62. <span class='choose-month'>{{ currentMonth }}月</span>
  63. </li>
  64. <li class='arrow'>
  65. <a-popconfirm title="是否保存?" ok-text="是" cancel-text="否"
  66. @confirm="yes(2)"
  67. @cancel="no(2)"
  68. >
  69. <a-button type="primary">下个月</a-button></a-popconfirm>
  70. </li>
  71. </ul>
  72. <br>
  73. </div>
  74. <div>
  75. <a-table bordered :data-source="dataSource" :loading="loading" :columns="columns" :scroll="{ x:1500,y:500}" :pagination="ipagination"
  76. @change="handleTableChange">
  77. <template v-for='(dayobject,i) in days' :slot="dayobject.day.getDate()" style="color: #ff6b81">
  78. <div style="height: 35px;">
  79. <div style="text-align: center;margin-top: -13px;margin-left: 10px;">
  80. <p>{{dayobject.day.getDate()}}</p>
  81. <div style="margin-top: -10px;">
  82. <p v-if='dayobject.day.getDay()==0'>日</p>
  83. <p v-else-if='dayobject.day.getDay()==1'>一</p>
  84. <p v-else-if='dayobject.day.getDay()==2'>二</p>
  85. <p v-else-if='dayobject.day.getDay()==3'>三</p>
  86. <p v-else-if='dayobject.day.getDay()==4'>四</p>
  87. <p v-else-if='dayobject.day.getDay()==5'>五</p>
  88. <p v-else-if='dayobject.day.getDay()==6'>六</p>
  89. </div>
  90. </div>
  91. </div>
  92. </template>
  93. <span v-for='(d,i) in tpdata' style="margin-left: -11px;" :slot="d" slot-scope="text, record, index">
  94. <a-dropdown :trigger="['click']">
  95. <a-tag closable @close="(e) => log(e,d,record)" color="blue" v-if="text=='休息'" @click="UserType(d,record,index)">{{text}}</a-tag>
  96. <a-tag closable @close="(e) => log(e,d,record)" color="#87d068" v-else-if="text!='休息'&&text!=''&&text!=null" @click="UserType(d,record,index)">
  97. {{text}}
  98. </a-tag>
  99. <a-tag color="#FFFFFF" v-else @click="UserType(d,record,index)" style="width: 60px;height: 22px;"> </a-tag>
  100. <a-menu slot="overlay" v-if="record.isColse" :style="isShow?'height:300px;overflow-y: scroll;':''">
  101. <a-menu-item key="0" v-if="isShows">
  102. <a @click="shiftOks(0,d,record,index)">休息</a>
  103. </a-menu-item>
  104. <a-menu-item v-if="isShow" v-for="(item,index) in shiftlist" :key="item.id">
  105. <a @click="shiftOks(item,d,record,index)">{{item.name}} <span>({{item.startDate}} - {{item.endDate}}<span v-if="item.shiftType==1"> / {{item.start2Date}} - {{item.end2Date}}</span>)</span></a>
  106. </a-menu-item>
  107. </a-menu>
  108. </a-dropdown>
  109. </span>
  110. <template slot="names" slot-scope="text, record, index">
  111. <div style="height: 27px;">
  112. {{text}}
  113. </div>
  114. </template>
  115. </a-table>
  116. </div>
  117. </a-calendar>
  118. <a-modal v-model="visibles" title="班次" @ok="shiftOk()">
  119. <div class="table-page-search-wrapper">
  120. <a-form layout="inline">
  121. <a-row :gutter="24">
  122. <a-col :xl="10" :lg="10" :md="8" :sm="24">
  123. <a-form-item label="班次名称">
  124. <a-select v-model="shiftname" placeholder="请选择班次">
  125. <a-select-option value="">请选择</a-select-option>
  126. <a-select-option value="a">休息</a-select-option>
  127. <a-select-option v-for="(item,index) in shiftlist" :value="item.id">{{item.name}}
  128. </a-select-option>
  129. </a-select>
  130. </a-form-item>
  131. </a-col>
  132. </a-row>
  133. </a-form>
  134. </div>
  135. </a-modal>
  136. </div>
  137. </a-spin>
  138. </j-modal>
  139. </template>
  140. <script>
  141. import {
  142. httpAction,
  143. getFileAccessHttpUrl,
  144. getAction,
  145. deleteAction
  146. } from '@/api/manage'
  147. import pick from 'lodash.pick'
  148. import moment from "moment"
  149. import {
  150. JeecgListMixin
  151. } from '@/mixins/JeecgListMixin'
  152. import '@/assets/less/TableExpand.less'
  153. import ar from '../AttendanceRuleList.vue'
  154. export default {
  155. name: "UserShiftModal",
  156. mixins: [JeecgListMixin],
  157. data() {
  158. return {
  159. tts: false,
  160. tpdata: [],
  161. dataSource: [],
  162. savef:true,
  163. columns: [],
  164. queryParam: {
  165. shiftDate: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  166. type: "1"
  167. },
  168. types: "1",
  169. currentMonth: new Date().getMonth(),
  170. currentYear: new Date().getYear(),
  171. days: [],
  172. selectUsers: [],
  173. checkUserIds: "",
  174. visibles: false,
  175. shiftDate: null,
  176. startDate: "",
  177. endDate: "",
  178. show: 1,
  179. id: null,
  180. obj: {
  181. "cid": "C0",
  182. "ctext": "区县"
  183. },
  184. shiftname: "",
  185. username: "",
  186. deptlist: null,
  187. shiftlist: null,
  188. title: "操作",
  189. visible: false,
  190. isSave:false,
  191. key: null,
  192. index: null,
  193. vs: false,
  194. model: {},
  195. labelCol: {
  196. xs: {
  197. span: 24
  198. },
  199. sm: {
  200. span: 5
  201. },
  202. },
  203. wrapperCol: {
  204. xs: {
  205. span: 24
  206. },
  207. sm: {
  208. span: 16
  209. },
  210. },
  211. isShow: true,
  212. isShows: true,
  213. listData: [],
  214. confirmLoading: false,
  215. form: this.$form.createForm(this),
  216. validatorRules: {},
  217. url: {
  218. add: "/attendanceRule/attendanceRule/add",
  219. userShift: "/userShift/userShift/queryMothByUser",
  220. shift: "/shift/shift/lists",
  221. list: "/sys/user/queryMothByUsers",
  222. moth: "/userShift/userShift/queryMothByUser",
  223. deptlist: "/sys/sysDepart/listAll",
  224. delUserShift: '/userShift/userShift/delete',
  225. edit: '/attendanceRule/attendanceRule/edit',
  226. userShiftDay:'/userShift/userShift/UserShiftType'
  227. },
  228. }
  229. },
  230. created() {
  231. this.initData(null)
  232. this.queryShift()
  233. },
  234. mounted () {
  235. // this.h = document.querySelector('.ptp-layout-main').offsetHeight - 45
  236. const _this = this
  237. var tableBodyInnerNodeList = document.querySelectorAll('.ant-table-body-inner')
  238. tableBodyInnerNodeList.forEach(item => {
  239. this.$nextTick(() => {
  240. item.style.maxHeight = (parseInt(item.style.maxHeight) - 13) + 'px'
  241. })
  242. })
  243. window.addEventListener('resize', function () {
  244. // _this.h = document.querySelector('.ptp-layout-main').offsetHeight - 45
  245. tableBodyInnerNodeList = document.querySelectorAll('.ant-table-body-inner')
  246. tableBodyInnerNodeList.forEach(item => {
  247. _this.$nextTick(() => {
  248. item.style.maxHeight = (parseInt(item.style.maxHeight) - 13) + 'px'
  249. })
  250. })
  251. })
  252. },
  253. methods: {
  254. log(e,b,c){
  255. e.preventDefault();
  256. if(!c.isColse){
  257. this.$message.warning("当月已关账无法操作!");
  258. return;
  259. }
  260. var name="";
  261. var shift="";
  262. if (b == 1) {
  263. c.a1 = name;
  264. c.shiftid1 = shift;
  265. } else if (b == 2) {
  266. c.a2 = name;
  267. c.shiftid2 = shift;
  268. } else if (b == 3) {
  269. c.a3 = name;
  270. c.shiftid3 = shift;
  271. } else if (b == 4) {
  272. c.a4 = name;
  273. c.shiftid4 = shift;
  274. } else if (b == 5) {
  275. c.a5 = name;
  276. c.shiftid5 = shift;
  277. } else if (b == 6) {
  278. c.a6 = name;
  279. c.shiftid6 = shift;
  280. } else if (b == 7) {
  281. c.a7 = name;
  282. c.shiftid7 = shift;
  283. } else if (b == 8) {
  284. c.a8 = name;
  285. c.shiftid8 = shift;
  286. } else if (b == 9) {
  287. c.a9 = name;
  288. c.shiftid9 = shift;
  289. } else if (b == 10) {
  290. c.a10 = name;
  291. c.shiftid10 = shift;
  292. } else if (b == 11) {
  293. c.a11 = name;
  294. c.shiftid11 = shift;
  295. } else if (b == 12) {
  296. c.a12 = name;
  297. c.shiftid12 = shift;
  298. } else if (b == 13) {
  299. c.a13 = name;
  300. c.shiftid13 = shift;
  301. } else if (b == 14) {
  302. c.a14 = name;
  303. c.shiftid14 = shift;
  304. } else if (b == 15) {
  305. c.a15 = name;
  306. c.shiftid15 = shift;
  307. } else if (b == 16) {
  308. c.a16 = name;
  309. c.shiftid16 = shift;
  310. } else if (b == 17) {
  311. c.a17 = name;
  312. c.shiftid17 = shift;
  313. } else if (b == 18) {
  314. c.a18 = name;
  315. c.shiftid18 = shift;
  316. } else if (b == 19) {
  317. c.a19 = name;
  318. c.shiftid19 = shift;
  319. } else if (b == 20) {
  320. c.a20 = name;
  321. c.shiftid20 = shift;
  322. } else if (b == 21) {
  323. c.a21 = name;
  324. c.shiftid21 = shift;
  325. } else if (b == 22) {
  326. c.a22 = name;
  327. c.shiftid22 = shift;
  328. } else if (b == 23) {
  329. c.a23 = name;
  330. c.shiftid23 = shift;
  331. } else if (b == 24) {
  332. c.a24 = name;
  333. c.shiftid24 = shift;
  334. } else if (b == 25) {
  335. c.a25 = name;
  336. c.shiftid25 = shift;
  337. } else if (b == 26) {
  338. c.a26 = name;
  339. c.shiftid26 = shift;
  340. } else if (b == 27) {
  341. c.a27 = name;
  342. c.shiftid27 = shift;
  343. } else if (b == 28) {
  344. c.a28 = name;
  345. c.shiftid28 = shift;
  346. } else if (b == 29) {
  347. c.a29 = name;
  348. c.shiftid29 = shift;
  349. } else if (b == 30) {
  350. c.a30 = name;
  351. c.shiftid30 = shift;
  352. } else if (b == 31) {
  353. c.a31 = name;
  354. c.shiftid31 = shift;
  355. }
  356. },
  357. saves(){
  358. this.savef=true;
  359. this.save()
  360. },
  361. yes(e){
  362. this.savef=false;
  363. this.save();
  364. if(e==1){
  365. this.pickPre(this.currentYear,this.currentMonth)
  366. }else if(e==2){
  367. this.pickNext(this.currentYear,this.currentMonth);
  368. }
  369. },
  370. no(e){
  371. if(e==1){
  372. this.pickPre(this.currentYear,this.currentMonth)
  373. }else if(e==2){
  374. this.pickNext(this.currentYear,this.currentMonth);
  375. }
  376. },
  377. tagBtnCloseFunc(e) {
  378. const tags = this.selectUsers.filter(tag => tag !== e);
  379. this.selectUsers = tags;
  380. },
  381. UserType(e, a, index) {
  382. if(!a.isColse){
  383. this.$message.warning("当月已关账无法操作!");
  384. return;
  385. }
  386. this.isShow = true;
  387. this.isShows = true;
  388. var d = new Date(this.formatDate(this.currentYear, this.currentMonth, e))
  389. var obj = this.dataSource[index];
  390. var list = [];
  391. var sum=0;
  392. var xsum=0;
  393. var f=false;
  394. if (d.getDay() == 1) {
  395. list.push(this.getDays(0, d));
  396. list.push(this.getDays(1, d));
  397. list.push(this.getDays(2, d));
  398. list.push(this.getDays(3, d));
  399. list.push(this.getDays(4, d));
  400. list.push(this.getDays(5, d));
  401. list.push(this.getDays(6, d));
  402. } else if (d.getDay() == 2) {
  403. list.push(this.getDays(-1, d));
  404. list.push(this.getDays(0, d));
  405. list.push(this.getDays(1, d));
  406. list.push(this.getDays(2, d));
  407. list.push(this.getDays(3, d));
  408. list.push(this.getDays(4, d));
  409. list.push(this.getDays(5, d));
  410. } else if (d.getDay() == 3) {
  411. list.push(this.getDays(-2, d));
  412. list.push(this.getDays(-1, d));
  413. list.push(this.getDays(0, d));
  414. list.push(this.getDays(1, d));
  415. list.push(this.getDays(2, d));
  416. list.push(this.getDays(3, d));
  417. list.push(this.getDays(4, d));
  418. } else if (d.getDay() == 4) {
  419. list.push(this.getDays(-3, d));
  420. list.push(this.getDays(-2, d));
  421. list.push(this.getDays(-1, d));
  422. list.push(this.getDays(0, d));
  423. list.push(this.getDays(1, d));
  424. list.push(this.getDays(2, d));
  425. list.push(this.getDays(3, d));
  426. } else if (d.getDay() == 5) {
  427. list.push(this.getDays(-4, d));
  428. list.push(this.getDays(-3, d));
  429. list.push(this.getDays(-2, d));
  430. list.push(this.getDays(-1, d));
  431. list.push(this.getDays(0, d));
  432. list.push(this.getDays(1, d));
  433. list.push(this.getDays(2, d));
  434. } else if (d.getDay() == 6) {
  435. list.push(this.getDays(-5, d));
  436. list.push(this.getDays(-4, d));
  437. list.push(this.getDays(-3, d));
  438. list.push(this.getDays(-2, d));
  439. list.push(this.getDays(-1, d));
  440. list.push(this.getDays(0, d));
  441. list.push(this.getDays(1, d));
  442. } else if (d.getDay() == 0) {
  443. list.push(this.getDays(-6, d));
  444. list.push(this.getDays(-5, d));
  445. list.push(this.getDays(-4, d));
  446. list.push(this.getDays(-3, d));
  447. list.push(this.getDays(-2, d));
  448. list.push(this.getDays(-1, d));
  449. list.push(this.getDays(0, d));
  450. }
  451. for (var i = 0; i < list.length; i++) {
  452. if (list[i].split("-")[0] != this.currentYear || list[i].split("-")[1] != this.currentMonth) {
  453. getAction(this.url.userShiftDay, {
  454. userid: a.id,
  455. shiftDate:moment(new Date(list[i])).format('YYYY-MM-DD HH:mm:ss') ,
  456. }
  457. ).then((res) => {
  458. if (res.success) {
  459. if(res.result!=0&&res.result!='0'){
  460. sum++;
  461. }else if(res.result==0||res.result=='0'){
  462. xsum++;
  463. }
  464. }
  465. }).finally(() => {
  466. })
  467. list.splice(i, 1)
  468. }
  469. }
  470. for (var o = 0; o< list.length; o++) {
  471. for (var t in obj) { //用javascript的for/in循环遍历对象的属性
  472. if(this.currentYear==list[o].split("-")[0]&&this.currentMonth==list[o].split("-")[1]){
  473. if (t == "shiftid" + list[o].split("-")[2]&&list[o].split("-")[2]==e) {
  474. if(obj[t]!=0&&obj[t]!="0"&&obj[t]!=null){
  475. sum++;
  476. f=true;
  477. } if(obj[t]!=null&&obj[t]=="0"){
  478. xsum++;
  479. }
  480. }else if(t == "shiftid" + list[o].split("-")[2]){
  481. if(obj[t]!=0&&obj[t]!="0"&&obj[t]!=null){
  482. sum++;
  483. } if(obj[t]!=null&&obj[t]=="0"){
  484. xsum++;
  485. }
  486. }
  487. }
  488. }
  489. }
  490. if (a.category == 106) {
  491. if (sum==6&&f==false) {
  492. this.isShow = false;
  493. }
  494. } else{
  495. if (sum==5&&f==false) {
  496. this.isShow = false;
  497. }else if(xsum==2){
  498. this.isShows = false;
  499. }
  500. }
  501. },
  502. // 获取当前时间,day为number,getDay(-1):昨天的日期;getDay(0):今天的日期;getDay(1):明天的日期;【以此类推】
  503. getDays(day, date) {
  504. var today = new Date(date);
  505. var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
  506. today.setTime(targetday_milliseconds); //注意,这行是关键代码
  507. var tYear = today.getFullYear();
  508. var tMonth = today.getMonth() + 1;
  509. var tDate = today.getDate();
  510. return tYear + "-" + tMonth + "-" + tDate;
  511. },
  512. doHandleMonth(month) {
  513. var m = month;
  514. if (month.toString().length == 1) {
  515. m = "0" + month;
  516. }
  517. return m;
  518. },
  519. shiftOks(a, b, c, d) {
  520. var date = this.currentYear + "-" + this.currentMonth + "-" + b + " 00:00:000";
  521. var name = a.name;
  522. var shift = a.id;
  523. if (a == 0 || a == "0") {
  524. name = "休息";
  525. shift = "0";
  526. }
  527. if (b == 1) {
  528. c.a1 = name;
  529. c.shiftid1 = shift;
  530. } else if (b == 2) {
  531. c.a2 = name;
  532. c.shiftid2 = shift;
  533. } else if (b == 3) {
  534. c.a3 = name;
  535. c.shiftid3 = shift;
  536. } else if (b == 4) {
  537. c.a4 = name;
  538. c.shiftid4 = shift;
  539. } else if (b == 5) {
  540. c.a5 = name;
  541. c.shiftid5 = shift;
  542. } else if (b == 6) {
  543. c.a6 = name;
  544. c.shiftid6 = shift;
  545. } else if (b == 7) {
  546. c.a7 = name;
  547. c.shiftid7 = shift;
  548. } else if (b == 8) {
  549. c.a8 = name;
  550. c.shiftid8 = shift;
  551. } else if (b == 9) {
  552. c.a9 = name;
  553. c.shiftid9 = shift;
  554. } else if (b == 10) {
  555. c.a10 = name;
  556. c.shiftid10 = shift;
  557. } else if (b == 11) {
  558. c.a11 = name;
  559. c.shiftid11 = shift;
  560. } else if (b == 12) {
  561. c.a12 = name;
  562. c.shiftid12 = shift;
  563. } else if (b == 13) {
  564. c.a13 = name;
  565. c.shiftid13 = shift;
  566. } else if (b == 14) {
  567. c.a14 = name;
  568. c.shiftid14 = shift;
  569. } else if (b == 15) {
  570. c.a15 = name;
  571. c.shiftid15 = shift;
  572. } else if (b == 16) {
  573. c.a16 = name;
  574. c.shiftid16 = shift;
  575. } else if (b == 17) {
  576. c.a17 = name;
  577. c.shiftid17 = shift;
  578. } else if (b == 18) {
  579. c.a18 = name;
  580. c.shiftid18 = shift;
  581. } else if (b == 19) {
  582. c.a19 = name;
  583. c.shiftid19 = shift;
  584. } else if (b == 20) {
  585. c.a20 = name;
  586. c.shiftid20 = shift;
  587. } else if (b == 21) {
  588. c.a21 = name;
  589. c.shiftid21 = shift;
  590. } else if (b == 22) {
  591. c.a22 = name;
  592. c.shiftid22 = shift;
  593. } else if (b == 23) {
  594. c.a23 = name;
  595. c.shiftid23 = shift;
  596. } else if (b == 24) {
  597. c.a24 = name;
  598. c.shiftid24 = shift;
  599. } else if (b == 25) {
  600. c.a25 = name;
  601. c.shiftid25 = shift;
  602. } else if (b == 26) {
  603. c.a26 = name;
  604. c.shiftid26 = shift;
  605. } else if (b == 27) {
  606. c.a27 = name;
  607. c.shiftid27 = shift;
  608. } else if (b == 28) {
  609. c.a28 = name;
  610. c.shiftid28 = shift;
  611. } else if (b == 29) {
  612. c.a29 = name;
  613. c.shiftid29 = shift;
  614. } else if (b == 30) {
  615. c.a30 = name;
  616. c.shiftid30 = shift;
  617. } else if (b == 31) {
  618. c.a31 = name;
  619. c.shiftid31 = shift;
  620. }
  621. },
  622. pickPre: function(year, month) {
  623. var d = new Date(this.formatDate(year, month, 1))
  624. d.setDate(0)
  625. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  626. this.queryParam.shiftDate = this.formatDate(d.getFullYear(), d.getMonth() + 1, 1) + " 00:00:000";
  627. this.$options.methods.searchQuery.call(this)
  628. },
  629. pickNext: function(year, month) {
  630. var d = new Date(this.formatDate(year, month + 1, 1))
  631. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  632. this.queryParam.shiftDate = this.formatDate(d.getFullYear(), d.getMonth() + 1, 1) + " 00:00:000";
  633. this.$options.methods.searchQuery.call(this)
  634. },
  635. initData: function(cur) {
  636. this.columns = [];
  637. var date
  638. if (cur) {
  639. date = new Date(cur)
  640. } else {
  641. var now = new Date()
  642. date = now;
  643. }
  644. this.currentDay = date.getDate()
  645. this.currentYear = date.getFullYear()
  646. this.currentMonth = date.getMonth() + 1
  647. this.currentWeek = date.getDay() // 1...6,0
  648. var str = this.formatDate(
  649. this.currentYear,
  650. this.currentMonth,
  651. this.currentDay
  652. )
  653. this.days.length = 0
  654. var moth = new Date(str);
  655. moth.setDate(28)
  656. moth.setMonth(moth.getMonth() + 1);
  657. moth.setDate(0);
  658. this.columns.push({
  659. title: '名称',
  660. dataIndex: 'realname',
  661. width: '80px',
  662. scopedSlots: {
  663. customRender: 'names'
  664. },
  665. fixed: 'left'
  666. })
  667. for (var i = 1; i <= moth.getDate(); i++) {
  668. var d = new Date(this.formatDate(this.currentYear, this.currentMonth, i))
  669. this.tpdata.push(i)
  670. var dayobjectSelf = {
  671. width: '70px',
  672. slots: {
  673. title: d.getDate()
  674. },
  675. dataIndex: "a" + d.getDate(),
  676. scopedSlots: {
  677. customRender: i
  678. },
  679. } // 用一个对象包装Date对象 以便为以后预定功能添加属性
  680. var dat = {};
  681. dat.day = d;
  682. this.days.push(dat)
  683. this.columns.push(dayobjectSelf) // 将日期放入data 中的days数组 供页面渲染使用
  684. }
  685. },
  686. // 返回 类似 2016-01-02 格式的字符串
  687. formatDate: function(year, month, day) {
  688. var y = year
  689. if (month > 12) {
  690. y = y + 1;
  691. month = 1;
  692. };
  693. var m = month
  694. if (m < 10) m = '0' + m
  695. var d = day
  696. if (d < 10) d = '0' + d
  697. return y + '-' + m + '-' + d
  698. },
  699. delUserShift(e) {
  700. this.vs = true;
  701. deleteAction(this.url.delUserShift, {
  702. id: e
  703. }).then((res) => {
  704. if (res.success) {
  705. this.$message.success(res.message);
  706. } else {
  707. this.$message.warning(res.message);
  708. }
  709. }).finally(() => {
  710. this.vs = false;
  711. this.getListData(moment(this.queryParam.entryDate).format('YYYY-MM-DD HH:mm:ss'));
  712. })
  713. },
  714. queryUserShifts() {
  715. this.queryParam.shiftDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
  716. this.$options.methods.searchQuery.call(this);
  717. },
  718. close() {
  719. this.selectedRowKeys = [];
  720. this.queryParam = {};
  721. this.shiftname = "";
  722. this.id = null;
  723. this.$emit('close');
  724. this.dataSource = [];
  725. this.visible = false;
  726. this.selectUsers = [];
  727. this.startDate = "";
  728. this.endDate = "";
  729. this.initData(null);
  730. },
  731. queryShift() {
  732. httpAction(this.url.shift, "", "get").then((res) => {
  733. if (res.success) {
  734. this.shiftlist = res.result;
  735. }
  736. }).finally(() => {
  737. })
  738. },
  739. handleCancel() {
  740. this.close()
  741. },
  742. save() {
  743. var userid = "";
  744. var startDate = "";
  745. var endDate = "";
  746. var workDay = "";
  747. var obj = "";
  748. var year = this.currentYear + "-" + this.currentMonth;
  749. if (this.types != '2' && this.types != 2) {
  750. if (this.selectUsers == [] || this.selectUsers.length < 1) {
  751. this.$message.warning('人员不能为空');
  752. return;
  753. } else if (this.types == '1' || this.types == 1) {
  754. if (this.startDate == null || this.startDate == "") {
  755. this.$message.warning('请选择上班时间');
  756. return;
  757. } else if (this.endDate == null || this.endDate == "") {
  758. this.$message.warning('请选择下班时间');
  759. return;
  760. }
  761. startDate = moment(this.startDate).format('YYYY-MM-DD HH:mm') + ":00";
  762. endDate = moment(this.endDate).format('YYYY-MM-DD HH:mm') + ":00";
  763. }
  764. var ids = [];
  765. for (var i = 0; i < this.selectUsers.length; i++) {
  766. ids.push(this.selectUsers[i].id);
  767. }
  768. userid = ids.join(',');
  769. workDay = "1,2,3,4,5";
  770. } else if (this.types == '2' || this.types == 2) {
  771. var data = [];
  772. var uids = [];
  773. userid = this.checkUserIds;
  774. for (var i = 0; i < this.dataSource.length; i++) {
  775. uids.push(this.dataSource[i].id);
  776. if (this.dataSource[i].shiftid1 != "" && this.dataSource[i].shiftid1 != null) {
  777. var str = {
  778. userid: this.dataSource[i].id,
  779. shiftid: this.dataSource[i].shiftid1,
  780. date: year + "-1 00:00:00"
  781. };
  782. data.push(str)
  783. }
  784. if (this.dataSource[i].shiftid2 != "" && this.dataSource[i].shiftid2 != null) {
  785. var str = {
  786. userid: this.dataSource[i].id,
  787. shiftid: this.dataSource[i].shiftid2,
  788. date: year + "-2 00:00:00"
  789. };
  790. data.push(str)
  791. }
  792. if (this.dataSource[i].shiftid3 != "" && this.dataSource[i].shiftid3 != null) {
  793. var str = {
  794. userid: this.dataSource[i].id,
  795. shiftid: this.dataSource[i].shiftid3,
  796. date: year + "-3 00:00:00",
  797. };
  798. data.push(str)
  799. }
  800. if (this.dataSource[i].shiftid4 != "" && this.dataSource[i].shiftid4 != null) {
  801. var str = {
  802. userid: this.dataSource[i].id,
  803. shiftid: this.dataSource[i].shiftid4,
  804. date: year + "-4 00:00:00"
  805. };
  806. data.push(str)
  807. }
  808. if (this.dataSource[i].shiftid5 != "" && this.dataSource[i].shiftid5 != null) {
  809. var str = {
  810. userid: this.dataSource[i].id,
  811. shiftid: this.dataSource[i].shiftid5,
  812. date: year + "-5 00:00:00",
  813. };
  814. data.push(str)
  815. }
  816. if (this.dataSource[i].shiftid6 != "" && this.dataSource[i].shiftid6 != null) {
  817. var str = {
  818. userid: this.dataSource[i].id,
  819. shiftid: this.dataSource[i].shiftid6,
  820. date: year + "-6 00:00:00",
  821. };
  822. data.push(str)
  823. }
  824. if (this.dataSource[i].shiftid7 != "" && this.dataSource[i].shiftid7 != null) {
  825. var str = {
  826. userid: this.dataSource[i].id,
  827. shiftid: this.dataSource[i].shiftid7,
  828. date: year + "-7 00:00:00"
  829. };
  830. data.push(str)
  831. }
  832. if (this.dataSource[i].shiftid8 != "" && this.dataSource[i].shiftid8 != null) {
  833. var str = {
  834. userid: this.dataSource[i].id,
  835. shiftid: this.dataSource[i].shiftid8,
  836. date: year + "-8 00:00:00"
  837. };
  838. data.push(str)
  839. }
  840. if (this.dataSource[i].shiftid9 != "" && this.dataSource[i].shiftid9 != null) {
  841. var str = {
  842. userid: this.dataSource[i].id,
  843. shiftid: this.dataSource[i].shiftid9,
  844. date: year + "-9 00:00:00"
  845. };
  846. data.push(str)
  847. }
  848. if (this.dataSource[i].shiftid10 != "" && this.dataSource[i].shiftid10 != null) {
  849. var str = {
  850. userid: this.dataSource[i].id,
  851. shiftid: this.dataSource[i].shiftid10,
  852. date: year + "-10 00:00:00"
  853. };
  854. data.push(str)
  855. }
  856. if (this.dataSource[i].shiftid11 != "" && this.dataSource[i].shiftid11 != null) {
  857. var str = {
  858. userid: this.dataSource[i].id,
  859. shiftid: this.dataSource[i].shiftid11,
  860. date: year + "-11 00:00:00"
  861. };
  862. data.push(str)
  863. }
  864. if (this.dataSource[i].shiftid12 != "" && this.dataSource[i].shiftid12 != null) {
  865. var str = {
  866. userid: this.dataSource[i].id,
  867. shiftid: this.dataSource[i].shiftid12,
  868. date: year + "-12 00:00:00"
  869. };
  870. data.push(str)
  871. }
  872. if (this.dataSource[i].shiftid13 != "" && this.dataSource[i].shiftid13 != null) {
  873. var str = {
  874. userid: this.dataSource[i].id,
  875. shiftid: this.dataSource[i].shiftid13,
  876. date: year + "-13 00:00:00"
  877. };
  878. data.push(str)
  879. }
  880. if (this.dataSource[i].shiftid14 != "" && this.dataSource[i].shiftid14 != null) {
  881. var str = {
  882. userid: this.dataSource[i].id,
  883. shiftid: this.dataSource[i].shiftid14,
  884. date: year + "-14 00:00:00"
  885. };
  886. data.push(str)
  887. }
  888. if (this.dataSource[i].shiftid15 != "" && this.dataSource[i].shiftid15 != null) {
  889. var str = {
  890. userid: this.dataSource[i].id,
  891. shiftid: this.dataSource[i].shiftid15,
  892. date: year + "-15 00:00:00"
  893. };
  894. data.push(str)
  895. }
  896. if (this.dataSource[i].shiftid16 != "" && this.dataSource[i].shiftid16 != null) {
  897. var str = {
  898. userid: this.dataSource[i].id,
  899. shiftid: this.dataSource[i].shiftid16,
  900. date: year + "-16 00:00:00"
  901. };
  902. data.push(str)
  903. }
  904. if (this.dataSource[i].shiftid17 != "" && this.dataSource[i].shiftid17 != null) {
  905. var str = {
  906. userid: this.dataSource[i].id,
  907. shiftid: this.dataSource[i].shiftid17,
  908. date: year + "-17 00:00:00"
  909. };
  910. data.push(str)
  911. }
  912. if (this.dataSource[i].shiftid18 != "" && this.dataSource[i].shiftid18 != null) {
  913. var str = {
  914. userid: this.dataSource[i].id,
  915. shiftid: this.dataSource[i].shiftid18,
  916. date: year + "-18 00:00:00"
  917. };
  918. data.push(str)
  919. }
  920. if (this.dataSource[i].shiftid19 != "" && this.dataSource[i].shiftid19 != null) {
  921. var str = {
  922. userid: this.dataSource[i].id,
  923. shiftid: this.dataSource[i].shiftid19,
  924. date: year + "-19 00:00:00"
  925. };
  926. data.push(str)
  927. }
  928. if (this.dataSource[i].shiftid20 != "" && this.dataSource[i].shiftid20 != null) {
  929. var str = {
  930. userid: this.dataSource[i].id,
  931. shiftid: this.dataSource[i].shiftid20,
  932. date: year + "-20 00:00:00"
  933. };
  934. data.push(str)
  935. }
  936. if (this.dataSource[i].shiftid21 != "" && this.dataSource[i].shiftid21 != null) {
  937. var str = {
  938. userid: this.dataSource[i].id,
  939. shiftid: this.dataSource[i].shiftid21,
  940. date: year + "-21 00:00:00"
  941. };
  942. data.push(str)
  943. }
  944. if (this.dataSource[i].shiftid22 != "" && this.dataSource[i].shiftid22 != null) {
  945. var str = {
  946. userid: this.dataSource[i].id,
  947. shiftid: this.dataSource[i].shiftid22,
  948. date: year + "-22 00:00:00"
  949. };
  950. data.push(str)
  951. }
  952. if (this.dataSource[i].shiftid23 != "" && this.dataSource[i].shiftid23 != null) {
  953. var str = {
  954. userid: this.dataSource[i].id,
  955. shiftid: this.dataSource[i].shiftid23,
  956. date: year + "-23 00:00:00"
  957. };
  958. data.push(str)
  959. }
  960. if (this.dataSource[i].shiftid24 != "" && this.dataSource[i].shiftid24 != null) {
  961. var str = {
  962. userid: this.dataSource[i].id,
  963. shiftid: this.dataSource[i].shiftid24,
  964. date: year + "-24 00:00:00"
  965. };
  966. data.push(str)
  967. }
  968. if (this.dataSource[i].shiftid25 != "" && this.dataSource[i].shiftid25 != null) {
  969. var str = {
  970. userid: this.dataSource[i].id,
  971. shiftid: this.dataSource[i].shiftid25,
  972. date: year + "-25 00:00:00"
  973. };
  974. data.push(str)
  975. }
  976. if (this.dataSource[i].shiftid26 != "" && this.dataSource[i].shiftid26 != null) {
  977. var str = {
  978. userid: this.dataSource[i].id,
  979. shiftid: this.dataSource[i].shiftid26,
  980. date: year + "-26 00:00:00"
  981. };
  982. data.push(str)
  983. }
  984. if (this.dataSource[i].shiftid27 != "" && this.dataSource[i].shiftid27 != null) {
  985. var str = {
  986. userid: this.dataSource[i].id,
  987. shiftid: this.dataSource[i].shiftid27,
  988. date: year + "-27 00:00:00"
  989. };
  990. data.push(str)
  991. }
  992. if (this.dataSource[i].shiftid28 != "" && this.dataSource[i].shiftid28 != null) {
  993. var str = {
  994. userid: this.dataSource[i].id,
  995. shiftid: this.dataSource[i].shiftid28,
  996. date: year + "-28 00:00:00"
  997. };
  998. data.push(str)
  999. }
  1000. if (this.dataSource[i].shiftid29 != "" && this.dataSource[i].shiftid29 != null) {
  1001. var str = {
  1002. userid: this.dataSource[i].id,
  1003. shiftid: this.dataSource[i].shiftid29,
  1004. date: year + "-29 00:00:00"
  1005. };
  1006. data.push(str)
  1007. }
  1008. if (this.dataSource[i].shiftid30 != "" && this.dataSource[i].shiftid30 != null) {
  1009. var str = {
  1010. userid: this.dataSource[i].id,
  1011. shiftid: this.dataSource[i].shiftid30,
  1012. date: year + "-30 00:00:00"
  1013. };
  1014. data.push(str)
  1015. }
  1016. if (this.dataSource[i].shiftid31 != "" && this.dataSource[i].shiftid31 != null) {
  1017. var str = {
  1018. userid: this.dataSource[i].id,
  1019. shiftid: this.dataSource[i].shiftid31,
  1020. date: year + "-31 00:00:00"
  1021. };
  1022. data.push(str)
  1023. }
  1024. }
  1025. obj = JSON.stringify(data);
  1026. userid = uids.join(",");
  1027. }
  1028. var url = this.url.add;
  1029. var typet = "post"
  1030. if (this.id != null && this.id != "") {
  1031. url = this.url.edit;
  1032. typet = "put";
  1033. }if(data!=null&&data.length>0){
  1034. this.confirmLoading = true;
  1035. httpAction(url, {
  1036. id: this.id,
  1037. type: this.types,
  1038. startDate: startDate,
  1039. endDate: endDate,
  1040. userId: userid,
  1041. workDay: workDay,
  1042. ruleType: obj
  1043. },
  1044. typet).then((res) => {
  1045. if (res.success) {
  1046. this.$message.success(res.message);
  1047. this.$emit('ok');
  1048. } else {
  1049. this.$message.warning(res.message);
  1050. }
  1051. }).finally(() => {
  1052. this.confirmLoading = false;
  1053. if(this.savef){
  1054. this.close();
  1055. }
  1056. this.savef=true;
  1057. })
  1058. }if(this.savef){
  1059. this.close();
  1060. }
  1061. },
  1062. add(e, a) {
  1063. this.visible = true;
  1064. this.queryParam.usertid = e.join(",");
  1065. this.checkUserIds = e.join(",");
  1066. this.selectUsers = a;
  1067. this.queryParam.shiftDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
  1068. this.queryParam.type = "1";
  1069. this.$options.methods.searchQuery.call(this)
  1070. },
  1071. edit(e, a) {
  1072. this.visible = true;
  1073. this.queryParam.usertid = e.join(",");
  1074. this.checkUserIds = e.join(",");
  1075. this.selectUsers = a;
  1076. this.types = a[0].type;
  1077. this.id = a[0].id;
  1078. this.queryParam.shiftDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
  1079. this.queryParam.type = "2";
  1080. if (a[0].startDate != null) {
  1081. this.startDate = moment(new Date(a[0].startDate)).format('YYYY-MM-DD HH:mm:ss');
  1082. }
  1083. if (a[0].endDate != null) {
  1084. this.endDate = moment(new Date(a[0].endDate)).format('YYYY-MM-DD HH:mm:ss');
  1085. }
  1086. this.$options.methods.searchQuery.call(this)
  1087. }
  1088. }
  1089. }
  1090. </script>
  1091. <style lang="less" scoped>
  1092. .month {
  1093. width: 100%;
  1094. color: #333333;
  1095. background: #ffffff;
  1096. margin-top: -20px;
  1097. }
  1098. .month ul {
  1099. margin: 0;
  1100. padding: 0;
  1101. display: flex;
  1102. justify-content: space-between;
  1103. height: 30px;
  1104. list-style-type: none;
  1105. }
  1106. .year-month {
  1107. display: flex;
  1108. align-items: center;
  1109. justify-content: space-around;
  1110. margin-top: 10px;
  1111. }
  1112. .choose-month {
  1113. text-align: center;
  1114. font-size: 12px;
  1115. }
  1116. .arrow {
  1117. padding: 15px;
  1118. color: #999999;
  1119. }
  1120. .month ul li {
  1121. font-size: 12px;
  1122. text-transform: uppercase;
  1123. letter-spacing: 3px;
  1124. }
  1125. .weekdays {
  1126. margin: 0;
  1127. padding: 10px;
  1128. display: flex;
  1129. flex-wrap: wrap;
  1130. color: #999;
  1131. justify-content: space-around;
  1132. background: #ffffff;
  1133. }
  1134. .weekdays li {
  1135. display: inline-block;
  1136. width: 13.6%;
  1137. text-align: center;
  1138. }
  1139. .days {
  1140. padding: 10px;
  1141. background: #ffffff;
  1142. margin: 0;
  1143. display: flex;
  1144. flex-wrap: wrap;
  1145. }
  1146. .ts {
  1147. padding: 20px;
  1148. background: #ffffff;
  1149. margin: 0;
  1150. display: flex;
  1151. flex-wrap: wrap;
  1152. }
  1153. .days li {
  1154. list-style-type: none;
  1155. display: inline-block;
  1156. width: 14.2%;
  1157. text-align: center;
  1158. padding-bottom: 4px;
  1159. padding-top: 5px;
  1160. font-size: 13px;
  1161. color: #000;
  1162. height: 40px;
  1163. }
  1164. .days li .active {
  1165. padding: 8px 10px;
  1166. border-radius: 5%;
  1167. background: #00b8ec;
  1168. color: #fff;
  1169. }
  1170. .days li .other-month {
  1171. padding: 5px;
  1172. color: gainsboro;
  1173. }
  1174. .days li:hover .act {
  1175. padding: 6px 10px;
  1176. border-radius: 50%;
  1177. background: #e1e1e1;
  1178. color: #fff;
  1179. }
  1180. </style>