demo/ruoyi-ui-vue3/src/views/mts/planDetail/index.vue

574 lines
18 KiB
Vue

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名称" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="计划时间" prop="planDate">
<el-date-picker clearable v-model="queryParams.planDate" type="date" value-format="YYYY-MM-DD"
placeholder="选择计划时间">
</el-date-picker>
</el-form-item>
<el-form-item label="实际时间" prop="actualDate">
<el-date-picker clearable v-model="queryParams.actualDate" type="date" value-format="YYYY-MM-DD"
placeholder="选择实际时间">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['mts:planDetail:add']">新增</el-button>
</el-col>
<!-- <el-col :span="1.5">
<el-button type="info" plain icon="Sort" @click="toggleExpandAll">展开/折叠</el-button>
</el-col> -->
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-if="refreshTable" v-loading="loading" :data="planDetailList" :row-key="(row, index) => row.id + index"
height="800" :default-expand-all="isExpandAll" :span-method="objectSpanMethod" :cell-style="handleChangeCellStyle"
border>
<el-table-column fixed="left" label="名称" align="left" prop="name" width="180">
<!-- <template #default="scope">
<span v-html="handleName(scope.row)"></span>
{{ scope.row.name }}
</template> -->
<template #default="scope">
<el-dropdown>
<span class="el-dropdown-link">
<span v-html="handleName(scope.row)"></span>
{{ scope.row.name }}
<el-icon class="el-icon--right">
<arrow-down />
</el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item>
<router-link :to="'/mts/detail-bom/index/' + scope.row.id" class="link-type">
<span>物料清单</span>
</router-link>
</el-dropdown-item>
<!-- <el-dropdown-item @click="handleDate(scope.row)">任务备注</el-dropdown-item> -->
<el-dropdown-item @click="handleAdd(scope.row)" v-if="scope.row.parentId == 0">新增</el-dropdown-item>
<!-- <el-dropdown-item @click="handleUpdate(scope.row)">修改</el-dropdown-item> -->
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
</el-table-column>
<el-table-column label="计划/实际" align="center" prop="flag" width="100">
<template #default="scope">
<span>{{ scope.row.flag === 'plan' ? '计划' : '实际' }}</span>
</template>
</el-table-column>
<!-- <el-table-column label="计划时间" align="center" prop="planDate" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.planDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="实际时间" align="center" prop="actualDate" width="180">
<template #default="scope">
<span>{{ parseTime(scope.row.actualDate, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column> -->
<el-table-column v-for="item in dateColumns" :label="item.label" align="left" :prop="item.prop" width="110">
<template #default="scope">
<!-- <el-tooltip v-if="scope.row.record.length > 0" placement="bottom">
<template #content> 修改历史留痕:<br />
<li v-for="item in handleHistory(scope.row, scope.column) ">{{ item }}</li>
</template>
<el-button link @click="handleDate(scope.column, scope.row)">
{{ handleDateColumn(scope.row, scope.column) }}
</el-button>
</el-tooltip> -->
<el-popover v-if="scope.row.record.length > 0" @before-enter="handleHistory(scope.row, scope.column)" placement="bottom"
title="修改历史留痕" :width="200" trigger="hover">
<template #reference>
<el-button link @click="handleDate(scope.column, scope.row)">
{{ handleDateColumn(scope.row, scope.column) }}
</el-button>
</template>
<template #default>
<li v-for="his in hisRecord">{{ his }}</li>
</template>
</el-popover>
<el-button v-else link @click="handleDate(scope.column, scope.row)">
{{ handleDateColumn(scope.row, scope.column) }}
</el-button>
</template>
</el-table-column>
<!-- <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="210">
<template #default="scope">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
v-hasPermi="['mts:planDetail:edit']">修改</el-button>
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)"
v-hasPermi="['mts:planDetail:add']">新增</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
v-hasPermi="['mts:planDetail:remove']">删除</el-button>
</template>
</el-table-column> -->
</el-table>
<!-- 添加或修改生产计划明细对话框 -->
<el-dialog :title="title" v-model="open" width="550px" append-to-body>
<el-form ref="planDetailRef" :model="form" :rules="rules" label-width="120px">
<el-form-item label="上级" prop="parentId">
<el-tree-select style="width: 100%;" v-model="form.parentId" :data="planDetailOptions"
:props="{ value: 'id', label: 'name', children: 'children' }" value-key="id" placeholder="请选择父id"
check-strictly />
</el-form-item>
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" placeholder="请输入名称" />
</el-form-item>
<el-form-item label="计划开始时间" prop="planStartDate">
<el-date-picker style="width: 100%;" clearable v-model="form.planStartDate" type="datetime"
value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择时间">
</el-date-picker>
</el-form-item>
<el-form-item label="计划结束时间" prop="planEndDate">
<el-date-picker style="width: 100%;" clearable v-model="form.planEndDate" type="datetime"
value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择时间">
</el-date-picker>
</el-form-item>
<!-- <el-form-item label="实际开始时间" prop="actualStartDate">
<el-date-picker style="width: 100%;" clearable v-model="form.actualStartDate" type="datetime"
value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择时间">
</el-date-picker>
</el-form-item>
<el-form-item label="实际开始时间" prop="actualEndDate">
<el-date-picker style="width: 100%;" clearable v-model="form.actualEndDate" type="datetime"
value-format="YYYY-MM-DD HH:mm:ss" placeholder="选择时间">
</el-date-picker>
</el-form-item> -->
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
<!-- 点击日期对话框 -->
<el-dialog title="任务备注" v-model="openDate" width="550px" append-to-body :before-close="cancelDate">
<el-form ref="planRecordRef" :model="formDate" label-width="90px">
<el-form-item label="备注" prop="remark">
<el-input v-model="formDate.remark" placeholder="请输入备注" autosize type="textarea" />
</el-form-item>
<el-form-item label="附件" prop="ossId">
<file-upload v-model="formDate.ossId" />
</el-form-item>
<el-form-item label="甘特图颜色" prop="ganttColor">
<el-color-picker v-model="formDate.ganttColor" size="large" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitFormDate">确 定</el-button>
<el-button @click="cancelDate">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="PlanDetail">
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import dayjs from 'dayjs'
import { listPlanDetail, getPlanDetail, delPlanDetail, addPlanDetail, updatePlanDetail, selectList } from "@/api/mts/planDetail";
import { getPlanMain } from "@/api/mts/planMain";
import { queryByBo } from "@/api/mts/planrecord";
import { addPlanRecord, updatePlanRecord } from "@/api/mts/planRecord";
import { listPlanRecordHistory } from "@/api/mts/planRecordHistory";
const { proxy } = getCurrentInstance();
const route = useRoute();
const planDetailList = ref([]);
const planDetailOptions = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const title = ref("");
const isExpandAll = ref(true);
const refreshTable = ref(true);
const data = reactive({
form: {
},
queryParams: {
parentId: undefined,
mainId: route.params.mainId,
name: undefined,
planDate: undefined,
actualDate: undefined,
},
rules: {
id: [
{ required: true, message: "主键不能为空", trigger: "blur" }
],
parentId: [
{ required: true, message: "父id不能为空", trigger: "blur" }
],
mainId: [
{ required: true, message: "主表id不能为空", trigger: "blur" }
],
name: [
{ required: true, message: "名称不能为空", trigger: "blur" }
],
planDate: [
{ required: true, message: "计划时间不能为空", trigger: "blur" }
],
actualDate: [
{ required: true, message: "实际时间不能为空", trigger: "blur" }
],
}
});
const { queryParams, form, rules } = toRefs(data);
const dateColumns = ref([])
const allDates = [];
onMounted(async () => {
const res = await getPlanMain(route.params.mainId);
const { startDate, endDate } = res.data
for (const date of getDays(startDate, endDate)) {
allDates.push(date);
dateColumns.value.push({
label: date,
prop: date
})
}
})
// 获取日期间隔之间的天数
function getDays(start, end) {
const startDate = dayjs(start);
const endDate = dayjs(end);
let allDates = [];
for (let date = startDate.clone(); date.isBefore(endDate); date = date.add(1, 'day')) {
allDates.push(date.format('YYYY-MM-DD'));
}
allDates.push(endDate.format('YYYY-MM-DD'))
return allDates
}
/**
* 改变表格单元格颜色
*/
function handleChangeCellStyle({ row, column, rowIndex, columnIndex }) {
let cellStyle = {}
for (const item of row.record) {
if (item.recordDate == column.label) {
cellStyle.backgroundColor = item.ganttColor
}
}
// 获取两个日期之间的所有日期
//column.label == dayjs(row.planStartDate).format('YYYY-MM-DD')
// const planDates = row.record.map(v => v.recordDate)
// let arr = planDates.filter(v => allDates.indexOf(v) > -1)
// if (arr.includes(column.label)) {
// if (row.ganttColor) {
// cellStyle.backgroundColor = row.ganttColor
// } else {
// cellStyle.backgroundColor = '#FFC000'
// }
// if (rowIndex % 2 == 0) {
// if (row.ganttColor) {
// cellStyle.backgroundColor = row.ganttColor
// } else {
// cellStyle.backgroundColor = '#00B050'
// }
// }
// } else {
// cellStyle.backgroundColor = 'white'
// }
return cellStyle
}
function handleDateColumn(row, column) {
let remark = ''
if (row.record.length > 0) {
for (const item of row.record) {
if (item.recordDate == column.label) {
remark = item.remark
}
}
}
return remark
}
const hisRecord = ref([])
async function handleHistory(row, column) {
let res = []
if (row.record.length > 0) {
for (const item of row.record) {
if (item.recordDate == column.label) {
const hisList = await listPlanRecordHistory({ recordId: item.id })
for (const his of hisList.rows) {
res.push(his.remark)
}
break;
}
}
}
hisRecord.value = res
}
const nbsp = "&nbsp;&nbsp;&nbsp;&nbsp;"
function handleName(row) {
let res = ''
if (row.parentId != 0) {
res = res + nbsp
}
return res
}
const objectSpanMethod = ({
row,
column,
rowIndex,
columnIndex,
}) => {
if (columnIndex === 0) {
if (rowIndex % 2 === 0) {
return {
rowspan: 2,
colspan: 1,
}
} else {
return {
rowspan: 0,
colspan: 0,
}
}
}
}
/** 查询生产计划明细列表 */
function getList() {
loading.value = true;
listPlanDetail(queryParams.value).then(response => {
// planDetailList.value = proxy.handleTree(response.data, "id", "parentId");
planDetailList.value = response.data
loading.value = false;
});
}
/** 查询生产计划明细下拉树结构 */
async function getTreeselect() {
selectList().then(response => {
planDetailOptions.value = [];
const data = { id: 0, name: '顶级节点', children: [] };
data.children = proxy.handleTree(response.data, "id", "parentId");
planDetailOptions.value.push(data);
});
}
// 取消按钮
function cancel() {
open.value = false;
reset();
}
// 表单重置
function reset() {
form.value = {
id: null,
parentId: null,
mainId: null,
name: null,
planDate: null,
actualDate: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
delFlag: null
};
proxy.resetForm("planDetailRef");
}
/** 搜索按钮操作 */
function handleQuery() {
getList();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
const openDate = ref(false)
const formDate = ref({})
async function handleDate(column, row) {
console.log('handleDate', column.label, row.id, row.flag)
const res = await queryByBo({ recordDate: column.label, detailId: row.id, flag: row.flag })
console.log('res', res)
openDate.value = true
if (res.data) {
formDate.value = res.data
}
formDate.value.flag = row.flag
formDate.value.recordDate = column.label
formDate.value.detailId = row.id
}
function submitFormDate() {
proxy.$refs["planRecordRef"].validate(valid => {
if (valid) {
buttonLoading.value = true;
if (formDate.value.id != null) {
updatePlanRecord(formDate.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
openDate.value = false;
getList();
resetDate();
}).finally(() => {
buttonLoading.value = false;
});
} else {
addPlanRecord(formDate.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
openDate.value = false;
getList();
resetDate();
}).finally(() => {
buttonLoading.value = false;
});
}
}
});
}
// 取消按钮
function cancelDate() {
openDate.value = false;
resetDate();
}
// 表单重置
function resetDate() {
formDate.value = {
id: null,
detailId: null,
recordDate: null,
startDate: null,
remark: null,
flag: null,
ganttColor: null,
ossId: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
delFlag: null
};
proxy.resetForm("planRecordRef");
}
/** 新增按钮操作 */
function handleAdd(row) {
reset();
getTreeselect();
if (row != null && row.id) {
form.value.parentId = row.id;
} else {
form.value.parentId = 0;
}
form.value.mainId = route.params.mainId;
open.value = true;
title.value = "添加生产计划明细";
}
/** 展开/折叠操作 */
function toggleExpandAll() {
refreshTable.value = false;
isExpandAll.value = !isExpandAll.value;
nextTick(() => {
refreshTable.value = true;
});
}
/** 修改按钮操作 */
async function handleUpdate(row) {
loading.value = true;
reset();
await getTreeselect();
if (row != null) {
form.value.parentId = row.parentId;
}
form.value.mainId = route.params.mainId;
getPlanDetail(row.id).then(response => {
loading.value = false;
form.value = response.data;
open.value = true;
title.value = "修改生产计划明细";
});
}
/** 提交按钮 */
function submitForm() {
proxy.$refs["planDetailRef"].validate(valid => {
if (valid) {
buttonLoading.value = true;
if (form.value.id != null) {
updatePlanDetail(form.value).then(response => {
proxy.$modal.msgSuccess("修改成功");
open.value = false;
getList();
}).finally(() => {
buttonLoading.value = false;
});
} else {
addPlanDetail(form.value).then(response => {
proxy.$modal.msgSuccess("新增成功");
open.value = false;
getList();
}).finally(() => {
buttonLoading.value = false;
});
}
}
});
}
/** 删除按钮操作 */
function handleDelete(row) {
proxy.$modal.confirm('是否确认删除生产计划明细编号为"' + row.id + '"的数据项?').then(function () {
loading.value = true;
return delPlanDetail(row.id);
}).then(() => {
loading.value = false;
getList();
proxy.$modal.msgSuccess("删除成功");
}).catch(() => {
}).finally(() => {
loading.value = false;
});
}
getList();
</script>
<style scoped lang="scss"></style>