weeklyCustomization.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div class='weeklyCustomization'>
  3. <div class="title">
  4. <el-button @click="getCurrentWeek(-7)" size="small">&lt;&lt;</el-button>
  5. <el-button @click="getCurrentWeek(0)" size="small">本周</el-button>
  6. <el-button @click="getCurrentWeek(7)" size="small">&gt;&gt;</el-button>
  7. </div>
  8. <div class="weekcen flexColumn" v-loading="submitLoading">
  9. <div class="flexColumnAuto flex1">
  10. <el-table :data="weekTableData" border style="width: 100%;" height="0" :span-method="arraySpanMethod">
  11. <el-table-column prop="dateTime" label="日期" width="180">
  12. <template slot-scope="scope">
  13. <span>{{ scope.row.dateTime }}</span>
  14. (<span>{{ scope.row.weekDayTxt }}</span>)
  15. </template>
  16. </el-table-column>
  17. <el-table-column label="项目" width="220">
  18. <template slot-scope="scope">
  19. <el-select v-model="scope.row.projectId" size="small" placeholder="请选择项目" clearable
  20. @change="changeProject(scope.row.projectId, scope.$index)"
  21. :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill">
  22. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName"
  23. :value="item.id">
  24. </el-option>
  25. </el-select>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="分组" width="180">
  29. <template slot-scope="scope">
  30. <el-select v-model="scope.row.groupId" size="small" placeholder="请选择分组"
  31. @change="changeGroup(scope.row.groupId, scope.row.taskGroups, scope.$index)"
  32. :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill">
  33. <el-option v-for="item in scope.row.taskGroups" :key="item.id" :label="item.name"
  34. :value="item.id">
  35. </el-option>
  36. </el-select>
  37. </template>
  38. </el-table-column>
  39. <el-table-column prop="content" label="工作内容" width="300">
  40. <template slot-scope="scope">
  41. <el-input size="small" type="textarea" :rows="2" v-model="scope.row.content"
  42. :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill"
  43. resize="none"></el-input>
  44. </template>
  45. </el-table-column>
  46. <el-table-column prop="workingTime" label="时间(小时)" width="160">
  47. <template slot-scope="scope">
  48. <el-input-number size="small" v-model="scope.row.workingTime" :min="0" :max="12" :step="0.5"
  49. :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill"></el-input-number>
  50. </template>
  51. </el-table-column>
  52. <el-table-column prop="projectAuditorId" label="审批人" width="160">
  53. <template slot-scope="scope">
  54. <!-- <span v-if="user.userNameNeedTranslate != '1'">{{ scope.row.projectAuditorName }}</span>
  55. <span v-if="user.userNameNeedTranslate == '1'"><TranslationOpenDataText type='userName'
  56. :openid='scope.row.projectAuditorName'></TranslationOpenDataText></span> -->
  57. <span v-if="user.userNameNeedTranslate != '1'">{{ auditorNameFun(scope.row) }}</span>
  58. <span v-if="user.userNameNeedTranslate == '1'">
  59. <TranslationOpenDataText type='userName' :openid='auditorNameFun(scope.row)'></TranslationOpenDataText>
  60. </span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column prop="state" label="状态" width="140" fixed="right">
  64. <template slot-scope="scope">
  65. <div class="controls">
  66. <el-tag v-if="scope.row.state == 0" type="warning">待审</el-tag>
  67. <el-tag v-if="scope.row.state == 1" type="success">通过</el-tag>
  68. <el-tag v-if="scope.row.state == 2" type="danger">拒绝</el-tag>
  69. <span v-if="scope.row.state != 1 && scope.row.canFill">
  70. <el-link type="primary" :underline="false" class="el-icon-circle-plus-outline"
  71. @click="insertRow(scope.$index)"></el-link>
  72. <el-link type="primary" :underline="false" class="el-icon-delete"
  73. @click="deleteRow(scope.$index)" v-if="!scope.row.isDelete"></el-link>
  74. </span>
  75. </div>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. </div>
  80. <div>
  81. <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6}" maxlength="1000" show-word-limit
  82. placeholder="请输入周总结"
  83. v-model="summaryContent">
  84. </el-input>
  85. </div>
  86. <div class="weeklyCustomization_btn">
  87. <el-button @click="handleClose()">取 消</el-button>
  88. <el-button @click="submitWeekData(1)">暂 存</el-button>
  89. <el-button type="primary" @click="submitWeekData(0)">提 交</el-button>
  90. </div>
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. import cloneDeep from 'lodash/cloneDeep'; // 深拷贝
  96. export default {
  97. name: '',
  98. components: {},
  99. props: {
  100. weekParentData: {
  101. type: Object,
  102. default: () => {
  103. return {}
  104. }
  105. },
  106. },
  107. data() {
  108. return {
  109. summaryContent: null,
  110. weekTableData: [],
  111. projectList: [],
  112. nowTime: this.dayjs().format('YYYY-MM-DD'),
  113. submitLoading: false,
  114. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  115. user: JSON.parse(sessionStorage.getItem("user")),
  116. }
  117. },
  118. computed: {},
  119. watch: {},
  120. created() { },
  121. mounted() {
  122. this.$set(this, 'weekTableData', [])
  123. this.getCurrentWeek(0)
  124. this.getProjectList()
  125. },
  126. methods: {
  127. // 提交与暂存
  128. submitWeekData(draft) { // draft 暂存(1)提交(0)
  129. const newWeekData = cloneDeep(this.weekTableData)
  130. let strArr = this.judgmentData(newWeekData)
  131. const { allday } = this.user.timeType // 系统设置的每日工作时间
  132. if (strArr.length > 0) {
  133. this.$message({
  134. message: `【${strArr.join('、')}】填写工时合计非 ${allday} 小时`,
  135. type: "error"
  136. });
  137. return
  138. }
  139. let formData = new FormData();
  140. formData.append("draft", draft);
  141. formData.append('summary', this.summaryContent);
  142. let fixation = {
  143. id: -1,
  144. projectId: '',
  145. subProjectId: 0,
  146. taskId: 0,
  147. reportTimeType: 1,
  148. workingTime: 0,
  149. multiWorktime: 0,
  150. content: '',
  151. isOvertime: 0,
  152. // professionProgress: [],
  153. groupId: '',
  154. stage: '',
  155. createDate: '',
  156. projectAuditorId: '',
  157. basecostId: 0,
  158. degreeId: -1,
  159. customData: 0,
  160. customText: '-',
  161. }
  162. const arr = newWeekData
  163. .filter(data => data.projectId)
  164. .map(data => ({
  165. ...fixation,
  166. projectId: data.projectId,
  167. createDate: data.dateTime,
  168. content: data.content ? data.content : '',
  169. projectAuditorId: data.projectAuditorId,
  170. workingTime: data.workingTime,
  171. groupId: data.groupId,
  172. id: data.id || -1,
  173. }));
  174. arr.forEach(item => {
  175. Object.entries(item).forEach(([key, value]) => {
  176. formData.append(key, value);
  177. });
  178. });
  179. this.submitLoading = true
  180. this.http.uploadFile(this.port.report.editPort, formData,
  181. res => {
  182. this.submitLoading = false
  183. if (res.code == "ok") {
  184. this.$message({
  185. message: `${draft ? '暂存成功' : '提交成功'}`,
  186. type: "success"
  187. });
  188. this.$emit('weekClose')
  189. this.$emit('weekSubmit')
  190. } else {
  191. this.$message({
  192. message: `${draft ? '暂存失败:' : '提交失败:'}` + res.msg,
  193. type: "error"
  194. });
  195. }
  196. },
  197. error => {
  198. this.submitLoading = false
  199. this.$message({
  200. message: error,
  201. type: "error"
  202. });
  203. });
  204. },
  205. // 判断是否小于系统设置的每日工作时间
  206. judgmentData(data) {
  207. const { allday } = this.user.timeType // 系统设置的每日工作时间
  208. console.log(allday, '<======= 填写日报时长allday')
  209. const result = [];
  210. data.forEach((item) => {
  211. const date = item.dateTime;
  212. const index = result.findIndex((arr) => arr[0].dateTime === date);
  213. if (index === -1) {
  214. result.push([item]);
  215. } else {
  216. result[index].push(item);
  217. }
  218. });
  219. const strArr = result
  220. .filter((arr) => arr[0].projectId)
  221. .filter(
  222. (arr) => arr.reduce((sum, item) => sum + (+item.workingTime || 0), 0) != allday
  223. )
  224. .map((arr) => arr[0].dateTime);
  225. return strArr
  226. },
  227. // 项目切换事件
  228. changeProject(projectId, index) {
  229. this.$set(this.weekTableData[index], 'projectAuditorId', '')
  230. this.$set(this.weekTableData[index], 'projectAuditorName', '')
  231. this.$set(this.weekTableData[index], 'groupId', '')
  232. if (projectId) {
  233. this.getProjectGroup(projectId, index)
  234. }
  235. },
  236. // 分组切换事件
  237. changeGroup(groupId, groupList, index) {
  238. let newArr = groupList.filter(item => item.id == groupId)
  239. if (!newArr[0].inchargerId) {
  240. this.$message({
  241. message: `【${newArr[0].name}】分组未设置审批人,请联系该项目管理人员`,
  242. type: "error"
  243. });
  244. return
  245. }
  246. this.$set(this.weekTableData[index], 'projectAuditorId', newArr[0].inchargerId)
  247. this.$set(this.weekTableData[index], 'projectAuditorName', newArr[0].inchargerName)
  248. },
  249. // 获取周数据
  250. async getCurrentWeek(time) {
  251. if (!time) {
  252. this.nowTime = this.dayjs().format('YYYY-MM-DD')
  253. } else {
  254. this.nowTime = this.dayjs(this.nowTime).add(time, 'day').format('YYYY-MM-DD')
  255. }
  256. let { data } = await this.getData('/report/getWeeklyFillReportData', { targetDate: this.nowTime })
  257. console.log(JSON.parse(JSON.stringify(data)), '<===== 处理之前的')
  258. this.summaryContent = data.summary;
  259. data.dateList.forEach(dateItem => {
  260. const reportList = dateItem.reportList;
  261. reportList.forEach(report => {
  262. const { state, taskGroups } = report;
  263. console.log(state, taskGroups);
  264. if(state != 1 && state != 0 && taskGroups && taskGroups.length > 0) {
  265. console.log('执行');
  266. report.projectAuditorId = taskGroups[0].inchargerId;
  267. report.projectAuditorName = taskGroups[0].inchargerName;
  268. }
  269. if(state == 1 && state == 0 && taskGroups && taskGroups.length > 0) {
  270. taskGroups[0].inchargerId = report.projectAuditorId;
  271. taskGroups[0].inchargerName = report.projectAuditorName;
  272. }
  273. });
  274. });
  275. console.log(data, '<===== 处理之后的')
  276. const { dateList, projectList, sumTimeList, cardTimeList } = data;
  277. const weekTableData = dateList.flatMap(date => {
  278. const { weekDayTxt, date: dateTime, reportList, canFill } = date;
  279. const reports = reportList.map(report => ({ ...report, weekDayTxt, dateTime, canFill }));
  280. return reports.length > 0 ? reports : [{ weekDayTxt, dateTime, canFill }];
  281. });
  282. let sumSet = new Set();
  283. weekTableData.forEach(obj => {
  284. obj.isDelete = sumSet.has(obj.dateTime) ? false : true;
  285. sumSet.add(obj.dateTime);
  286. });
  287. this.weekTableData = weekTableData;
  288. console.log(weekTableData, '<========== weekTableData')
  289. },
  290. // 获取项目列表
  291. async getProjectList() {
  292. let { data } = await this.getData('/project/getProjectList', { forReport: 1 })
  293. this.projectList = data
  294. },
  295. // 获取项目下的分组
  296. async getProjectGroup(projectId, index) {
  297. const { isSubstitude } = this.weekParentData;
  298. let { data } = await this.getData('/task-group/listProjectGroupAndAuditor', { projectId, isSubstitude: isSubstitude ? 1 : 0 })
  299. if (data.length == 0) {
  300. this.$message({
  301. message: '分组未设置,请联系该项目管理人员',
  302. type: "error"
  303. });
  304. } else if (data.length == 1) {
  305. this.$set(this.weekTableData[index], 'groupId', data[0].id)
  306. this.$set(this.weekTableData[index], 'projectAuditorId', data[0].inchargerId)
  307. this.$set(this.weekTableData[index], 'projectAuditorName', data[0].inchargerName)
  308. if (!data[0].inchargerId) {
  309. this.$message({
  310. message: `【${data[0].name}】分组未设置审批人,请联系该项目管理人员`,
  311. type: "error"
  312. });
  313. }
  314. }
  315. this.$set(this.weekTableData[index], 'taskGroups', data)
  316. },
  317. // 插入一行
  318. insertRow(index) {
  319. this.weekTableData.splice(index + 1, 0, {
  320. dateTime: this.weekTableData[index].dateTime,
  321. weekDayTxt: this.weekTableData[index].weekDayTxt,
  322. content: '',
  323. workingTime: 0,
  324. projectId: '',
  325. projectAuditorId: '',
  326. projectAuditorName: '',
  327. groupId: '',
  328. groupList: [],
  329. approverList: [],
  330. canFill: 1,
  331. isDelete: false
  332. })
  333. },
  334. // 删除一行
  335. deleteRow(index) {
  336. this.weekTableData.splice(index, 1)
  337. },
  338. // 合并单元格
  339. arraySpanMethod({ row, column, rowIndex, columnIndex }) {
  340. let spanOneArr = [], concatOne = 0;
  341. this.weekTableData.map((item, index) => {
  342. if (index === 0) {
  343. spanOneArr.push(1);
  344. } else {
  345. if (item.dateTime === this.weekTableData[index - 1].dateTime) {
  346. spanOneArr[concatOne] += 1;
  347. spanOneArr.push(0);
  348. } else {
  349. spanOneArr.push(1);
  350. concatOne = index;
  351. };
  352. }
  353. });
  354. if (columnIndex === 0) {
  355. const _row = spanOneArr[rowIndex];
  356. const _col = _row > 0 ? 1 : 0;
  357. return {
  358. rowspan: _row,
  359. colspan: _col
  360. }
  361. }
  362. },
  363. // 回显审批人名字
  364. auditorNameFun(item) {
  365. const { groupId, taskGroups } = item;
  366. if (groupId) {
  367. const newArr = taskGroups.filter(v => v.id === groupId);
  368. return newArr.length > 0 ? newArr[0].inchargerName : '';
  369. }
  370. return '';
  371. },
  372. // post 方法请求二次封装
  373. async getData(url, param) {
  374. return new Promise((resolve, reject) => {
  375. this.http.post(url, param,
  376. res => {
  377. resolve(res)
  378. },
  379. error => {
  380. this.$message({
  381. message: error,
  382. type: "error"
  383. });
  384. reject(error)
  385. }
  386. )
  387. });
  388. },
  389. // 关闭弹窗
  390. handleClose() {
  391. this.$emit('weekClose')
  392. },
  393. },
  394. }
  395. </script>
  396. <style scoped lang='scss'>
  397. .flexColumn {
  398. display: flex;
  399. flex-direction: column;
  400. }
  401. .flexColumnAuto {
  402. display: flex;
  403. flex-direction: column;
  404. overflow: auto;
  405. }
  406. .flex1 {
  407. flex: 1;
  408. overflow-y: auto;
  409. }
  410. .weeklyCustomization {
  411. width: 100%;
  412. height: 100%;
  413. .title {
  414. position: absolute;
  415. top: 16px;
  416. left: 140px;
  417. }
  418. .weekcen {
  419. width: 100%;
  420. height: 100%;
  421. }
  422. .weeklyCustomization_btn {
  423. display: flex;
  424. justify-content: flex-end;
  425. padding-top: 10px;
  426. }
  427. .controls {
  428. display: flex;
  429. justify-content: space-between;
  430. align-items: center;
  431. width: 100%;
  432. .el-link {
  433. font-size: 18px;
  434. margin-right: 5px;
  435. }
  436. }
  437. }
  438. </style>