weeklyCustomization.vue 20 KB

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