attendance_rating.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. export default {
  153. data() {
  154. return {
  155. // 设置只能选择当前日期及之后的日期
  156. pickerOptions: {
  157. disabledDate(time) {
  158. return time.getTime() > Date.now() - 8.64e7;//如果没有后面的-8.64e7就是不可以选择今天的
  159. }
  160. },
  161. exportLoad: false,
  162. dialogVisible: false,
  163. checkingInGroup: [],
  164. event_type: [
  165. { id: 0, name: '总分' },
  166. { id: 1, name: '迟到' },
  167. { id: 2, name: '早退' },
  168. { id: 6, name: '准时打卡' },
  169. { id: 20, name: '上班缺卡' },
  170. { id: 21, name: '下班缺卡' },
  171. { id: 16, name: '加班 ' },
  172. { id: 10, name: '缺勤' }
  173. ],
  174. attendload: false,
  175. loading: false,
  176. all_integral_list: null,
  177. Month_range: this.$moment().format('YYYY-MM'),
  178. time_range: [
  179. this.$moment()
  180. .startOf('month')
  181. .format('YYYY-MM-DD'),
  182. this.$moment()
  183. .endOf('month')
  184. .format('YYYY-MM-DD')
  185. ],
  186. formData: {
  187. group_id: '',
  188. // date_type: 3,
  189. page: 1,
  190. page_size: 10,
  191. event_type: 0
  192. },
  193. exportMonth_range: this.$moment().format('YYYY-MM'),
  194. exportTime_range: [
  195. this.$moment()
  196. .startOf('month')
  197. .format('YYYY-MM-DD'),
  198. this.$moment()
  199. .endOf('month')
  200. .format('YYYY-MM-DD')
  201. ],
  202. exportData: {
  203. group_id: '',
  204. event_type: 0
  205. },
  206. total: 0,
  207. dept_tree: [],
  208. dept_name: [],
  209. pageLimit1: 10,
  210. instantPickerOptions: {
  211. shortcuts: [
  212. {
  213. text: '本周',
  214. onClick(picker) {
  215. const now = new Date();
  216. const start = new Date();
  217. start.setTime(now.getTime() - (now.getDay() - 1) * 24 * 60 * 60 * 1000);
  218. now.setTime(start.getTime() + 6 * 24 * 60 * 60 * 1000 - 1000);
  219. picker.$emit('pick', [start, now]);
  220. }
  221. },
  222. {
  223. text: '上周',
  224. onClick(picker) {
  225. const end = new Date();
  226. const start = new Date();
  227. start.setTime(start.getTime() - (start.getDay() + 6) * 3600 * 1000 * 24);
  228. end.setTime(start.getTime() + 6 * 24 * 60 * 60 * 1000 - 1000);
  229. picker.$emit('pick', [start, end]);
  230. }
  231. },
  232. {
  233. text: '本月',
  234. onClick(picker) {
  235. const now = new Date();
  236. const startDate = new Date(now.getFullYear(), now.getMonth(), 1);
  237. const endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0);
  238. picker.$emit('pick', [startDate, endDate]);
  239. }
  240. },
  241. {
  242. text: '上月',
  243. onClick(picker) {
  244. const now = new Date();
  245. const startDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() + 11) % 12, 1);
  246. const endDate = new Date(now.getFullYear(), now.getMonth(), 0);
  247. picker.$emit('pick', [startDate, endDate]);
  248. }
  249. }
  250. ]
  251. },
  252. // 更新考勤数据
  253. isUpdate:false,
  254. update:{
  255. type:'daily',
  256. target_date:this.$moment().subtract(1, "days").format("YYYY-MM-DD"),
  257. target_month:this.$moment().format("YYYY-MM"),
  258. }
  259. };
  260. },
  261. watch:{
  262. isUpdate(val){
  263. if(!val){
  264. this.update={
  265. type:'daily',
  266. target_date:this.$moment().subtract(1, "days").format("YYYY-MM-DD"),
  267. target_month:this.$moment().format("YYYY-MM"),
  268. }
  269. }
  270. }
  271. },
  272. mounted() {
  273. this.checkingIn_group(); //考勤组
  274. },
  275. methods: {
  276. saveUpdate(){
  277. let update=this.update
  278. let data={type:update.type};
  279. if(update.type=='daily'){
  280. if(!update.target_date){
  281. this.$message.error('请选择日期');
  282. return false
  283. }
  284. data.target_date=update.target_date
  285. }else{
  286. if(!update.target_month){
  287. this.$message.error('请选择月份');
  288. return false
  289. }
  290. data.target_month=update.target_month
  291. }
  292. this.$axios('post','/api/ding/ad_sync',data).then(res => {
  293. if (res.data.code == 1) {
  294. this.$message.success('已更新');
  295. this.isUpdate=false;
  296. }
  297. })
  298. },
  299. exportRanking() {
  300. if (this.checkingInGroup.length > 0) {
  301. this.exportData.group_id = this.checkingInGroup[0].id;
  302. }
  303. this.dialogVisible = true;
  304. },
  305. exportExcel() {
  306. window.open(
  307. process.env.VUE_APP_BASE_API +
  308. 'api/download/groups_ranking/export?start_date=' +
  309. this.exportTime_range[0] +
  310. '&end_date=' +
  311. this.exportTime_range[1] +
  312. '&page=' +
  313. 1 +
  314. '&page_size=' +
  315. 2000 +
  316. '&group_id=' +
  317. this.exportData.group_id +
  318. '&event_type=' +
  319. this.exportData.event_type +
  320. '&employee_id=' +
  321. this.$getUserData().id,
  322. '_blank'
  323. );
  324. },
  325. selectgroupId() {
  326. this.get_all_integral();
  327. },
  328. onFilterChanged() {
  329. this.get_all_integral();
  330. },
  331. //分页
  332. handleSizeChange1(val) {
  333. this.pageLimit1 = val;
  334. this.formData.page_size = this.pageLimit1;
  335. this.get_all_integral();
  336. },
  337. handleCurrentChange(val) {
  338. this.formData.page = val;
  339. this.get_all_integral();
  340. },
  341. //请求数据
  342. checkingIn_group() {
  343. this.attendload = true;
  344. let self = this;
  345. let params = {
  346. page: 1,
  347. page_size: 2000
  348. };
  349. this.$axios('get', '/api/ad/groups', params)
  350. .then(res => {
  351. if (res.data.code == 1) {
  352. let list = res.data.data.list;
  353. let datas = [];
  354. for (let key in list) {
  355. let obj = {};
  356. obj.id = key;
  357. obj.name = list[key];
  358. datas.push(obj);
  359. }
  360. this.checkingInGroup = datas;
  361. if(datas.length>0){
  362. this.formData.group_id = datas[0].id;
  363. }
  364. }
  365. })
  366. .finally(() => {
  367. this.get_all_integral();
  368. this.attendload = false;
  369. });
  370. },
  371. //请求数据
  372. get_all_integral() {
  373. let self = this;
  374. self.loading = true;
  375. let data = {
  376. group_id: this.formData.group_id,
  377. page: this.formData.page,
  378. page_size: this.formData.page_size,
  379. event_type: this.formData.event_type
  380. };
  381. data.start_date = this.time_range[0];
  382. data.end_date = this.time_range[1];
  383. this.$axios('post', '/api/ad/rank', data)
  384. .then(res => {
  385. if (res.data.code == 1) {
  386. this.all_integral_list =this.$returnDeptName(res.data.data.list);
  387. this.total = res.data.data.total;
  388. } else {
  389. self.$message.error(res.data.data.msg);
  390. }
  391. })
  392. .finally(() => {
  393. self.loading = false;
  394. });
  395. }
  396. }
  397. };
  398. </script>
  399. <style scoped>
  400. .el-date-editor.el-input {
  401. width: auto;
  402. }
  403. .date-picker-width {
  404. width: 145px !important;
  405. }
  406. .search ::v-deep .el-input-group__append:active {
  407. background: #26a2ff;
  408. }
  409. .search ::v-deep .el-input-group__append:active .el-icon-search {
  410. color: #fff;
  411. }
  412. </style>
  413. <style lang="scss" scoped>
  414. ::v-deep .el-dialog__body {
  415. padding: 0px 20px 30px;
  416. }
  417. </style>