daily.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item>
  7. <el-date-picker v-model="date" :editable="false" format="yyyy-MM" value-format="yyyy-MM"
  8. @change="changeMonth()" :clearable="false" type="month" placeholder="选择月份"></el-date-picker>
  9. </el-form-item>
  10. <el-form-item style="float:right;">
  11. <el-link type="primary" :underline="false" v-if="user.role != 0" @click="exportReport">导出日报</el-link>
  12. </el-form-item>
  13. <el-form-item style="float:right;">
  14. <el-link type="primary" :underline="false" @click="fillInReport">填写日报</el-link>
  15. </el-form-item>
  16. </el-form>
  17. </el-col>
  18. <!--列表-->
  19. <div>
  20. <el-card class="box-card daily" shadow="never" :style="'height:'+tableHeight +'px'">
  21. <div slot="header" class="clearfix">
  22. <span>日期:</span>
  23. <span v-for="(item,index) in allDate" :id="'day'+index" :class="index==choseDay?'chooseDate date_item':'date_item'"
  24. @click="choseDate(index)" :key="index">{{item}}</span>
  25. </div>
  26. <div class="allDaily">
  27. <div class="one_daily" v-for="(item1,index1) in reportList" :key="index1">
  28. <i class="fa fa-circle"></i>{{item1.name}}
  29. <span style="margin-left:30px;">
  30. <span style="margin-right:20px;">
  31. <i v-if="parseFloat(item1.reportTime)>parseFloat(item1.calculateTime)+0.5" style="color:red;margin-right:8px;" class="fa fa-exclamation-triangle"></i>
  32. 总填报:
  33. <span :style="parseFloat(item1.reportTime)>parseFloat(item1.calculateTime)+0.5?'color:red':''">{{item1.reportTime}}h</span>
  34. </span>
  35. <span>系统智能统计:{{item1.calculateTime}}h</span>
  36. </span>
  37. <div class="one_daily_body">
  38. <el-timeline>
  39. <el-timeline-item v-for="(item2,index2) in item1.data" :key="index2">
  40. <el-card shadow="never">
  41. <p>项目:<b>{{item2.project}}</b></p>
  42. <p>时长:{{item2.time}}h</p>
  43. <p>事项:<span v-html="item2.content"></span></p>
  44. </el-card>
  45. </el-timeline-item>
  46. </el-timeline>
  47. </div>
  48. </div>
  49. <!-- 简陋的无报告提示 -->
  50. <span v-if="reportList.length==0">本日暂无报告</span>
  51. </div>
  52. </el-card>
  53. </div>
  54. <!-- 项目管理的dialog -->
  55. <el-dialog title="填写日报" :visible.sync="dialogVisible" width="60%">
  56. <el-form ref="workForm" :model="workForm" :rules="workRules" label-width="100px">
  57. <el-form-item label="工作日期" prop="createDate">
  58. <el-date-picker v-model="workForm.createDate" :editable="false" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  59. @change="changeMonth()" :clearable="false" type="date" placeholder="选择工作日期" style="width:100%;"></el-date-picker>
  60. </el-form-item>
  61. <el-form-item label="待分配时长" prop="name">
  62. <span>{{report.time}}h</span>
  63. <el-link type="primary" :underline="false" @click="addDomain" style="margin-left:40px">添加项目</el-link>
  64. </el-form-item>
  65. <div v-for="(domain, index) in workForm.domains" :key="domain.id">
  66. <el-form-item label="投入项目" :prop="'domains.' + index + '.projectId'"
  67. :rules="{ required: true, message: '请选择投入项目', trigger: ['change','blur'] }">
  68. <el-select v-model="domain.projectId" placeholder="请选择" style="width:200px;">
  69. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"></el-option>
  70. </el-select>
  71. <el-link v-if="index >= 1" type="primary" :underline="false" @click="delDomain(index)" style="float:right;margin-right:10px;">
  72. <i class="fa fa-trash" style="color: red;;font-size:18px;"></i>
  73. </el-link>
  74. </el-form-item>
  75. <el-form-item label="投入时长" :prop="'domains.' + index + '.workingTime'"
  76. :rules="{ required: true, message: '请输入投入时长', trigger: 'blur' }">
  77. <el-input v-model.number="domain.workingTime" placeholder="请输入投入时长" type='number' clearable style="width:200px;"></el-input>
  78. </el-form-item>
  79. <el-form-item label="工作事项" :prop="'domains.' + index + '.content'" :rules="{ required: true, message: '请输入工作事项', trigger: 'blur' }">
  80. <el-input v-model="domain.content" type="textarea" :rows="4" placeholder="请输入投入时长" clearable></el-input>
  81. </el-form-item>
  82. <el-divider v-if="workForm.domains.length>1"></el-divider>
  83. </div>
  84. </el-form>
  85. <span slot="footer" class="dialog-footer">
  86. <el-button @click="dialogVisible = false">取消</el-button>
  87. <el-button type="primary" @click="submitDepartment">提交</el-button>
  88. </span>
  89. </el-dialog>
  90. </section>
  91. </template>
  92. <script>
  93. import util from "../../common/js/util";
  94. export default {
  95. data() {
  96. return {
  97. user: JSON.parse(sessionStorage.getItem("user")),
  98. allDate: [],
  99. date: util.formatDate.format(new Date(new Date()), "yyyy-MM"),
  100. choseDay: 0,
  101. tableHeight: 0,
  102. listLoading: false,
  103. projectList: [], //项目列表
  104. reportList: [], //日报列表
  105. dialogVisible: false, //项目弹窗
  106. report: '',
  107. workForm: {
  108. createDate: util.formatDate.format(new Date(new Date()), "yyyy-MM-dd"),
  109. domains: [{
  110. id: null,
  111. projectId: "",
  112. workingTime: "",
  113. content: ""
  114. }],
  115. },
  116. workRules: {
  117. createDate: [{ required: true, message: "请选择工作日期", trigger: "change" }],
  118. }
  119. };
  120. },
  121. methods: {
  122. // 改变月份
  123. changeMonth() {
  124. this.getAllDate();
  125. this.getReportList();
  126. },
  127. // 选择日期
  128. choseDate(i) {
  129. this.choseDay = i;
  130. this.getReportList();
  131. },
  132. // 获取日期列表
  133. getAllDate() {
  134. var dayArry = [];
  135. var day = this.getCountDays();
  136. for (var k = 1; k <= day; k++) {
  137. var str = new Date(this.date.replace(/-/g, "/")).getMonth() + 1 + "月" + k + "日";
  138. if ( new Date(this.date.replace(/-/g, "/")).getFullYear() == new Date(new Date()).getFullYear() &&
  139. new Date(this.date.replace(/-/g, "/")).getMonth() == new Date(new Date()).getMonth()) {
  140. if (new Date().getDate() == k) {
  141. this.choseDay = k - 1;
  142. }
  143. } else {
  144. this.choseDay = 0;
  145. }
  146. dayArry.push(str);
  147. }
  148. this.allDate = dayArry;
  149. },
  150. getCountDays() {
  151. var newstr = this.date.replace(/-/g, "/");
  152. var curDate = new Date(newstr);
  153. var curMonth = curDate.getMonth();
  154. curDate.setMonth(curMonth + 1);
  155. curDate.setDate(0);
  156. return curDate.getDate();
  157. },
  158. //获取日报列表
  159. getReportList() {
  160. this.listLoading = true;
  161. let day = this.choseDay > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
  162. this.http.post( this.port.report.list, { date: this.date + day },
  163. res => {
  164. this.listLoading = false;
  165. if (res.code == "ok") {
  166. this.reportList = res.data;
  167. } else {
  168. this.$message({
  169. message: res.msg,
  170. type: "error"
  171. });
  172. }
  173. },
  174. error => {
  175. this.listLoading = false;
  176. this.$message({
  177. message: error,
  178. type: "error"
  179. });
  180. });
  181. },
  182. //导出日报
  183. exportReport() {
  184. if (this.reportList.length > 0) {
  185. this.listLoading = true;
  186. //首先处理日期
  187. let day = this.choseDay > 9 ? "-" + (this.choseDay + 1) : "-0" + (this.choseDay + 1);
  188. this.http.post( this.port.report.export, { date: this.date + day },
  189. res => {
  190. this.listLoading = false;
  191. if (res.code == "ok") {
  192. location.href = res.data;
  193. } else {
  194. this.$message({
  195. message: res.msg,
  196. type: "error"
  197. });
  198. }
  199. },
  200. error => {
  201. this.listLoading = false;
  202. this.$message({
  203. message: error,
  204. type: "error"
  205. });
  206. });
  207. } else {
  208. this.$message({
  209. message: "当天没有报告 无法导出",
  210. type: "info"
  211. });
  212. }
  213. },
  214. //获取项目列表
  215. getProjectList() {
  216. this.listLoading = true;
  217. this.http.post( this.port.project.list, {},
  218. res => {
  219. this.listLoading = false;
  220. if (res.code == "ok") {
  221. this.projectList = res.data;
  222. } else {
  223. this.$message({
  224. message: res.msg,
  225. type: "error"
  226. });
  227. }
  228. },
  229. error => {
  230. this.listLoading = false;
  231. this.$message({
  232. message: error,
  233. type: "error"
  234. });
  235. });
  236. },
  237. // 获取个人某天的日报
  238. getReport() {
  239. this.http.post( this.port.report.getPort, {
  240. date: this.workForm.createDate
  241. },
  242. res => {
  243. if (res.code == "ok") {
  244. var list = res.data;
  245. this.report = list;
  246. if(list.report.length != 0) {
  247. var arr = [];
  248. for(var i in list.report) {
  249. arr.push({
  250. id: list.report[i].id,
  251. projectId: list.report[i].projectId,
  252. workingTime: list.report[i].workingTime,
  253. content: list.report[i].content
  254. })
  255. }
  256. this.workForm = {
  257. createDate: this.workForm.createDate,
  258. domains: arr,
  259. }
  260. } else {
  261. this.workForm = {
  262. createDate: this.workForm.createDate,
  263. domains: [{
  264. id: null,
  265. projectId: "",
  266. workingTime: "",
  267. content: ""
  268. }],
  269. }
  270. }
  271. } else {
  272. this.$message({
  273. message: res.msg,
  274. type: "error"
  275. });
  276. }
  277. },
  278. error => {
  279. this.$message({
  280. message: error,
  281. type: "error"
  282. });
  283. });
  284. },
  285. // 打开日报填写
  286. fillInReport() {
  287. this.getReport();
  288. this.dialogVisible = true;
  289. },
  290. // 添加模块
  291. addDomain() {
  292. this.workForm.domains.push({
  293. projectId: "",
  294. workingTime: "",
  295. content: ""
  296. });
  297. },
  298. // 移除模块
  299. delDomain(i) {
  300. this.workForm.domains.splice(i,1)
  301. },
  302. // 改变月份
  303. changeMonth() {
  304. this.getReport()
  305. },
  306. // 保存日报
  307. submitDepartment() {
  308. this.$refs.workForm.validate(valid => {
  309. if (valid) {
  310. this.listLoading = true;
  311. let formData = new FormData();
  312. for(var i in this.workForm.domains) {
  313. if (this.workForm.domains[i].id != null) {
  314. formData.append("id", this.workForm.domains[i].id);
  315. } else {
  316. formData.append("id", -1);
  317. }
  318. formData.append("projectId", this.workForm.domains[i].projectId);
  319. formData.append("workingTime", this.workForm.domains[i].workingTime);
  320. formData.append("content", this.workForm.domains[i].content);
  321. formData.append("createDate", this.workForm.createDate);
  322. }
  323. this.http.uploadFile( this.port.report.editPort, formData,
  324. res => {
  325. this.listLoading = false;
  326. if (res.code == "ok") {
  327. this.$message({
  328. message: "填报成功",
  329. type: "success"
  330. });
  331. this.dialogVisible = false;
  332. this.getReportList();
  333. } else {
  334. this.$message({
  335. message: res.msg,
  336. type: "error"
  337. });
  338. }
  339. },
  340. error => {
  341. this.listLoading = false;
  342. this.$message({
  343. message: error,
  344. type: "error"
  345. });
  346. });
  347. }
  348. });
  349. },
  350. },
  351. created() {
  352. let height = window.innerHeight;
  353. this.tableHeight = height - 170;
  354. const that = this;
  355. window.onresize = function temp() {
  356. that.tableHeight = window.innerHeight - 170;
  357. };
  358. },
  359. mounted() {
  360. this.getAllDate();
  361. this.getReportList();
  362. this.getProjectList();
  363. }
  364. };
  365. </script>
  366. <style lang="scss" scoped>
  367. .clearfix {
  368. overflow-x: auto;
  369. white-space: nowrap;
  370. padding: 15px 0;
  371. .date_item {
  372. padding: 0 15px;
  373. cursor: pointer;
  374. }
  375. .chooseDate {
  376. color: #20a0ff;
  377. }
  378. }
  379. .one_daily {
  380. i {
  381. color: #9ed0ff;
  382. margin-right: 5px;
  383. }
  384. .one_daily_body {
  385. padding: 15px 0px;
  386. p {
  387. margin: 0;
  388. line-height: 30px;
  389. }
  390. }
  391. ul {
  392. padding: 0;
  393. }
  394. }
  395. </style>
  396. <style lang="scss">
  397. .daily {
  398. .el-card__body {
  399. height: 82%;
  400. overflow-y: auto;
  401. }
  402. }
  403. </style>
  404. <style scoped>
  405. /* 项目标签的样式 */
  406. .el-tag + .el-tag {
  407. margin-left: 10px;
  408. }
  409. .button-new-tag {
  410. margin-left: 10px;
  411. height: 32px;
  412. line-height: 30px;
  413. padding-top: 0;
  414. padding-bottom: 0;
  415. }
  416. .input-new-tag {
  417. width: 90px;
  418. margin-left: 10px;
  419. vertical-align: bottom;
  420. }
  421. </style>