123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- <template>
- <div class='weeklyCustomization'>
- <div class="title">
- <el-button @click="getCurrentWeek(-7)" size="small"><<</el-button>
- <el-button @click="getCurrentWeek(0)" size="small">本周</el-button>
- <el-button @click="getCurrentWeek(7)" size="small">>></el-button>
- </div>
- <div class="weekcen flexColumn" v-loading="submitLoading">
- <div class="flexColumnAuto flex1">
- <el-table :data="weekTableData" border style="width: 100%;" height="0" :span-method="arraySpanMethod">
- <el-table-column prop="dateTime" label="日期" width="180">
- <template slot-scope="scope">
- <span>{{ scope.row.dateTime }}</span>
- (<span>{{ scope.row.weekDayTxt }}</span>)
- </template>
- </el-table-column>
- <el-table-column label="项目" width="220">
- <template slot-scope="scope">
- <el-select v-model="scope.row.projectId" size="small" placeholder="请选择项目" clearable
- @change="changeProject(scope.row.projectId, scope.$index)"
- :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill">
- <el-option v-for="item in projectList" :key="item.id" :label="item.projectName"
- :value="item.id">
- </el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column label="分组" width="180">
- <template slot-scope="scope">
- <el-select v-model="scope.row.groupId" size="small" placeholder="请选择分组"
- @change="changeGroup(scope.row.groupId, scope.row.taskGroups, scope.$index)"
- :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill">
- <el-option v-for="item in scope.row.taskGroups" :key="item.id" :label="item.name"
- :value="item.id">
- </el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column prop="content" label="工作内容" width="300">
- <template slot-scope="scope">
- <el-input size="small" type="textarea" :rows="2" v-model="scope.row.content"
- :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill"
- resize="none"></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="workingTime" label="时间(小时)" width="160">
- <template slot-scope="scope">
- <el-input-number size="small" v-model="scope.row.workingTime" :min="0" :max="12" :step="0.5"
- :disabled="scope.row.state == 1 || scope.row.state == 0 || !scope.row.canFill"></el-input-number>
- </template>
- </el-table-column>
- <el-table-column prop="projectAuditorId" label="审批人" width="160">
- <template slot-scope="scope">
- <!-- <span v-if="user.userNameNeedTranslate != '1'">{{ scope.row.projectAuditorName }}</span>
- <span v-if="user.userNameNeedTranslate == '1'"><TranslationOpenDataText type='userName'
- :openid='scope.row.projectAuditorName'></TranslationOpenDataText></span> -->
- <span v-if="user.userNameNeedTranslate != '1'">{{ auditorNameFun(scope.row) }}</span>
- <span v-if="user.userNameNeedTranslate == '1'">
- <TranslationOpenDataText type='userName' :openid='auditorNameFun(scope.row)'></TranslationOpenDataText>
- </span>
- </template>
- </el-table-column>
- <el-table-column prop="state" label="状态" width="140" fixed="right">
- <template slot-scope="scope">
- <div class="controls">
- <el-tag v-if="scope.row.state == 0" type="warning">待审</el-tag>
- <el-tag v-if="scope.row.state == 1" type="success">通过</el-tag>
- <el-tag v-if="scope.row.state == 2" type="danger">拒绝</el-tag>
- <span v-if="scope.row.state != 1 && scope.row.canFill">
- <el-link type="primary" :underline="false" class="el-icon-circle-plus-outline"
- @click="insertRow(scope.$index)"></el-link>
- <el-link type="primary" :underline="false" class="el-icon-delete"
- @click="deleteRow(scope.$index)" v-if="!scope.row.isDelete"></el-link>
- </span>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div>
- <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6}" maxlength="1000" show-word-limit
- placeholder="请输入周总结"
- v-model="summaryContent">
- </el-input>
- </div>
- <div class="weeklyCustomization_btn">
- <el-button @click="handleClose()">取 消</el-button>
- <el-button @click="submitWeekData(1)">暂 存</el-button>
- <el-button type="primary" @click="submitWeekData(0)">提 交</el-button>
- </div>
- </div>
- </div>
- </template>
- <script>
- import cloneDeep from 'lodash/cloneDeep'; // 深拷贝
- export default {
- name: '',
- components: {},
- props: {
- weekParentData: {
- type: Object,
- default: () => {
- return {}
- }
- },
- },
- data() {
- return {
- summaryContent: null,
- weekTableData: [],
- projectList: [],
- nowTime: this.dayjs().format('YYYY-MM-DD'),
- submitLoading: false,
- permissions: JSON.parse(sessionStorage.getItem("permissions")),
- user: JSON.parse(sessionStorage.getItem("user")),
- }
- },
- computed: {},
- watch: {},
- created() { },
- mounted() {
- this.$set(this, 'weekTableData', [])
- this.getCurrentWeek(0)
- this.getProjectList()
- },
- methods: {
- // 提交与暂存
- submitWeekData(draft) { // draft 暂存(1)提交(0)
- const newWeekData = cloneDeep(this.weekTableData)
- let strArr = this.judgmentData(newWeekData)
- const { allday } = this.user.timeType // 系统设置的每日工作时间
- if (strArr.length > 0) {
- this.$message({
- message: `【${strArr.join('、')}】填写工时合计非 ${allday} 小时`,
- type: "error"
- });
- return
- }
- let formData = new FormData();
- formData.append("draft", draft);
- formData.append('summary', this.summaryContent);
- let fixation = {
- id: -1,
- projectId: '',
- subProjectId: 0,
- taskId: 0,
- reportTimeType: 1,
- workingTime: 0,
- multiWorktime: 0,
- content: '',
- isOvertime: 0,
- // professionProgress: [],
- groupId: '',
- stage: '',
- createDate: '',
- projectAuditorId: '',
- basecostId: 0,
- degreeId: -1,
- customData: 0,
- customText: '-',
- }
- const arr = newWeekData
- .filter(data => data.projectId)
- .map(data => ({
- ...fixation,
- projectId: data.projectId,
- createDate: data.dateTime,
- content: data.content ? data.content : '',
- projectAuditorId: data.projectAuditorId,
- workingTime: data.workingTime,
- groupId: data.groupId,
- id: data.id || -1,
- }));
- arr.forEach(item => {
- Object.entries(item).forEach(([key, value]) => {
- formData.append(key, value);
- });
- });
- this.submitLoading = true
- this.http.uploadFile(this.port.report.editPort, formData,
- res => {
- this.submitLoading = false
- if (res.code == "ok") {
- this.$message({
- message: `${draft ? '暂存成功' : '提交成功'}`,
- type: "success"
- });
- this.$emit('weekClose')
- this.$emit('weekSubmit')
- } else {
- this.$message({
- message: `${draft ? '暂存失败:' : '提交失败:'}` + res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.submitLoading = false
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- // 判断是否小于系统设置的每日工作时间
- judgmentData(data) {
- const { allday } = this.user.timeType // 系统设置的每日工作时间
- console.log(allday, '<======= 填写日报时长allday')
- const result = [];
- data.forEach((item) => {
- const date = item.dateTime;
- const index = result.findIndex((arr) => arr[0].dateTime === date);
- if (index === -1) {
- result.push([item]);
- } else {
- result[index].push(item);
- }
- });
- const strArr = result
- .filter((arr) => arr[0].projectId)
- .filter(
- (arr) => arr.reduce((sum, item) => sum + (+item.workingTime || 0), 0) != allday
- )
- .map((arr) => arr[0].dateTime);
- return strArr
- },
- // 项目切换事件
- changeProject(projectId, index) {
- this.$set(this.weekTableData[index], 'projectAuditorId', '')
- this.$set(this.weekTableData[index], 'projectAuditorName', '')
- this.$set(this.weekTableData[index], 'groupId', '')
- if (projectId) {
- this.getProjectGroup(projectId, index)
- }
- },
- // 分组切换事件
- changeGroup(groupId, groupList, index) {
- let newArr = groupList.filter(item => item.id == groupId)
- if (!newArr[0].inchargerId) {
- this.$message({
- message: `【${newArr[0].name}】分组未设置审批人,请联系该项目管理人员`,
- type: "error"
- });
- return
- }
- this.$set(this.weekTableData[index], 'projectAuditorId', newArr[0].inchargerId)
- this.$set(this.weekTableData[index], 'projectAuditorName', newArr[0].inchargerName)
- },
- // 获取周数据
- async getCurrentWeek(time) {
- if (!time) {
- this.nowTime = this.dayjs().format('YYYY-MM-DD')
- } else {
- this.nowTime = this.dayjs(this.nowTime).add(time, 'day').format('YYYY-MM-DD')
- }
- let { data } = await this.getData('/report/getWeeklyFillReportData', { targetDate: this.nowTime })
- console.log(JSON.parse(JSON.stringify(data)), '<===== 处理之前的')
- this.summaryContent = data.summary;
- data.dateList.forEach(dateItem => {
- const reportList = dateItem.reportList;
- reportList.forEach(report => {
- const { state, taskGroups } = report;
- console.log(state, taskGroups);
- if(state != 1 && state != 0 && taskGroups && taskGroups.length > 0) {
- console.log('执行');
- report.projectAuditorId = taskGroups[0].inchargerId;
- report.projectAuditorName = taskGroups[0].inchargerName;
- }
- if(state == 1 && state == 0 && taskGroups && taskGroups.length > 0) {
- taskGroups[0].inchargerId = report.projectAuditorId;
- taskGroups[0].inchargerName = report.projectAuditorName;
- }
- });
- });
- console.log(data, '<===== 处理之后的')
- const { dateList, projectList, sumTimeList, cardTimeList } = data;
- const weekTableData = dateList.flatMap(date => {
- const { weekDayTxt, date: dateTime, reportList, canFill } = date;
- const reports = reportList.map(report => ({ ...report, weekDayTxt, dateTime, canFill }));
- return reports.length > 0 ? reports : [{ weekDayTxt, dateTime, canFill }];
- });
- let sumSet = new Set();
- weekTableData.forEach(obj => {
- obj.isDelete = sumSet.has(obj.dateTime) ? false : true;
- sumSet.add(obj.dateTime);
- });
- this.weekTableData = weekTableData;
- console.log(weekTableData, '<========== weekTableData')
- },
- // 获取项目列表
- async getProjectList() {
- let { data } = await this.getData('/project/getProjectList', { forReport: 1 })
- this.projectList = data
- },
- // 获取项目下的分组
- async getProjectGroup(projectId, index) {
- const { isSubstitude } = this.weekParentData;
- let { data } = await this.getData('/task-group/listProjectGroupAndAuditor', { projectId, isSubstitude: isSubstitude ? 1 : 0 })
- if (data.length == 0) {
- this.$message({
- message: '分组未设置,请联系该项目管理人员',
- type: "error"
- });
- } else if (data.length == 1) {
- this.$set(this.weekTableData[index], 'groupId', data[0].id)
- this.$set(this.weekTableData[index], 'projectAuditorId', data[0].inchargerId)
- this.$set(this.weekTableData[index], 'projectAuditorName', data[0].inchargerName)
- if (!data[0].inchargerId) {
- this.$message({
- message: `【${data[0].name}】分组未设置审批人,请联系该项目管理人员`,
- type: "error"
- });
- }
- }
- this.$set(this.weekTableData[index], 'taskGroups', data)
- },
- // 插入一行
- insertRow(index) {
- this.weekTableData.splice(index + 1, 0, {
- dateTime: this.weekTableData[index].dateTime,
- weekDayTxt: this.weekTableData[index].weekDayTxt,
- content: '',
- workingTime: 0,
- projectId: '',
- projectAuditorId: '',
- projectAuditorName: '',
- groupId: '',
- groupList: [],
- approverList: [],
- canFill: 1,
- isDelete: false
- })
- },
- // 删除一行
- deleteRow(index) {
- this.weekTableData.splice(index, 1)
- },
- // 合并单元格
- arraySpanMethod({ row, column, rowIndex, columnIndex }) {
- let spanOneArr = [], concatOne = 0;
- this.weekTableData.map((item, index) => {
- if (index === 0) {
- spanOneArr.push(1);
- } else {
- if (item.dateTime === this.weekTableData[index - 1].dateTime) {
- spanOneArr[concatOne] += 1;
- spanOneArr.push(0);
- } else {
- spanOneArr.push(1);
- concatOne = index;
- };
- }
- });
- if (columnIndex === 0) {
- const _row = spanOneArr[rowIndex];
- const _col = _row > 0 ? 1 : 0;
- return {
- rowspan: _row,
- colspan: _col
- }
- }
- },
- // 回显审批人名字
- auditorNameFun(item) {
- const { groupId, taskGroups } = item;
- if (groupId) {
- const newArr = taskGroups.filter(v => v.id === groupId);
- return newArr.length > 0 ? newArr[0].inchargerName : '';
- }
- return '';
- },
- // post 方法请求二次封装
- async getData(url, param) {
- return new Promise((resolve, reject) => {
- this.http.post(url, param,
- res => {
- resolve(res)
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- reject(error)
- }
- )
- });
- },
- // 关闭弹窗
- handleClose() {
- this.$emit('weekClose')
- },
- },
- }
- </script>
- <style scoped lang='scss'>
- .flexColumn {
- display: flex;
- flex-direction: column;
- }
- .flexColumnAuto {
- display: flex;
- flex-direction: column;
- overflow: auto;
- }
- .flex1 {
- flex: 1;
- overflow-y: auto;
- }
- .weeklyCustomization {
- width: 100%;
- height: 100%;
- .title {
- position: absolute;
- top: 16px;
- left: 140px;
- }
- .weekcen {
- width: 100%;
- height: 100%;
- }
- .weeklyCustomization_btn {
- display: flex;
- justify-content: flex-end;
- padding-top: 10px;
- }
- .controls {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- .el-link {
- font-size: 18px;
- margin-right: 5px;
- }
- }
- }
- </style>
|