Commit 370ab00e authored by tianhongyang's avatar tianhongyang

decimal封装优化,工料汇总80%

parent 0f5de350
...@@ -11,7 +11,8 @@ export const add = (num1, num2, digit = 9, omit = false) => { ...@@ -11,7 +11,8 @@ export const add = (num1, num2, digit = 9, omit = false) => {
if (flag) throw new Error("传入参数错误,参数不为number"); if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1); const decimal1 = new Decimal(num1);
const decimal2 = new Decimal(num2); const decimal2 = new Decimal(num2);
return decimal1.plus(decimal2).toDecimalPlaces(digit, Decimal.ROUND_UP).toString(); const result = decimal1.plus(decimal2);
return omit ? result.toFixed(digit, Decimal.ROUND_UP) : result.toDecimalPlaces(digit, Decimal.ROUND_UP).toString();
}; };
/** /**
...@@ -20,12 +21,13 @@ export const add = (num1, num2, digit = 9, omit = false) => { ...@@ -20,12 +21,13 @@ export const add = (num1, num2, digit = 9, omit = false) => {
* @param {*} num2 * @param {*} num2
* @returns * @returns
*/ */
export const subtract = (num1, num2, digit = 9) => { export const subtract = (num1, num2, digit = 9, omit = false) => {
const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0"); const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0");
if (flag) throw new Error("传入参数错误,参数不为number"); if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1); const decimal1 = new Decimal(num1);
const decimal2 = new Decimal(num2); const decimal2 = new Decimal(num2);
return decimal1.minus(decimal2).toDecimalPlaces(digit, Decimal.ROUND_UP).toString(); const result = decimal1.minus(decimal2);
return omit ? result.toFixed(digit, Decimal.ROUND_UP) : result.toDecimalPlaces(digit, Decimal.ROUND_UP).toString();
}; };
/** /**
...@@ -34,12 +36,13 @@ export const subtract = (num1, num2, digit = 9) => { ...@@ -34,12 +36,13 @@ export const subtract = (num1, num2, digit = 9) => {
* @param {*} num2 * @param {*} num2
* @returns * @returns
*/ */
export const multiply = (num1, num2, digit = 9) => { export const multiply = (num1, num2, digit = 9, omit = false) => {
const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0"); const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0");
if (flag) throw new Error("传入参数错误,参数不为number"); if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1); const decimal1 = new Decimal(num1);
const decimal2 = new Decimal(num2); const decimal2 = new Decimal(num2);
return decimal1.times(decimal2).toDecimalPlaces(digit, Decimal.ROUND_UP).toString(); const result = decimal1.times(decimal2);
return omit ? result.toFixed(digit, Decimal.ROUND_UP) : result.toDecimalPlaces(digit, Decimal.ROUND_UP).toString();
}; };
/** /**
...@@ -48,10 +51,11 @@ export const multiply = (num1, num2, digit = 9) => { ...@@ -48,10 +51,11 @@ export const multiply = (num1, num2, digit = 9) => {
* @param {*} num2 * @param {*} num2
* @returns * @returns
*/ */
export const divide = (num1, num2, digit = 9) => { export const divide = (num1, num2, digit = 9, omit = false) => {
const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0"); const flag = (!parseFloat(num1) && parseFloat(num1) != "0") || (!parseFloat(num2) && parseFloat(num2) != "0");
if (flag) throw new Error("传入参数错误,参数不为number"); if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1); const decimal1 = new Decimal(num1);
const decimal2 = new Decimal(num2); const decimal2 = new Decimal(num2);
return decimal1.dividedBy(decimal2).toDecimalPlaces(digit, Decimal.ROUND_UP).toString(); const result = decimal1.dividedBy(decimal2);
return omit ? result.toFixed(digit, Decimal.ROUND_UP) : result.toDecimalPlaces(digit, Decimal.ROUND_UP).toString();
}; };
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</div> </div>
<div class="project-table-list-haeder-right"> <div class="project-table-list-haeder-right">
<!-- 实体工程材料单位换算 --> <!-- 实体工程材料单位换算 -->
<el-button type="primary" size="medium" class="unit-conversion-btn" v-if="currentParentName.indexOf('实体工程材料') != -1">单位换算</el-button> <el-button type="primary" size="medium" class="unit-conversion-btn" v-if="isEntityMaterials">单位换算</el-button>
<!-- 填写实际成本 --> <!-- 填写实际成本 -->
<el-button type="primary" size="medium" class="actual-cost-btn" v-else <el-button type="primary" size="medium" class="actual-cost-btn" v-else
@click="addActualCostEditStatus ? saveActualCost() : fillActualCost()">{{addActualCostEditStatus ? '保存成本' : '填写实际成本'}}</el-button> @click="addActualCostEditStatus ? saveActualCost() : fillActualCost()">{{addActualCostEditStatus ? '保存成本' : '填写实际成本'}}</el-button>
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
<!-- 数据列表部分 --> <!-- 数据列表部分 -->
<div class="project-feedsummary-list-container"> <div class="project-feedsummary-list-container">
<dsk-skeleton v-if="tableLoading"></dsk-skeleton> <dsk-skeleton v-if="tableLoading"></dsk-skeleton>
<el-form :model="dataForm" ref="feedSummaryForm" :show-message="false" v-else-if="!tableLoading" class="feed-summary-form"> <!-- 非实体工程材料列表 -->
<el-form :model="dataForm" ref="feedSummaryForm" :show-message="false" v-else-if="!isEntityMaterials" class="feed-summary-form">
<custom-table :tableData="dataForm.tableDataList" :formColum="formColum" :max-height="true" :tableDataTotal="total" :paging="false" <custom-table :tableData="dataForm.tableDataList" :formColum="formColum" :max-height="true" :tableDataTotal="total" :paging="false"
:cell-class-name="cellClassName"> :cell-class-name="cellClassName">
<template slot="action-field-bar" slot-scope="scope"> <template slot="action-field-bar" slot-scope="scope">
...@@ -63,6 +64,18 @@ ...@@ -63,6 +64,18 @@
</template> </template>
</custom-table> </custom-table>
</el-form> </el-form>
<!-- 实体工程材料列表 -->
<entity-materials-table v-else-if="isEntityMaterials" :tableData="dataForm.tableDataList" :formColum="entityMaterialsFormColum"
:max-height="true" :tableDataTotal="total" :paging="false" @selectionChange="selectionChange">
<template slot="action-field-bar" slot-scope="scope">
<div class="project-action-field-bar">
<span class="push-project">推送工程量</span>
</div>
<span v-else>-</span>
</template>
</entity-materials-table>
</div> </div>
</div> </div>
</div> </div>
...@@ -78,6 +91,7 @@ import { getFeedSummaryMenuTreeApi, getFeedSummaryMonthListApi, getFeedSummaryLi ...@@ -78,6 +91,7 @@ import { getFeedSummaryMenuTreeApi, getFeedSummaryMonthListApi, getFeedSummaryLi
import DskTableHeaderSetting from "@/components/DskTableHeaderSetting"; import DskTableHeaderSetting from "@/components/DskTableHeaderSetting";
import DskSkeleton from "@/components/DskSkeleton"; import DskSkeleton from "@/components/DskSkeleton";
import CustomTable from "@/components/CustomTable"; import CustomTable from "@/components/CustomTable";
import EntityMaterialsTable from "@/components/CustomTable";
import AddActualCost from "./components/AddActualCost"; import AddActualCost from "./components/AddActualCost";
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import dayjs from "dayjs"; import dayjs from "dayjs";
...@@ -130,12 +144,18 @@ export default { ...@@ -130,12 +144,18 @@ export default {
handler(newValue) { handler(newValue) {
this.comProjectId = newValue; this.comProjectId = newValue;
} }
},
recordDate: {
handler(newValue, oldValue) {
this.oldRecordDate = newValue;
}
} }
}, },
components: { components: {
ProjectSideMenu, ProjectSideMenu,
DskTableHeaderSetting, DskTableHeaderSetting,
CustomTable, CustomTable,
EntityMaterialsTable,
DskSkeleton, DskSkeleton,
AddActualCost AddActualCost
}, },
...@@ -194,6 +214,11 @@ export default { ...@@ -194,6 +214,11 @@ export default {
{ label: '备注', prop: "remark", width: "115", uid: v4(), slot: true }, { label: '备注', prop: "remark", width: "115", uid: v4(), slot: true },
{ label: '操作', prop: "action-field-bar", width: "99", uid: v4(), fixed: "right" }, { label: '操作', prop: "action-field-bar", width: "99", uid: v4(), fixed: "right" },
], ],
// 实体工程材料表头
entityMaterialsFormColum: [
{ label: '多选', prop: "staticSerialNumber", type: "selection", lock: true, width: "53", fixed: false, uid: v4() },
{ label: '操作', prop: "action-field-bar", width: "99", uid: v4(), fixed: "right" },
],
// 已记录月份集合 // 已记录月份集合
monthList: [], monthList: [],
// 源数据月份 // 源数据月份
...@@ -238,11 +263,15 @@ export default { ...@@ -238,11 +263,15 @@ export default {
computed: { computed: {
hasTarget() { hasTarget() {
return this.statisticsParentName.includes(this.currentParentName); return this.statisticsParentName.includes(this.currentParentName);
},
// 实体工程材料
isEntityMaterials() {
return this.currentParentName.indexOf('实体工程材料') != -1;
} }
}, },
//方法集 //方法集
methods: { methods: {
async init(detail = {}) { async init(detail = {}, resetDate = "") {
try { try {
this.resetEditStatus(); this.resetEditStatus();
const { projectId, cbStage } = detail; const { projectId, cbStage } = detail;
...@@ -253,14 +282,14 @@ export default { ...@@ -253,14 +282,14 @@ export default {
}; };
await this.getFeedSummaryMenuTree(params); await this.getFeedSummaryMenuTree(params);
await this.getFeedSummaryMonthList(params); await this.getFeedSummaryMonthList(params);
await this.initDefaultSetting(); await this.initDefaultSetting(resetDate);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} finally { } finally {
this.tableLoading = false; this.tableLoading = false;
} }
}, },
async initDefaultSetting() { async initDefaultSetting(resetDate = "") {
try { try {
await this.$nextTick(); await this.$nextTick();
const menus = this.$refs["projectSideMenu"].getResultMenuList(); const menus = this.$refs["projectSideMenu"].getResultMenuList();
...@@ -270,7 +299,7 @@ export default { ...@@ -270,7 +299,7 @@ export default {
this.currentNodeName = defaultCurrent.nodeName; this.currentNodeName = defaultCurrent.nodeName;
const parentName = defaultCurrent.parent ? this.getCurrentType(defaultCurrent.parent) : defaultCurrent.name; const parentName = defaultCurrent.parent ? this.getCurrentType(defaultCurrent.parent) : defaultCurrent.name;
if (parentName) this.currentParentName = parentName; if (parentName) this.currentParentName = parentName;
const params = this.createRequestConditions(); const params = this.createRequestConditions(resetDate);
await this.getFeedSummaryList(params); await this.getFeedSummaryList(params);
} }
} catch (error) { } catch (error) {
...@@ -280,16 +309,18 @@ export default { ...@@ -280,16 +309,18 @@ export default {
getNowMonth() { getNowMonth() {
return dayjs(new Date().valueOf()).format("YYYYMM"); return dayjs(new Date().valueOf()).format("YYYYMM");
}, },
createRequestConditions() { createRequestConditions(resetDate = "") {
const { projectId, cbStage } = this.comProjectDetailInfo; const { projectId, cbStage } = this.comProjectDetailInfo;
const params = { const params = {
projectId, projectId,
cbStage cbStage
}; };
params["cbSubjectName"] = this.currentNodeName; params["cbSubjectName"] = this.currentNodeName;
// 判断当月是否存在于server返回month集合中 // 判断当月是否存在于server返回month集合中 有传入的重置时间 采用重置时间
const _now = this.getNowMonth(); const _now = this.getNowMonth();
if (this.includeNowMonth(_now)) { if (resetDate && this.includeNowMonth(resetDate)) {
params["recordDate"] = resetDate;
} else if (this.includeNowMonth(_now)) {
params["recordDate"] = _now; params["recordDate"] = _now;
} }
return params; return params;
...@@ -373,7 +404,7 @@ export default { ...@@ -373,7 +404,7 @@ export default {
this.originMonthList = cloneDeep(data); this.originMonthList = cloneDeep(data);
const _now = this.getNowMonth(); const _now = this.getNowMonth();
this.recordDate = _now; this.recordDate = _now;
this.oldRecordDate = _now; // this.oldRecordDate = _now;
// 默认以当前月数据为准 若不包含当前月 需要手动push数据 // 默认以当前月数据为准 若不包含当前月 需要手动push数据
if (!data.includes(_now)) { if (!data.includes(_now)) {
data.push(_now); data.push(_now);
...@@ -405,16 +436,14 @@ export default { ...@@ -405,16 +436,14 @@ export default {
const _now = this.getNowMonth(); const _now = this.getNowMonth();
// 请求列表参数 // 请求列表参数
const params = this.createRequestConditions(); const params = this.createRequestConditions();
// 清空了年月默认选中当前月 // 清空了年月 默认选中当前月
if (!month) { if (!month) {
this.recordDate = _now; this.recordDate = _now;
// 如果命中的旧月份 等于当前月 且 不处于编辑状态 说明清空的是当前月 不调用接口 // 如果命中的旧月份 等于当前月 且 不处于编辑状态 说明清空的是默认查询月 不调用接口
if (this.oldRecordDate == _now && !this.addActualCostEditStatus) return; if (this.oldRecordDate == _now && !this.addActualCostEditStatus) return;
} else { } else {
// 正常选择 // 正常选择
params["recordDate"] = month; params["recordDate"] = month;
// 记录历史切换年月
this.oldRecordDate = month;
} }
this.resetEditStatus(); this.resetEditStatus();
// 获取列表数据 // 获取列表数据
...@@ -425,10 +454,9 @@ export default { ...@@ -425,10 +454,9 @@ export default {
this.currentNodeName = currentId; this.currentNodeName = currentId;
const parentName = currentTemp.parent ? this.getCurrentType(currentTemp.parent) : currentId; const parentName = currentTemp.parent ? this.getCurrentType(currentTemp.parent) : currentId;
if (parentName) this.currentParentName = parentName; if (parentName) this.currentParentName = parentName;
// 请求数据列表 this.resetTableData();
const params = this.createRequestConditions(); // 实体工程材料
this.getFeedSummaryList(params); if (this.isEntityMaterials) {
if (this.currentParentName.indexOf('实体工程材料') != -1) {
const { projectId, cbStage } = this.comProjectDetailInfo; const { projectId, cbStage } = this.comProjectDetailInfo;
const params = { const params = {
projectId, projectId,
...@@ -441,6 +469,10 @@ export default { ...@@ -441,6 +469,10 @@ export default {
params["recordDate"] = _now; params["recordDate"] = _now;
} }
this.getFeedSummaryConversionNotice(params); this.getFeedSummaryConversionNotice(params);
} else {
// 非实体工程材料 获取数据
const params = this.createRequestConditions(this.recordDate);
this.getFeedSummaryList(params);
} }
}, },
async getFeedSummaryConversionNotice(params) { async getFeedSummaryConversionNotice(params) {
...@@ -458,7 +490,16 @@ export default { ...@@ -458,7 +490,16 @@ export default {
message: '已取消删除' message: '已取消删除'
}); });
}); });
} else if (data.data instanceof Array) {
const _temp = data.data;
this.$set(this.dataForm, "tableDataList", cloneDeep(_temp));
this.originTableDataList = cloneDeep(_temp);
this.total = _temp.length;
} }
},
// 复选框回调
selectionChange(array) {
}, },
getCurrentType(parent) { getCurrentType(parent) {
if (parent.level == 2) { if (parent.level == 2) {
...@@ -515,6 +556,7 @@ export default { ...@@ -515,6 +556,7 @@ export default {
this.resetEditStatus(); this.resetEditStatus();
const params = this.createRequestConditions(); const params = this.createRequestConditions();
await this.getFeedSummaryList(params); await this.getFeedSummaryList(params);
return;
} }
// 有差异提交数据 // 有差异提交数据
resultData = resultData.map(item => { resultData = resultData.map(item => {
...@@ -529,7 +571,8 @@ export default { ...@@ -529,7 +571,8 @@ export default {
const result = await updateFeedSummaryRowsApi(resultData); const result = await updateFeedSummaryRowsApi(resultData);
if (result.code == 200) { if (result.code == 200) {
this.$message.success("保存成功"); this.$message.success("保存成功");
await this.init(this.comProjectDetailInfo); await this.init(this.comProjectDetailInfo, this.selectActualCostTime);
await this.editRegionToViewPort();
} }
} }
}); });
...@@ -556,9 +599,10 @@ export default { ...@@ -556,9 +599,10 @@ export default {
this.addActualCostEditStatus = false; this.addActualCostEditStatus = false;
this.selectActualCostTime = ""; this.selectActualCostTime = "";
/** /**
* 判断 当前需要编辑 或者新增的成本年份是否存在于server返回的month数组中 * 判断 当前需要编辑 或者新增的成本年份是否存在于server返回的month数组中 不存在则删除 该月份 然后 选中当前月
* 默认本月 * 默认本月
*/ */
if (!_selectActualCostTime) return;
if (!this.originMonthList.includes(_selectActualCostTime) && _selectActualCostTime != this.getNowMonth()) { if (!this.originMonthList.includes(_selectActualCostTime) && _selectActualCostTime != this.getNowMonth()) {
const index = this.monthList.findIndex(item => item.value == _selectActualCostTime); const index = this.monthList.findIndex(item => item.value == _selectActualCostTime);
if (index != -1) { if (index != -1) {
...@@ -567,6 +611,12 @@ export default { ...@@ -567,6 +611,12 @@ export default {
} }
} }
}, },
// 重置表格数据
resetTableData() {
this.$set(this.dataForm, "tableDataList", []);
this.originTableDataList = [];
this.total = 0;
},
async timeSelect(selectTime) { async timeSelect(selectTime) {
// 编辑状态 // 编辑状态
this.addActualCostEditStatus = true; this.addActualCostEditStatus = true;
...@@ -582,11 +632,10 @@ export default { ...@@ -582,11 +632,10 @@ export default {
value: selectTime value: selectTime
}); });
_temp = this.monthsSort(_temp); _temp = this.monthsSort(_temp);
console.log(_temp); // console.log(_temp);
this.monthList = _temp; this.monthList = _temp;
} }
this.recordDate = selectTime; this.recordDate = selectTime;
this.oldRecordDate = selectTime;
params["recordDate"] = selectTime; params["recordDate"] = selectTime;
// 获取选中月数据 // 获取选中月数据
await this.getFeedSummaryList(params); await this.getFeedSummaryList(params);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment