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) => {
if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1);
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) => {
* @param {*} num2
* @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");
if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1);
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) => {
* @param {*} num2
* @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");
if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1);
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) => {
* @param {*} num2
* @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");
if (flag) throw new Error("传入参数错误,参数不为number");
const decimal1 = new Decimal(num1);
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 @@
</div>
<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
@click="addActualCostEditStatus ? saveActualCost() : fillActualCost()">{{addActualCostEditStatus ? '保存成本' : '填写实际成本'}}</el-button>
......@@ -35,7 +35,8 @@
<!-- 数据列表部分 -->
<div class="project-feedsummary-list-container">
<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"
:cell-class-name="cellClassName">
<template slot="action-field-bar" slot-scope="scope">
......@@ -63,6 +64,18 @@
</template>
</custom-table>
</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>
......@@ -78,6 +91,7 @@ import { getFeedSummaryMenuTreeApi, getFeedSummaryMonthListApi, getFeedSummaryLi
import DskTableHeaderSetting from "@/components/DskTableHeaderSetting";
import DskSkeleton from "@/components/DskSkeleton";
import CustomTable from "@/components/CustomTable";
import EntityMaterialsTable from "@/components/CustomTable";
import AddActualCost from "./components/AddActualCost";
import { v4 } from 'uuid';
import dayjs from "dayjs";
......@@ -130,12 +144,18 @@ export default {
handler(newValue) {
this.comProjectId = newValue;
}
},
recordDate: {
handler(newValue, oldValue) {
this.oldRecordDate = newValue;
}
}
},
components: {
ProjectSideMenu,
DskTableHeaderSetting,
CustomTable,
EntityMaterialsTable,
DskSkeleton,
AddActualCost
},
......@@ -194,6 +214,11 @@ export default {
{ label: '备注', prop: "remark", width: "115", uid: v4(), slot: true },
{ 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: [],
// 源数据月份
......@@ -238,11 +263,15 @@ export default {
computed: {
hasTarget() {
return this.statisticsParentName.includes(this.currentParentName);
},
// 实体工程材料
isEntityMaterials() {
return this.currentParentName.indexOf('实体工程材料') != -1;
}
},
//方法集
methods: {
async init(detail = {}) {
async init(detail = {}, resetDate = "") {
try {
this.resetEditStatus();
const { projectId, cbStage } = detail;
......@@ -253,14 +282,14 @@ export default {
};
await this.getFeedSummaryMenuTree(params);
await this.getFeedSummaryMonthList(params);
await this.initDefaultSetting();
await this.initDefaultSetting(resetDate);
} catch (error) {
console.log(error);
} finally {
this.tableLoading = false;
}
},
async initDefaultSetting() {
async initDefaultSetting(resetDate = "") {
try {
await this.$nextTick();
const menus = this.$refs["projectSideMenu"].getResultMenuList();
......@@ -270,7 +299,7 @@ export default {
this.currentNodeName = defaultCurrent.nodeName;
const parentName = defaultCurrent.parent ? this.getCurrentType(defaultCurrent.parent) : defaultCurrent.name;
if (parentName) this.currentParentName = parentName;
const params = this.createRequestConditions();
const params = this.createRequestConditions(resetDate);
await this.getFeedSummaryList(params);
}
} catch (error) {
......@@ -280,16 +309,18 @@ export default {
getNowMonth() {
return dayjs(new Date().valueOf()).format("YYYYMM");
},
createRequestConditions() {
createRequestConditions(resetDate = "") {
const { projectId, cbStage } = this.comProjectDetailInfo;
const params = {
projectId,
cbStage
};
params["cbSubjectName"] = this.currentNodeName;
// 判断当月是否存在于server返回month集合中
// 判断当月是否存在于server返回month集合中 有传入的重置时间 采用重置时间
const _now = this.getNowMonth();
if (this.includeNowMonth(_now)) {
if (resetDate && this.includeNowMonth(resetDate)) {
params["recordDate"] = resetDate;
} else if (this.includeNowMonth(_now)) {
params["recordDate"] = _now;
}
return params;
......@@ -373,7 +404,7 @@ export default {
this.originMonthList = cloneDeep(data);
const _now = this.getNowMonth();
this.recordDate = _now;
this.oldRecordDate = _now;
// this.oldRecordDate = _now;
// 默认以当前月数据为准 若不包含当前月 需要手动push数据
if (!data.includes(_now)) {
data.push(_now);
......@@ -405,16 +436,14 @@ export default {
const _now = this.getNowMonth();
// 请求列表参数
const params = this.createRequestConditions();
// 清空了年月默认选中当前月
// 清空了年月 默认选中当前月
if (!month) {
this.recordDate = _now;
// 如果命中的旧月份 等于当前月 且 不处于编辑状态 说明清空的是当前月 不调用接口
// 如果命中的旧月份 等于当前月 且 不处于编辑状态 说明清空的是默认查询月 不调用接口
if (this.oldRecordDate == _now && !this.addActualCostEditStatus) return;
} else {
// 正常选择
params["recordDate"] = month;
// 记录历史切换年月
this.oldRecordDate = month;
}
this.resetEditStatus();
// 获取列表数据
......@@ -425,10 +454,9 @@ export default {
this.currentNodeName = currentId;
const parentName = currentTemp.parent ? this.getCurrentType(currentTemp.parent) : currentId;
if (parentName) this.currentParentName = parentName;
// 请求数据列表
const params = this.createRequestConditions();
this.getFeedSummaryList(params);
if (this.currentParentName.indexOf('实体工程材料') != -1) {
this.resetTableData();
// 实体工程材料
if (this.isEntityMaterials) {
const { projectId, cbStage } = this.comProjectDetailInfo;
const params = {
projectId,
......@@ -441,6 +469,10 @@ export default {
params["recordDate"] = _now;
}
this.getFeedSummaryConversionNotice(params);
} else {
// 非实体工程材料 获取数据
const params = this.createRequestConditions(this.recordDate);
this.getFeedSummaryList(params);
}
},
async getFeedSummaryConversionNotice(params) {
......@@ -458,7 +490,16 @@ export default {
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) {
if (parent.level == 2) {
......@@ -515,6 +556,7 @@ export default {
this.resetEditStatus();
const params = this.createRequestConditions();
await this.getFeedSummaryList(params);
return;
}
// 有差异提交数据
resultData = resultData.map(item => {
......@@ -529,7 +571,8 @@ export default {
const result = await updateFeedSummaryRowsApi(resultData);
if (result.code == 200) {
this.$message.success("保存成功");
await this.init(this.comProjectDetailInfo);
await this.init(this.comProjectDetailInfo, this.selectActualCostTime);
await this.editRegionToViewPort();
}
}
});
......@@ -556,9 +599,10 @@ export default {
this.addActualCostEditStatus = false;
this.selectActualCostTime = "";
/**
* 判断 当前需要编辑 或者新增的成本年份是否存在于server返回的month数组中
* 判断 当前需要编辑 或者新增的成本年份是否存在于server返回的month数组中 不存在则删除 该月份 然后 选中当前月
* 默认本月
*/
if (!_selectActualCostTime) return;
if (!this.originMonthList.includes(_selectActualCostTime) && _selectActualCostTime != this.getNowMonth()) {
const index = this.monthList.findIndex(item => item.value == _selectActualCostTime);
if (index != -1) {
......@@ -567,6 +611,12 @@ export default {
}
}
},
// 重置表格数据
resetTableData() {
this.$set(this.dataForm, "tableDataList", []);
this.originTableDataList = [];
this.total = 0;
},
async timeSelect(selectTime) {
// 编辑状态
this.addActualCostEditStatus = true;
......@@ -582,11 +632,10 @@ export default {
value: selectTime
});
_temp = this.monthsSort(_temp);
console.log(_temp);
// console.log(_temp);
this.monthList = _temp;
}
this.recordDate = selectTime;
this.oldRecordDate = selectTime;
params["recordDate"] = selectTime;
// 获取选中月数据
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