|
@@ -0,0 +1,317 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+// class Stage_IM {
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * @param stage
|
|
|
+// * @param imType
|
|
|
+// */
|
|
|
+// constructor (stage, imType) {
|
|
|
+// this.stage = stage;
|
|
|
+// this.imType = imType;
|
|
|
+// this.gsTreeSetting = {
|
|
|
+// id: 'ledger_id',
|
|
|
+// pid: 'ledger_pid',
|
|
|
+// order: 'order',
|
|
|
+// level: 'level',
|
|
|
+// rootId: -1,
|
|
|
+// keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
+// };
|
|
|
+// this.gsTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'];
|
|
|
+// this.gsTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
|
|
|
+// this.gsTreeSetting.calcFun = function (node) {
|
|
|
+// if (node.children && node.children.length === 0) {
|
|
|
+// node.end_contract_qty = _.toNumber(node.pre_contract_qty) + _.toNumber(node.contract_qty);
|
|
|
+// node.end_qc_qty = _.toNumber(node.pre_qc_qty) + _.toNumber(node.qc_qty);
|
|
|
+// node.end_gather_qty = _.toNumber(node.pre_gather_qty) + _.toNumber(node.gather_qty);
|
|
|
+// }
|
|
|
+// node.gather_tp = _.toNumber(node.contract_tp) + _.toNumber(node.qc_tp);
|
|
|
+// node.end_contract_tp = _.toNumber(node.pre_contract_tp) + _.toNumber(node.contract_tp);
|
|
|
+// node.end_qc_tp = _.toNumber(node.pre_qc_tp) + _.toNumber(node.qc_tp);
|
|
|
+// node.end_gather_tp = _.toNumber(node.pre_gather_tp) + _.toNumber(node.gather_tp);
|
|
|
+// if (checkZero(node.dgn_qty1)) {
|
|
|
+// node.dgn_price = _.round(node.total_price/node.dgn_qty1, 2);
|
|
|
+// } else {
|
|
|
+// node.dgn_price = null;
|
|
|
+// }
|
|
|
+// };
|
|
|
+// this.splitChar = '-';
|
|
|
+// }
|
|
|
+//
|
|
|
+// initCheck() {
|
|
|
+// const gatherNodes = this.stage.im_gather_node ? _.map(this.stage.im_gather_node.split(','), _.toNumber) : [];
|
|
|
+// for (const node of this.gsTree.datas) {
|
|
|
+// node.check = gatherNodes.indexOf(node.id) !== -1;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// initData (ledger, curStage, stageDetail) {
|
|
|
+// this.gsTree = createNewPathTree('stage', this.gsTreeSetting);
|
|
|
+// this.gsTree.loadDatas(ledger);
|
|
|
+//
|
|
|
+// this.gsTree.loadCurStageData(curStage);
|
|
|
+// // 根据设置 计算 台账树结构
|
|
|
+// treeCalc.calculateAll(this.gsTree);
|
|
|
+//
|
|
|
+// this.initCheck();
|
|
|
+// this.stageDetail = stageDetail;
|
|
|
+// }
|
|
|
+//
|
|
|
+// getNumberFormat(num, length) {
|
|
|
+// let s = '0000000000';
|
|
|
+// s = s + count;
|
|
|
+// return s.substr(s.length - length);
|
|
|
+// }
|
|
|
+//
|
|
|
+// getNewImCode () {
|
|
|
+// return this.pre + this.getNumberFormat(this.stage.order, 2) + this.splitChar + this.getNumberFormat(this.ImData.length + 1, 3);
|
|
|
+// }
|
|
|
+//
|
|
|
+// getFbfx (node) {
|
|
|
+// // to do
|
|
|
+// return node.name;
|
|
|
+// }
|
|
|
+//
|
|
|
+// getJldy (node) {
|
|
|
+// return '';
|
|
|
+// }
|
|
|
+//
|
|
|
+// getPeg (node) {
|
|
|
+// return '';
|
|
|
+// }
|
|
|
+//
|
|
|
+// buildTzImData (nodes) {
|
|
|
+// if (!nodes || nodes.length === 0) { return; }
|
|
|
+//
|
|
|
+// for (const node of nodes) {
|
|
|
+// if (!node.code || node.code === '') { continue; }
|
|
|
+//
|
|
|
+// if (this.gsTree.isLeafXmj(node)) {
|
|
|
+// if (node.gather_tp) {
|
|
|
+// const im = {
|
|
|
+// code: node.code,
|
|
|
+// tp: node.gather_tp,
|
|
|
+// im_code: this.getNewImCode(),
|
|
|
+// fbfx: this.getFbfx(node),
|
|
|
+// jldy: this.getJldy(node),
|
|
|
+// peg: this.getPeg(node),
|
|
|
+// drawing_code: this.getDrawingCode(node),
|
|
|
+// };
|
|
|
+// this.ImData.push(im);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// this.buildTzImData(node.children);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// buildTzImGatherData (nodes) {
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// buildZlImData (nodes) {
|
|
|
+//
|
|
|
+// };
|
|
|
+//
|
|
|
+// buildZlImGatherData (nodes) {
|
|
|
+//
|
|
|
+// };
|
|
|
+//
|
|
|
+// buildImData () {
|
|
|
+// this.ImData = [];
|
|
|
+// this.pre = (this.stage.im_pre && this.stage.im_pre !== '') ? this.stage.im_pre + this.splitChar : '';
|
|
|
+// if (this.stage.im_type === imType.tz.value) {
|
|
|
+// if (this.ctx.stage.im_gather) {
|
|
|
+// this.initCheck();
|
|
|
+// this.buildTzImGatherData(this.gsTree.children);
|
|
|
+// } else {
|
|
|
+// this.buildTzImData(this.gsTree.children);
|
|
|
+// }
|
|
|
+// } else if (this.stage.im_type === imType.zl.value) {
|
|
|
+// if (this.stage.im_gather) {
|
|
|
+// this.initCheck();
|
|
|
+// this.buildZlImGatherData(this.gsTree.children);
|
|
|
+// } else {
|
|
|
+// this.buildZlImData(this.gsTree.children);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+const stageIm = (function () {
|
|
|
+ const splitChar = '-';
|
|
|
+ let stage, imType, details, ImData, pre;
|
|
|
+ const gsTreeSetting = {
|
|
|
+ id: 'ledger_id',
|
|
|
+ pid: 'ledger_pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
+ stageId: 'id',
|
|
|
+ };
|
|
|
+ gsTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'];
|
|
|
+ gsTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
|
|
|
+ gsTreeSetting.calcFun = function (node) {
|
|
|
+ if (node.children && node.children.length === 0) {
|
|
|
+ node.gather_qty = _.toNumber(node.contract_qty) + _.toNumber(node.qc_qty);
|
|
|
+ node.end_contract_qty = _.toNumber(node.pre_contract_qty) + _.toNumber(node.contract_qty);
|
|
|
+ node.end_qc_qty = _.toNumber(node.pre_qc_qty) + _.toNumber(node.qc_qty);
|
|
|
+ node.end_gather_qty = _.toNumber(node.pre_gather_qty) + _.toNumber(node.gather_qty);
|
|
|
+ }
|
|
|
+ node.gather_tp = _.toNumber(node.contract_tp) + _.toNumber(node.qc_tp);
|
|
|
+ node.end_contract_tp = _.toNumber(node.pre_contract_tp) + _.toNumber(node.contract_tp);
|
|
|
+ node.end_qc_tp = _.toNumber(node.pre_qc_tp) + _.toNumber(node.qc_tp);
|
|
|
+ node.end_gather_tp = _.toNumber(node.pre_gather_tp) + _.toNumber(node.gather_tp);
|
|
|
+ if (checkZero(node.dgn_qty1)) {
|
|
|
+ node.dgn_price = _.round(node.total_price/node.dgn_qty1, 2);
|
|
|
+ } else {
|
|
|
+ node.dgn_price = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const gsTree = createNewPathTree('stage', gsTreeSetting);
|
|
|
+
|
|
|
+ function init (s, i) {
|
|
|
+ stage = s;
|
|
|
+ imType = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ function initCheck () {
|
|
|
+ const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(','), _.toNumber) : [];
|
|
|
+ for (const node of gsTree.datas) {
|
|
|
+ node.check = gatherNodes.indexOf(node.id) !== -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function loadData (ledger, curStage, stageDetail) {
|
|
|
+ gsTree.loadDatas(ledger);
|
|
|
+
|
|
|
+ gsTree.loadCurStageData(curStage);
|
|
|
+ // 根据设置 计算 台账树结构
|
|
|
+ treeCalc.calculateAll(gsTree);
|
|
|
+
|
|
|
+ this.initCheck();
|
|
|
+ details = stageDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getNumberFormat(num, length) {
|
|
|
+ let s = '0000000000';
|
|
|
+ s = s + num;
|
|
|
+ return s.substr(s.length - length);
|
|
|
+ }
|
|
|
+
|
|
|
+ function getNewImCode () {
|
|
|
+ return pre + getNumberFormat(stage.order, 2) + splitChar + getNumberFormat(ImData.length + 1, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ function getFbfx (node) {
|
|
|
+ // to do
|
|
|
+ return node.name;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getJldy (node) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ function getPeg (node) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDrawingCode(node) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ function generateTzImData (node) {
|
|
|
+ if (node.gather_tp) {
|
|
|
+ const im = {
|
|
|
+ lid: node.id,
|
|
|
+ code: node.code,
|
|
|
+ jl: node.gather_tp,
|
|
|
+ im_code: getNewImCode(),
|
|
|
+ fbfx: getFbfx(node),
|
|
|
+ jldy: getJldy(node),
|
|
|
+ peg: getPeg(node),
|
|
|
+ drawing_code: getDrawingCode(node),
|
|
|
+ };
|
|
|
+ ImData.push(im);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function generateZlImData (node) {
|
|
|
+ const nodeImData = [], posterity = gsTree.getPosterity(node);
|
|
|
+ for (const p of posterity) {
|
|
|
+ if (p.children && p.children.length > 0 ) { continue; }
|
|
|
+ if (!p.b_code || p.b_code === '') { continue }
|
|
|
+ if (!p.gather_qty || p.gather_qty === 0 ) { continue; }
|
|
|
+ let im = nodeImData.find(function (d) {
|
|
|
+ return d.code === p.b_code && p.name === d.name && p.unit === d.unit && checkZero(p.unit_price - d.unit_price);
|
|
|
+ });
|
|
|
+ if (!im) {
|
|
|
+ im = {
|
|
|
+ lid: node.lid,
|
|
|
+ code: p.b_code,
|
|
|
+ name: p.name,
|
|
|
+ unit: p.unit,
|
|
|
+ unit_price: p.unit_price,
|
|
|
+ jl: 0,
|
|
|
+ im_code: getNewImCode(),
|
|
|
+ fbfx: getFbfx(node),
|
|
|
+ jldy: getJldy(node),
|
|
|
+ peg: getPeg(node),
|
|
|
+ drawing_code: getDrawingCode(node),
|
|
|
+ };
|
|
|
+ nodeImData.push(im);
|
|
|
+ ImData.push(im);
|
|
|
+ }
|
|
|
+ im.jl = _.add(im.jl, p.gather_qty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function recursiveBuildImData (nodes) {
|
|
|
+ if (!nodes || nodes.length === 0) { return; }
|
|
|
+ for (const node of nodes) {
|
|
|
+ if (gsTree.isLeafXmj(node) || (stage.im_gather && node.check)) {
|
|
|
+ if (stage.im_type === imType.tz.value) {
|
|
|
+ generateTzImData(node);
|
|
|
+ } else {
|
|
|
+ generateZlImData(node);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ recursiveBuildImData(node.children);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function buildImData () {
|
|
|
+ ImData = [];
|
|
|
+ pre = (stage.im_pre && stage.im_pre !== '') ? stage.im_pre + splitChar : '';
|
|
|
+ if (stage.im_gather) {
|
|
|
+ initCheck();
|
|
|
+ }
|
|
|
+ recursiveBuildImData(gsTree.children);
|
|
|
+ return ImData;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ getGsTree: function () {
|
|
|
+ return gsTree;
|
|
|
+ },
|
|
|
+ init,
|
|
|
+ initCheck,
|
|
|
+ loadData,
|
|
|
+ buildImData,
|
|
|
+ getImData: function () {
|
|
|
+ return ImData;
|
|
|
+ },
|
|
|
+ }
|
|
|
+})();
|