attendance_rating.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div>
  3. <div class="all" v-loading="attendload">
  4. <FormBox>
  5. <div class="form-item">
  6. <div class="form-label">时间范围</div>
  7. <div class="form-search">
  8. <el-date-picker
  9. style="width:290px"
  10. :clearable="false"
  11. v-model="time_range"
  12. type="daterange"
  13. size="medium"
  14. value-format="yyyy-MM-dd"
  15. range-separator="至"
  16. start-placeholder="开始日期"
  17. end-placeholder="结束日期"
  18. :picker-options="instantPickerOptions"
  19. @change="onFilterChanged"
  20. ></el-date-picker>
  21. </div>
  22. </div>
  23. <div class="form-item">
  24. <div class="form-label">考勤组</div>
  25. <div class="form-search">
  26. <el-select size="medium" v-model="formData.group_id" @change="selectgroupId" filterable :clearable="false" placeholder="请选择考勤组">
  27. <el-option v-for="item in checkingInGroup" :key="item.id" :label="item.name" :value="item.id"></el-option>
  28. </el-select>
  29. </div>
  30. </div>
  31. <div class="form-item">
  32. <div class="form-label">排名类型</div>
  33. <div class="form-search">
  34. <el-select size="medium" v-model="formData.event_type" @change="selectgroupId" placeholder="请选择">
  35. <el-option v-for="(item, index) in event_type" :key="index" :label="item.name" :value="item.id"></el-option>
  36. </el-select>
  37. </div>
  38. </div>
  39. </FormBox>
  40. <div style="margin: 10px 0;">
  41. <el-button type="primary" size="medium" plain @click="exportRanking">导出排名</el-button>
  42. <el-button type="primary" size="medium" plain @click="isUpdate=true">更新考勤数据</el-button>
  43. </div>
  44. <el-table :data="all_integral_list" style="width: 100%" v-loading="loading">
  45. <el-table-column label="名次" width="100" align="center">
  46. <template slot-scope="scope">
  47. <img v-if="scope.row.rank === 1" src="@/assets/image/statistics_NO1.png" alt />
  48. <img v-if="scope.row.rank === 2" src="@/assets/image/statistics_NO2.png" alt />
  49. <img v-if="scope.row.rank === 3" src="@/assets/image/statistics_NO3.png" alt />
  50. <span v-if="scope.row.rank > 3">{{ scope.row.rank }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="姓名" align="left">
  54. <template slot-scope="scope">
  55. <div style="display:flex;">
  56. <userImage :user_name="scope.row.name" :img_url="scope.row.img_url" width="50px" height="50px"></userImage>
  57. <span style="line-height: 50px; padding-left: 10px;">{{ scope.row.name }}</span>
  58. </div>
  59. </template>
  60. </el-table-column>
  61. <el-table-column show-overflow-tooltip label="部门" align="left" min-width="120px" prop="deptName"></el-table-column>
  62. <el-table-column prop="point" label="B分" align="left">
  63. <template slot-scope="scope">
  64. <b style="font-size:15px;color:#909399">{{ scope.row.point }}</b>
  65. </template>
  66. </el-table-column>
  67. <template slot="empty">
  68. <noData :content="checkingInGroup.length == 0 ? '请先开启钉钉考勤' : '暂无数据'"></noData>
  69. </template>
  70. </el-table>
  71. <center style="padding: 20px 0;">
  72. <el-pagination
  73. background
  74. @size-change="handleSizeChange1"
  75. @current-change="handleCurrentChange"
  76. :current-page="formData.page"
  77. :page-sizes="[10, 20, 50, 100]"
  78. layout="total, sizes, prev, pager, next"
  79. :page-size="pageLimit1"
  80. :total="total"
  81. ></el-pagination>
  82. </center>
  83. </div>
  84. <!-- 更新考勤数据 -->
  85. <el-dialog title="更新考勤数据" :visible.sync="isUpdate" width="730px">
  86. <el-form>
  87. <el-form-item label="考勤组">
  88. <el-radio-group v-model="update.type">
  89. <el-radio label="daily">更新某一天的考勤数据</el-radio>
  90. <el-radio label="monthly">更新某个月的考勤数据</el-radio>
  91. </el-radio-group>
  92. </el-form-item>
  93. <el-form-item label="日" v-if="update.type=='daily'">
  94. <el-date-picker
  95. v-model="update.target_date"
  96. type="date"
  97. value-format="yyyy-MM-dd"
  98. :picker-options="pickerOptions"
  99. placeholder="选择日期">
  100. </el-date-picker>
  101. </el-form-item>
  102. <el-form-item label="月" v-else>
  103. <el-date-picker
  104. value-format="yyyy-MM"
  105. :picker-options="pickerOptions"
  106. v-model="update.target_month"
  107. type="month"
  108. placeholder="选择月">
  109. </el-date-picker>
  110. </el-form-item>
  111. </el-form>
  112. <span class="dialog-footer" style="display:flex;justify-content: flex-end;">
  113. <el-button @click="isUpdate = false">取 消</el-button>
  114. <el-button type="primary" @click="saveUpdate">确 定</el-button>
  115. </span>
  116. </el-dialog>
  117. <!-- 导出弹窗 -->
  118. <el-dialog title="导出排名" :visible.sync="dialogVisible" width="730px">
  119. <div style="font-size:15px;margin-bottom:10px;font-weight: 600;">系统将按以下已选条件导出对应的排名报表</div>
  120. <el-form :inline="true" label-width="70px">
  121. <el-form-item label="考勤组">
  122. <el-select v-model="exportData.group_id" @change="selectgroupId" filterable :clearable="false" placeholder="请选择考勤组">
  123. <el-option v-for="item in checkingInGroup" :key="item.id" :label="item.name" :value="item.id"></el-option>
  124. </el-select>
  125. </el-form-item>
  126. <el-form-item label="排名类型">
  127. <el-select v-model="exportData.event_type" style="width:150px" placeholder="请选择">
  128. <el-option v-for="(item, index) in event_type" :key="index" :label="item.name" :value="item.id"></el-option>
  129. </el-select>
  130. </el-form-item>
  131. <el-form-item label="时间">
  132. <el-date-picker
  133. :clearable="false"
  134. v-model="exportTime_range"
  135. type="daterange"
  136. value-format="yyyy-MM-dd"
  137. range-separator="至"
  138. start-placeholder="开始日期"
  139. end-placeholder="结束日期"
  140. :picker-options="instantPickerOptions"
  141. ></el-date-picker>
  142. </el-form-item>
  143. </el-form>
  144. <span slot="footer" class="dialog-footer">
  145. <el-button @click="dialogVisible = false" size="medium">取 消</el-button>
  146. <el-button type="primary" @click="exportExcel" size="medium">导 出</el-button>
  147. </span>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script>
  152. import moment from 'moment' // 时间库
  153. export default {
  154. data() {
  155. return {
  156. // 设置只能选择当前日期及之后的日期
  157. pickerOptions: {
  158. disabledDate(time) {
  159. return time.getTime() > Date.now() - 8.64e7;//如果没有后面的-8.64e7就是不可以选择今天的
  160. }
  161. },
  162. exportLoad: false,
  163. dialogVisible: false,
  164. checkingInGroup: [],
  165. event_type: [
  166. { id: 0, name: '总分' },
  167. { id: 1, name: '迟到' },
  168. { id: 23, name: '严重迟到' },
  169. { id: 27, name: '旷工迟到' },
  170. { id: 2, name: '早退' },
  171. { id: 6, name: '准时打卡' },
  172. { id: 20, name: '上班缺卡' },
  173. { id: 21, name: '下班缺卡' },
  174. { id: 16, name: '加班 ' },
  175. { id: 10, name: '缺勤' }
  176. ],
  177. attendload: false,
  178. loading: false,
  179. all_integral_list: null,
  180. Month_range: this.$moment().format('YYYY-MM'),
  181. time_range: [
  182. this.$moment()
  183. .startOf('month')
  184. .format('YYYY-MM-DD'),
  185. this.$moment()
  186. .endOf('month')
  187. .format('YYYY-MM-DD')
  188. ],
  189. formData: {
  190. group_id: '',
  191. // date_type: 3,
  192. page: 1,
  193. page_size: 10,
  194. event_type: 0
  195. },
  196. exportMonth_range: this.$moment().format('YYYY-MM'),
  197. exportTime_range: [
  198. this.$moment()
  199. .startOf('month')
  200. .format('YYYY-MM-DD'),
  201. this.$moment()
  202. .endOf('month')
  203. .format('YYYY-MM-DD')
  204. ],
  205. exportData: {
  206. group_id: '',
  207. event_type: 0
  208. },
  209. total: 0,
  210. dept_tree: [],
  211. dept_name: [],
  212. pageLimit1: 10,
  213. instantPickerOptions: {
  214. shortcuts: [
  215. {
  216. text: '本周',
  217. onClick(picker) {
  218. picker.$emit('pick', [moment().startOf('isoWeek').format('YYYY-MM-DD'),moment().endOf('isoWeek').format('YYYY-MM-DD')]);
  219. }
  220. },
  221. {
  222. text: '上周',
  223. onClick(picker) {
  224. const end = new Date();
  225. const start = new Date();
  226. start.setTime(start.getTime() - (start.getDay() + 6) * 3600 * 1000 * 24);
  227. end.setTime(start.getTime() + 6 * 24 * 60 * 60 * 1000 - 1000);
  228. picker.$emit('pick', [start, end]);
  229. }
  230. },
  231. {
  232. text: '本月',
  233. onClick(picker) {
  234. const now = new Date();
  235. const startDate = new Date(now.getFullYear(), now.getMonth(), 1);
  236. const endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0);
  237. picker.$emit('pick', [startDate, endDate]);
  238. }
  239. },
  240. {
  241. text: '上月',
  242. onClick(picker) {
  243. const now = new Date();
  244. const startDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() + 11) % 12, 1);
  245. const endDate = new Date(now.getFullYear(), now.getMonth(), 0);
  246. picker.$emit('pick', [startDate, endDate]);
  247. }
  248. }
  249. ]
  250. },
  251. // 更新考勤数据
  252. isUpdate:false,
  253. update:{
  254. type:'daily',
  255. target_date:this.$moment().subtract(1, "days").format("YYYY-MM-DD"),
  256. target_month:this.$moment().format("YYYY-MM"),
  257. }
  258. };
  259. },
  260. watch:{
  261. isUpdate(val){
  262. if(!val){
  263. this.update={
  264. type:'daily',
  265. target_date:this.$moment().subtract(1, "days").format("YYYY-MM-DD"),
  266. target_month:this.$moment().format("YYYY-MM"),
  267. }
  268. }
  269. }
  270. },
  271. mounted() {
  272. this.checkingIn_group(); //考勤组
  273. },
  274. methods: {
  275. saveUpdate(){
  276. let update=this.update
  277. let data={type:update.type};
  278. if(update.type=='daily'){
  279. if(!update.target_date){
  280. this.$message.error('请选择日期');
  281. return false
  282. }
  283. data.target_date=update.target_date
  284. }else{
  285. if(!update.target_month){
  286. this.$message.error('请选择月份');
  287. return false
  288. }
  289. data.target_month=update.target_month
  290. }
  291. this.$axios('post','/api/ding/ad_sync',data).then(res => {
  292. if (res.data.code == 1) {
  293. this.$message.success('已更新');
  294. this.isUpdate=false;
  295. }
  296. })
  297. },
  298. exportRanking() {
  299. if (this.checkingInGroup.length > 0) {
  300. this.exportData.group_id = this.checkingInGroup[0].id;
  301. }
  302. this.dialogVisible = true;
  303. },
  304. exportExcel() {
  305. window.open(
  306. process.env.VUE_APP_BASE_API +
  307. 'api/download/groups_ranking/export?start_date=' +
  308. this.exportTime_range[0] +
  309. '&end_date=' +
  310. this.exportTime_range[1] +
  311. '&page=' +
  312. 1 +
  313. '&page_size=' +
  314. 2000 +
  315. '&group_id=' +
  316. this.exportData.group_id +
  317. '&event_type=' +
  318. this.exportData.event_type +
  319. '&employee_id=' +
  320. this.$getUserData().id,
  321. '_blank'
  322. );
  323. },
  324. selectgroupId() {
  325. this.get_all_integral();
  326. },
  327. onFilterChanged() {
  328. this.get_all_integral();
  329. },
  330. //分页
  331. handleSizeChange1(val) {
  332. this.pageLimit1 = val;
  333. this.formData.page_size = this.pageLimit1;
  334. this.get_all_integral();
  335. },
  336. handleCurrentChange(val) {
  337. this.formData.page = val;
  338. this.get_all_integral();
  339. },
  340. //请求数据
  341. checkingIn_group() {
  342. this.attendload = true;
  343. let self = this;
  344. let params = {
  345. page: 1,
  346. page_size: 2000
  347. };
  348. this.$axios('get', '/api/ad/groups', params)
  349. .then(res => {
  350. if (res.data.code == 1) {
  351. let list = res.data.data.list;
  352. let datas = [];
  353. for (let key in list) {
  354. let obj = {};
  355. obj.id = key;
  356. obj.name = list[key];
  357. datas.push(obj);
  358. }
  359. this.checkingInGroup = datas;
  360. if(datas.length>0){
  361. this.formData.group_id = datas[0].id;
  362. }
  363. }
  364. })
  365. .finally(() => {
  366. this.get_all_integral();
  367. this.attendload = false;
  368. });
  369. },
  370. //请求数据
  371. get_all_integral() {
  372. let self = this;
  373. self.loading = true;
  374. let data = {
  375. group_id: this.formData.group_id,
  376. page: this.formData.page,
  377. page_size: this.formData.page_size,
  378. event_type: this.formData.event_type
  379. };
  380. data.start_date = this.time_range[0];
  381. data.end_date = this.time_range[1];
  382. this.$axios('post', '/api/ad/rank', data)
  383. .then(res => {
  384. if (res.data.code == 1) {
  385. this.all_integral_list =this.$returnDeptName(res.data.data.list);
  386. this.total = res.data.data.total;
  387. } else {
  388. self.$message.error(res.data.data.msg);
  389. }
  390. })
  391. .finally(() => {
  392. self.loading = false;
  393. });
  394. }
  395. }
  396. };
  397. </script>
  398. <style scoped>
  399. .el-date-editor.el-input {
  400. width: auto;
  401. }
  402. .date-picker-width {
  403. width: 145px !important;
  404. }
  405. .search ::v-deep .el-input-group__append:active {
  406. background: #26a2ff;
  407. }
  408. .search ::v-deep .el-input-group__append:active .el-icon-search {
  409. color: #fff;
  410. }
  411. </style>
  412. <style lang="scss" scoped>
  413. ::v-deep .el-dialog__body {
  414. padding: 0px 20px 30px;
  415. }
  416. </style>