|
@@ -0,0 +1,66 @@
|
|
|
|
|
+const importMaterial = (function(){
|
|
|
|
|
+ let importNode, materials, callback;
|
|
|
|
|
+ const getMaterialHtml = function() {
|
|
|
|
|
+ const html = materials.map(x => {
|
|
|
|
|
+ const mh = [];
|
|
|
|
|
+ mh.push('<tr>');
|
|
|
|
|
+ mh.push(`<td class="text-center"><input type="checkbox" mid="${x.id}"></td>`);
|
|
|
|
|
+ mh.push(`<td class="text-center">${x.m_order}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-center">${x.s_order}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.info_tp}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.info_tax_tp}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.index_tp}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.index_tax_tp}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.sum_tp}</td>`);
|
|
|
|
|
+ mh.push(`<td class="text-right">${x.sum_tax_tp}</td>`);
|
|
|
|
|
+ mh.push('</tr>');
|
|
|
|
|
+ return mh.join('');
|
|
|
|
|
+ });
|
|
|
|
|
+ return html.join('');
|
|
|
|
|
+ };
|
|
|
|
|
+ const analysisMaterial = function(data) {
|
|
|
|
|
+ materials = data.map(x => {
|
|
|
|
|
+ const md = { id: x.id, order: x.order, m_order: `第${x.order}期`, s_order: x.s_order };
|
|
|
|
|
+ md.info_tp = x.m_tp || 0;
|
|
|
|
|
+ md.info_tax_tp = x.material_tax ? (x.m_tax_tp || x.m_tp || 0) : (x.rate_tp || 0);
|
|
|
|
|
+ md.index_tp = x.ex_tp || 0;
|
|
|
|
|
+ md.index_tax_tp = x.ex_tax_tp || 0;
|
|
|
|
|
+ md.sum_tp = ZhCalc.add(md.info_tp, md.index_tp);
|
|
|
|
|
+ md.sum_tax_tp = ZhCalc.add(md.info_tax_tp, md.index_tax_tp);
|
|
|
|
|
+ return md;
|
|
|
|
|
+ });
|
|
|
|
|
+ $('#import-material-list').html(getMaterialHtml())
|
|
|
|
|
+ };
|
|
|
|
|
+ const init = async function() {
|
|
|
|
|
+ if (materials) return;
|
|
|
|
|
+
|
|
|
|
|
+ const tenderId = window.location.pathname.split('/')[2];
|
|
|
|
|
+ postData(`/tender/${tenderId}/load`, { filter: 'materials' }, function(data) {
|
|
|
|
|
+ analysisMaterial(data.materials);
|
|
|
|
|
+ });
|
|
|
|
|
+ $('#import-material-ok').click(function() {
|
|
|
|
|
+ const selects = $('input[mid]:checked');
|
|
|
|
|
+ if (selects.length === 0) {
|
|
|
|
|
+ toastr.warning('请选择材料调差');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const selectId = [];
|
|
|
|
|
+ selects.each(function(){ selectId.push(this.getAttribute('mid')); });
|
|
|
|
|
+ const tpField = $('input[name=im-type]:checked').val() + ($('#im-data-tax')[0].checked ? '_tax_tp' : '_tp');
|
|
|
|
|
+ const tpFieldStr = '{' + $('input[name=im-type]:checked').attr('type-name') + '}' + ($('#im-data-tax')[0].checked ? '{{含税金额}}' : '{{金额}}');
|
|
|
|
|
+ const selectMaterials = materials.filter(x => { return selectId.indexOf(x.id + '') >= 0 });
|
|
|
|
|
+ const tp = ZhCalc.sum(selectMaterials.map(y => { return y[tpField]; }));
|
|
|
|
|
+ const memo = '第{' + selectMaterials.map(y => { return y.order; }).join(',') + `}期材差-${tpFieldStr}`;
|
|
|
|
|
+ callback(importNode, tp, memo);
|
|
|
|
|
+ $('#import-material').modal('hide');
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ const show = async function(setting) {
|
|
|
|
|
+ importNode = setting.relaNode;
|
|
|
|
|
+ callback = setting.callback;
|
|
|
|
|
+ await init();
|
|
|
|
|
+ $('input[mid]').attr('checked', false);
|
|
|
|
|
+ $('#import-material').modal('show');
|
|
|
|
|
+ };
|
|
|
|
|
+ return { show }
|
|
|
|
|
+})();
|