attendance_rating.vue 12 KB

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