daily.vue 17 KB

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