0
0

add.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <div class="row">
  4. <div class="col-sm-12">
  5. <div class="ibox float-e-margins">
  6. <!--<div class="ibox-title">-->
  7. <!--<h5>{$title}</h5>-->
  8. <!--<div class="ibox-tools">-->
  9. <!--<a class="toback" href="{:url('index')}">-->
  10. <!--返回上一页-->
  11. <!--</a>-->
  12. <!--</div>-->
  13. <!--</div>-->
  14. <div class="ibox-content">
  15. <div id="vueapp">
  16. <div style="overflow: auto;padding: 15px 20px;">
  17. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  18. <el-form-item label="名称" prop="name">
  19. <el-input v-model="form.name" maxlength="50" show-word-limit placeholder="请输入" />
  20. </el-form-item>
  21. <el-form-item label="参与考勤人员" prop="selectUser">
  22. <el-select
  23. v-model="selectUser"
  24. placeholder="请选择"
  25. multiple
  26. collapse-tags
  27. filterable
  28. >
  29. <el-option
  30. v-for="item in users"
  31. :key="item.id"
  32. :label="item.real_name"
  33. :value="item.id">
  34. </el-option>
  35. <!-- <el-option-group-->
  36. <!-- v-for="group in users"-->
  37. <!-- :key="group.name"-->
  38. <!-- :label="group.name"-->
  39. <!-- >-->
  40. <!-- <el-option-->
  41. <!-- v-for="item in group.sub"-->
  42. <!-- :key="item.USER_ID"-->
  43. <!-- :label="item.REAL_NAME"-->
  44. <!-- :value="item.USER_ID">-->
  45. <!-- </el-option>-->
  46. <!-- </el-option-group>-->
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item label="类型" prop="type">
  50. <el-radio v-if="info" v-model="form.type" disabled label="1">
  51. 固定班制
  52. </el-radio>
  53. <el-radio v-if="info" v-model="form.type" disabled label="2">
  54. 排班制
  55. </el-radio>
  56. <el-radio v-if="!info" v-model="form.type" label="1">
  57. 固定班制
  58. </el-radio>
  59. <el-radio v-if="!info" v-model="form.type" label="2">
  60. 排班制
  61. </el-radio>
  62. </el-form-item>
  63. <el-form-item v-if="Number(form.type) === 2" label="考勤班次">
  64. <el-select
  65. v-if="classload"
  66. v-model="checkClass"
  67. multiple
  68. placeholder="请选择"
  69. style="width:100%;"
  70. @change="changePbClass"
  71. >
  72. <el-option
  73. v-for="item in classes"
  74. :key="item.id"
  75. :label="item.name"
  76. :value="item.id.toString()"
  77. />
  78. </el-select>
  79. </el-form-item>
  80. <el-form-item v-if="Number(form.type) === 2 && checkClass.length" label="排班周期">
  81. <table border="0" style="width:100%;">
  82. <tr>
  83. <th>周期名称</th>
  84. <th>周期天数</th>
  85. <th>操作</th>
  86. </tr>
  87. <tr v-for="item in [circle]">
  88. <td>{{item.title}}</td>
  89. <td>{{item.days}}</td>
  90. <td>
  91. <el-link type="primary" :underline="false" @click="setCircle()">
  92. 设置排班周期
  93. </el-link>
  94. </td>
  95. </tr>
  96. </table>
  97. </el-form-item>
  98. <el-form-item v-if="Number(form.type) === 1" label="工作日设置">
  99. <table border="0" style="width:100%;text-align: center;">
  100. <tr>
  101. <th style="width:120px">工作日</th>
  102. <th>班次时间段</th>
  103. </tr>
  104. <tr v-for="item in tableData">
  105. <td>{{item.text}}</td>
  106. <td>
  107. <el-select v-if="classload" v-model="item.class_id" size="small" clearable placeholder="请选择" style="width:100%">
  108. <el-option
  109. v-for="item in classes"
  110. :key="item.id"
  111. :label="item.name"
  112. :value="item.id"
  113. />
  114. </el-select>
  115. </td>
  116. </tr>
  117. </table>
  118. </el-form-item>
  119. <el-form-item v-if="Number(form.type) === 1" label="特殊日期" >
  120. <div>
  121. <el-button size="small" @click="handleClass(1,null)">
  122. 添加
  123. </el-button> <span> 必须打卡的日期</span>
  124. </div>
  125. <table v-if="signTable.length > 0" border="0" style="width:100%;">
  126. <tr>
  127. <th>日期</th>
  128. <th>考勤时间</th>
  129. <th>操作</th>
  130. </tr>
  131. <tr v-for="item in signTable" >
  132. <td>{{item.day}}</td>
  133. <td>
  134. {{item.class_name}}
  135. </td>
  136. <td>
  137. <el-link type="primary" :underline="false" @click="handleClass(1, item)">
  138. 编辑
  139. </el-link>
  140. <el-link type="danger" :underline="false" @click="delClass(1,item)">
  141. 删除
  142. </el-link>
  143. </td>
  144. </tr>
  145. </table>
  146. <div>
  147. <el-button size="small" @click="handleClass(2,null)">
  148. 添加
  149. </el-button> <span> 不用打卡的日期</span>
  150. </div>
  151. <table v-if="unsignTable.length > 0" border="0" style="width:100%;">
  152. <tr>
  153. <th>日期</th>
  154. <th>考勤时间</th>
  155. <th>操作</th>
  156. </tr>
  157. <tr v-for="item in unsignTable">
  158. <td>{{item.day}}</td>
  159. <td>
  160. 休息
  161. </td>
  162. <td>
  163. <el-link type="danger" :underline="false" @click="changeClass(item)">
  164. 删除
  165. </el-link>
  166. </td>
  167. </tr>
  168. </table>
  169. </el-form-item>
  170. <el-form-item label="考勤方式">
  171. <el-checkbox-group v-model="checkWay">
  172. <el-checkbox label="1" >
  173. 地点打卡
  174. </el-checkbox>
  175. <el-checkbox label="2">
  176. 考勤机打卡
  177. </el-checkbox>
  178. </el-checkbox-group>
  179. <!-- <span class="text-danger">物业人员仅支持考勤机打卡</span>-->
  180. </el-form-item>
  181. <el-form-item label="考勤地点">
  182. <el-select
  183. v-if="addrload"
  184. v-model="checkAddr"
  185. multiple
  186. collapse-tags
  187. placeholder="请选择"
  188. >
  189. <el-option
  190. v-for="item in addr"
  191. :key="item.id"
  192. :label="item.title"
  193. :value="item.id.toString()"
  194. />
  195. </el-select>
  196. </el-form-item>
  197. <el-form-item>
  198. <el-button type="primary" :loading="flag" @click="submitbtn('form')">
  199. 确定
  200. </el-button>
  201. </el-form-item>
  202. </el-form>
  203. </div>
  204. <el-dialog
  205. v-if="classVisible"
  206. :title="title1"
  207. :visible.sync="classVisible"
  208. width="600px"
  209. @close="handleCancelModal"
  210. >
  211. <el-form ref="classForm" :model="classForm" :rules="rules" label-position="right" label-width="120px">
  212. <el-form-item label="日期">
  213. <el-date-picker
  214. v-model="classForm.day"
  215. type="date"
  216. placeholder="请选择日期"
  217. :editable="false"
  218. value-format="yyyy-MM-dd"
  219. :clearable="true"
  220. @change="changeDate(classForm.type,classForm.edit)"
  221. />
  222. <div class="text-danger">
  223. {{ errormsg }}
  224. </div>
  225. </el-form-item>
  226. <el-form-item v-if="classForm.type === 1" label="考勤班次">
  227. <el-select v-if="classload" v-model="classForm.class_id" clearable placeholder="请选择">
  228. <el-option
  229. v-for="item in classes"
  230. :key="item.id"
  231. :label="item.name"
  232. :value="item.id"
  233. />
  234. </el-select>
  235. </el-form-item>
  236. <!-- <span slot="footer" class="dialog-footer">-->
  237. <el-button type="primary" style="margin-left: 200px" @click="handleClassForm('classForm')">确 定</el-button>
  238. </span>
  239. </el-form>
  240. </el-dialog>
  241. <el-dialog
  242. v-if="circleVisible"
  243. title="设置排班周期"
  244. :visible.sync="circleVisible"
  245. width="600px"
  246. @close="handleCancelModal2"
  247. >
  248. <el-form v-if="circle" ref="circleForm" :model="circle" :rules="rules" label-position="right" label-width="120px">
  249. <el-form-item label="周期名称">
  250. <el-input v-model="circle.title" maxlength="10" show-word-limit placeholder="请输入名称" />
  251. </el-form-item>
  252. <el-form-item label="周期天数">
  253. <el-input-number v-model="circle.days" :min="2" :max="31" :step="1" @change="changeDays" />
  254. </el-form-item>
  255. <el-form-item v-if="circle.class.length > 0" label="周期排班">
  256. <div v-for="item in circle.class" :key="item.id">
  257. <span>第{{ item.id }}天: </span>
  258. <span v-if="selectClasses.length > 0">
  259. <el-select v-model="item.class_id" size="small" clearable placeholder="请选择(不选即为休息)">
  260. <el-option
  261. v-for="item2 in selectClasses"
  262. :key="item2.id"
  263. :label="item2.name"
  264. :value="item2.id"
  265. />
  266. </el-select>
  267. </span>
  268. </div>
  269. </el-form-item>
  270. </el-form>
  271. <span slot="footer" class="dialog-footer">
  272. <el-button @click="handleCancelModal2">取 消</el-button>
  273. <el-button type="primary" @click="handleCircleForm('circleForm')">确 定</el-button>
  274. </span>
  275. </el-dialog>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. {/block}
  282. {block name="script"}
  283. <script>
  284. $(document).ready(function(){
  285. formSetValue("type", {$info.type|default=1});
  286. });
  287. </script>
  288. <script>
  289. var users = <?=json_encode($users)?>;
  290. var classes = <?=json_encode($classes)?>;
  291. var addrs = <?=json_encode($addrs)?>;
  292. var info = <?=json_encode($info)?>;
  293. console.log(info);
  294. new Vue({
  295. el: '#vueapp',
  296. data: function() {
  297. return {
  298. form : {
  299. id: 0,
  300. name: '',
  301. type: '1',
  302. },
  303. rules : {
  304. name: [
  305. { required: true, message: '请输入名称', trigger: 'blur' },
  306. ],
  307. },
  308. selectUser: [],
  309. users: users, // 所有用户
  310. checkClass:[], // 选择的考勤班次
  311. classload:true,
  312. // info: null,
  313. info: info?info:null,
  314. flag: false,
  315. tableData:[
  316. {
  317. week: 1, text: '周一', class_id: '', class_name: '',
  318. },
  319. {
  320. week: 2, text: '周二', class_id: '', class_name: '',
  321. },
  322. {
  323. week: 3, text: '周三', class_id: '', class_name: '',
  324. },
  325. {
  326. week: 4, text: '周四', class_id: '', class_name: '',
  327. },
  328. {
  329. week: 5, text: '周五', class_id: '', class_name: '',
  330. },
  331. {
  332. week: 6, text: '周六', class_id: '', class_name: '',
  333. },
  334. {
  335. week: 0, text: '周日', class_id: '', class_name: '',
  336. },
  337. ],
  338. signTable : [],
  339. unsignTable : [],
  340. circle : {
  341. title: '',
  342. days: 0,
  343. class: [
  344. {
  345. id: 1,
  346. class_id: '',
  347. },
  348. {
  349. id: 2,
  350. class_id: '',
  351. },
  352. ],
  353. },
  354. checkWay:['1', '2'],
  355. circleVisible:false,
  356. selectClasses : [],
  357. checkAddr:[],
  358. addr:addrs,
  359. addrload:true,
  360. classes:classes,
  361. title1: '必须打卡日期',
  362. errormsg:'',
  363. classForm:{
  364. day: '',
  365. class_id: '',
  366. type: 1,
  367. edit: 0,
  368. },
  369. oldday : '', // 编辑用
  370. classVisible:false,
  371. dataload:true,
  372. }
  373. },
  374. watch: {
  375. },
  376. created(){
  377. if(info){
  378. this.form = {
  379. id: info.id,
  380. name: info.name,
  381. type: info.type.toString(),
  382. };
  383. this.selectUser = info.userIds;
  384. this.users = users; // 所有用户
  385. this.checkClass = info.class_id?info.class_id.split(','):[]; // 选择的考勤班次
  386. this.checkAddr = info.addr?info.addr.split(','):[];
  387. this.addr = addrs;
  388. this.classes = classes;
  389. const content = JSON.parse(this.info.content);
  390. const way = this.info.cate ? this.info.cate.split(',') : [];
  391. this.checkWay = way ;
  392. const classs = this.info.classId ? this.info.classId.split(',') : [];
  393. classs.forEach((item) => {
  394. this.checkClass.push(item.toString());
  395. });
  396. if (this.info.type === 1) {
  397. this.tableData = content.week;
  398. this.signTable = content.sign;
  399. this.unsignTable = content.unsign;
  400. } else {
  401. this.circle = content.circle;
  402. this.selectClasses = [];
  403. this.classes.forEach((item) => {
  404. if (this.checkClass.includes(item.id.toString())) {
  405. this.selectClasses.push(item);
  406. }
  407. });
  408. }
  409. }
  410. },
  411. methods: {
  412. changePbClass() {
  413. this.selectClasses = [];
  414. this.classes.forEach((item) => {
  415. if (this.checkClass.includes(item.id.toString())) {
  416. this.selectClasses.push(item);
  417. }
  418. });
  419. this.circle = {
  420. title: '',
  421. days: 2,
  422. class: [
  423. {
  424. id: 1,
  425. class_id: '',
  426. },
  427. {
  428. id: 2,
  429. class_id: '',
  430. },
  431. ],
  432. };
  433. },
  434. handleClass(type, obj) {
  435. this.oldday = '';
  436. if (obj) {
  437. this.classForm = {
  438. day: obj.day,
  439. class_id: obj.class_id,
  440. type,
  441. edit: 1,
  442. };
  443. this.oldday = obj.day;
  444. } else {
  445. this.classForm = {
  446. day: '',
  447. class_id: '',
  448. type,
  449. edit: 0,
  450. };
  451. }
  452. if (type === 1) {
  453. this.title1 = '必须打卡的日期';
  454. } else {
  455. this.title1 = '不用打卡的日期';
  456. }
  457. this.classVisible = true;
  458. },
  459. delClass(type,obj){
  460. if (type === 1) {
  461. this.signTable = this.signTable.filter(item => item.day !== obj.day);
  462. } else {
  463. this.unsignTable = this.unsignTable.filter(item => item.day !== obj.day);
  464. }
  465. },
  466. changeClass(obj){
  467. this.unsignTable = this.unsignTable.filter(item => item.day !== obj.day);
  468. },
  469. handleCancelModal() {
  470. this.classVisible = false;
  471. },
  472. handleClassForm(formName) { // eslint-disable-line
  473. console.log(formName, this.classForm);
  474. if (this.errormsg) {
  475. return false;
  476. }
  477. if (!this.classForm.day) {
  478. this.$message.error('未选择日期');
  479. return false;
  480. } if (this.classForm.type === 1 && !this.classForm.class_id) {
  481. this.$message.error('未选择班次');
  482. return false;
  483. }
  484. if (this.classForm.type === 1) {
  485. let ff = false;
  486. this.signTable.forEach((item) => {
  487. const info = item;
  488. if (item.day === this.oldday && this.classForm.edit) { // 编辑
  489. info.class_id = this.classForm.class_id;
  490. info.day = this.classForm.day;
  491. ff = true;
  492. }
  493. });
  494. if (!ff) {
  495. this.signTable.push({
  496. day: this.classForm.day,
  497. class_id: this.classForm.class_id,
  498. class_name: '',
  499. });
  500. }
  501. this.signTable.forEach((item) => {
  502. const info = item;
  503. this.classes.forEach((item2) => {
  504. if (item2.id === info.class_id) {
  505. info.class_name = item2.name;
  506. }
  507. });
  508. });
  509. const nsignTable = JSON.parse(JSON.stringify(this.signTable));
  510. this.signTable = [];
  511. this.signTable = JSON.parse(JSON.stringify(nsignTable));
  512. } else {
  513. this.unsignTable.push({
  514. day: this.classForm.day,
  515. });
  516. const nunsignTable = JSON.parse(JSON.stringify(this.unsignTable));
  517. this.unsignTable = [];
  518. this.unsignTable = JSON.parse(JSON.stringify(nunsignTable));
  519. }
  520. console.log(this.signTable, this.unsignTable);
  521. this.classVisible = false;
  522. },
  523. goBack() {
  524. this.$router.go(-1);
  525. },
  526. changeDate(type, edit) {
  527. this.errormsg = '';
  528. if (this.classForm.day) {
  529. if(edit === 1){ // eslint-disable-line
  530. if (type === 1) {
  531. this.unsignTable.forEach((item) => {
  532. if (item.day === this.classForm.day) {
  533. this.errormsg = '该日期已被指定为不需要打卡';
  534. }
  535. });
  536. } else {
  537. this.signTable.forEach((item) => {
  538. if (item.day === this.classForm.day) {
  539. this.errormsg = '该日期已被指定为必须打卡';
  540. }
  541. });
  542. }
  543. } else {
  544. this.signTable.forEach((item) => {if (item.day === this.classForm.day) {
  545. this.errormsg = '该日期已被指定为必须打卡';
  546. }
  547. });
  548. this.unsignTable.forEach((item) => {
  549. if (item.day === this.classForm.day) {
  550. this.errormsg = '该日期已被指定为不需要打卡';
  551. }
  552. });
  553. }
  554. } else {
  555. this.errormsg = '';
  556. }
  557. },
  558. setCircle() {
  559. console.log('sss',this.selectClasses,this.checkClass);
  560. this.circleVisible = true;
  561. },
  562. handleCircleForm() {
  563. this.circleVisible = false;
  564. },
  565. handleCancelModal2() {
  566. this.circleVisible = false;
  567. },
  568. changeDays() {
  569. console.log('circle', this.circle);
  570. const newclass = [];
  571. for(let i=1;i<=this.circle.days;i++){ // eslint-disable-line
  572. newclass.push({
  573. id: i,
  574. class_id: '',
  575. });
  576. }
  577. newclass.forEach((item) => {
  578. const info = item;
  579. this.circle.class.forEach((item2) => {
  580. if (item.id === item2.id) {
  581. info.class_id = item2.class_id;
  582. }
  583. });
  584. });
  585. this.circle.class = [];
  586. this.circle.class = JSON.parse(JSON.stringify(newclass));
  587. },
  588. submitbtn(formName){
  589. this.$refs[formName].validate((valid) => { // eslint-disable-line
  590. if (valid) {
  591. this.flag = true;
  592. let content = {};
  593. if (Number(this.form.type) === 1) {
  594. content = {
  595. week: this.tableData,
  596. sign: this.signTable,
  597. unsign: this.unsignTable,
  598. };
  599. } else {
  600. content = {
  601. circle: this.circle,
  602. };
  603. }
  604. let param = {
  605. id: this.form.id,
  606. name: this.form.name,
  607. type: this.form.type,
  608. cate: this.checkWay ? this.checkWay.join(',') : '',
  609. classId: this.checkClass.length > 0 ? this.checkClass.join(',') : '',
  610. addr: this.checkAddr.length > 0 ? this.checkAddr.join(',') : '',
  611. content: JSON.stringify(content),
  612. users: this.selectUser.join(','),
  613. };
  614. let that = this;
  615. $.ajax({
  616. url: 'add',
  617. type: 'POST',
  618. data: param,
  619. success: function(data){
  620. if(data.code == '1'){
  621. layer.msg('操作成功',{time:2000})
  622. parent.layer.closeAll();
  623. // window.location.href = "{:url('AttendanceGroup/index')}"
  624. // parent.window.location.reload();
  625. }else{
  626. layer.msg('操作失败')
  627. }
  628. that.flag = false;
  629. },
  630. error: function (){
  631. that.flag = false;
  632. }
  633. });
  634. }
  635. });
  636. }
  637. }
  638. })
  639. </script>
  640. {/block}