|
@@ -0,0 +1,677 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 变更令详细页js
|
|
|
+ *
|
|
|
+ * @author EllisRan.
|
|
|
+ * @date 2018/11/22
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+// 编号排序,多重判断
|
|
|
+function sortByCode(a, b) {
|
|
|
+ let code1 = a.code.split('-');
|
|
|
+ let code2 = b.code.split('-');
|
|
|
+ let code1length = code1.length;
|
|
|
+ let code2length = code2.length;
|
|
|
+ for (let i = 0; i < code1length; i ++) {
|
|
|
+ if (i+1 <= code2length) {
|
|
|
+ if (code1[i] != code2[i]) {
|
|
|
+ if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
|
|
|
+ return parseInt(code1[i]) - parseInt(code2[i]);
|
|
|
+ } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
|
|
|
+ return 1;
|
|
|
+ } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
|
|
|
+ return -1;
|
|
|
+ } else {
|
|
|
+ const str1length = code1[i].length;
|
|
|
+ const str2length = code2[i].length;
|
|
|
+ for (let j = 0; j < str1length; j++) {
|
|
|
+ if (j+1 <= str2length) {
|
|
|
+ if (code1[i].charAt(j) != code2[i].charAt(j)) {
|
|
|
+ return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
|
|
|
+ } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
|
|
|
+ if (str1length == str2length) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ return str1length - str2length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (j+1 >= str1length) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (i+1 == code1length && code1[i] == code2[i]) {
|
|
|
+ if (code1length == code2length) {
|
|
|
+ return 0;
|
|
|
+ } else {
|
|
|
+ return code1length - code2length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (i+1 >= code1length) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+let searchCodeList = [];
|
|
|
+$(document).ready(() => {
|
|
|
+ let searchGcl;
|
|
|
+ autoFlashHeight();
|
|
|
+ const gclSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@'},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 300, formatter: '@'},
|
|
|
+ {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 100, formatter: '@'},
|
|
|
+ {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 100},
|
|
|
+ {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [25, 25],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: true,
|
|
|
+ rowHeader:[
|
|
|
+ {
|
|
|
+ rowHeaderType: 'circle',
|
|
|
+ setting: {
|
|
|
+ size: 5,
|
|
|
+ indent: 16,
|
|
|
+ getColor: function (index, data) {
|
|
|
+ if (!data) return;
|
|
|
+ if (data.cid) {
|
|
|
+ return '#dc3545';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ localCache: {
|
|
|
+ key: 'change-add-list-gcl-spread',
|
|
|
+ colWidth: true,
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ gclSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
|
|
|
+ if (data && data.settle_status && data.settle_status === settleStatus.finish) {
|
|
|
+ return spreadColor.stage.settle;
|
|
|
+ }
|
|
|
+ if (data && data.is_change) {
|
|
|
+ return '#c3e6cb';
|
|
|
+ }
|
|
|
+ return defaultColor;
|
|
|
+ }
|
|
|
+
|
|
|
+ const gclSpreadObj = {
|
|
|
+ resetXmjSpread: function(data = null) {
|
|
|
+ const xmjs = [];
|
|
|
+ if (data && data.id) {
|
|
|
+ xmjs.push({
|
|
|
+ cid: '',
|
|
|
+ is_change: _.findIndex(changeList, { lid: data.id }) !== -1 ? 1 : 0,
|
|
|
+ code: '',
|
|
|
+ jldy: '',
|
|
|
+ dwgc: '',
|
|
|
+ fbgc: '',
|
|
|
+ fxgc: '',
|
|
|
+ bwmx: '',
|
|
|
+ quantity: '',
|
|
|
+ })
|
|
|
+ } else if (data && data.leafXmjs) {
|
|
|
+ for (const leaf of data.leafXmjs) {
|
|
|
+ xmjs.push({
|
|
|
+ is_change: _.findIndex(changeList, { gcl_id: leaf.gcl_id, mx_id: leaf.mx_id || '' }) !== -1 ? 1 : 0,
|
|
|
+ cid: leaf.cid || '',
|
|
|
+ code: leaf.code,
|
|
|
+ jldy: leaf.jldy || '',
|
|
|
+ dwgc: leaf.dwgc || '',
|
|
|
+ fbgc: leaf.fbgc || '',
|
|
|
+ fxgc: leaf.fxgc || '',
|
|
|
+ bwmx: leaf.bwmx || '',
|
|
|
+ quantity: leaf.quantity ? ZhCalc.round(leaf.quantity, findDecimal(data.unit)).toString() : '0',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SpreadJsObj.loadSheetData(xmjSpreadSheet, SpreadJsObj.DataType.Data, xmjs);
|
|
|
+ checkSelectAll();
|
|
|
+ },
|
|
|
+ selectionChanged: function (e, info) {
|
|
|
+ const data = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ gclSpreadObj.resetXmjSpread(data);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const xmjSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ { title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList'},
|
|
|
+ {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
|
|
|
+ {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 150, formatter: '@', readOnly: true},
|
|
|
+ {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 150, formatter: '@', readOnly: true},
|
|
|
+ {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 150, readOnly: true},
|
|
|
+ {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 150, readOnly: true},
|
|
|
+ {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 150, readOnly: true},
|
|
|
+ {title: '数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, readOnly: true},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 2,
|
|
|
+ headRowHeight: [25, 25],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ rowHeader:[
|
|
|
+ {
|
|
|
+ rowHeaderType: 'circle',
|
|
|
+ setting: {
|
|
|
+ size: 5,
|
|
|
+ indent: 16,
|
|
|
+ getColor: function (index, data) {
|
|
|
+ if (!data) return;
|
|
|
+ if (data.cid) {
|
|
|
+ return '#dc3545';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+
|
|
|
+ const xmjCol = {
|
|
|
+ readOnly: {
|
|
|
+ isChangeList: function (data) {
|
|
|
+ if (!data) return true;
|
|
|
+ return !readOnly;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
|
|
|
+ let changeListData;
|
|
|
+ let gclGatherData;
|
|
|
+ const gclSpread = SpreadJsObj.createNewSpread($('#gcl-spread')[0]);
|
|
|
+ const gclSpreadSheet = gclSpread.getActiveSheet();
|
|
|
+ const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
|
|
|
+ const xmjSpreadSheet = xmjSpread.getActiveSheet();
|
|
|
+ sjsSettingObj.setGridSelectStyle(gclSpreadSetting);
|
|
|
+ SpreadJsObj.initSheet(gclSpreadSheet, gclSpreadSetting);
|
|
|
+ SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
|
|
|
+ SpreadJsObj.initSheet(xmjSpreadSheet, xmjSpreadSetting);
|
|
|
+ postData(preUrl + '/defaultBills', { from: 'batch' }, function (result) {
|
|
|
+ gclGatherModel.loadLedgerData(result.bills);
|
|
|
+ gclGatherModel.loadPosData(result.pos);
|
|
|
+
|
|
|
+ gclGatherData = gclGatherModel.gatherGclData();
|
|
|
+ gclGatherData = _.filter(gclGatherData, function (item) {
|
|
|
+ return item.leafXmjs && item.leafXmjs.length !== 0;
|
|
|
+ });
|
|
|
+ for (const ggd in gclGatherData) {
|
|
|
+ if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
|
|
|
+ gclGatherData.splice(ggd, 1);
|
|
|
+ }
|
|
|
+ gclGatherData[ggd].code = gclGatherData[ggd].b_code;
|
|
|
+ let hadcid = 0;
|
|
|
+ for (const xmj of gclGatherData[ggd].leafXmjs) {
|
|
|
+ const changeLedger = _.find(result.changeLedgerList, { id: xmj.gcl_id });
|
|
|
+ const changePos = _.find(result.changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
|
|
|
+ if (changeLedger || changePos) {
|
|
|
+ xmj.cid = 1;
|
|
|
+ xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
|
|
|
+ hadcid = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hadcid !== 0) gclGatherData[ggd].cid = 1;
|
|
|
+ }
|
|
|
+ // 数组去重
|
|
|
+ const dealBillList = result.dealBills;
|
|
|
+ for (const db of gclGatherData) {
|
|
|
+ const exist_index = dealBillList.findIndex(function (item) {
|
|
|
+ return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
|
|
|
+ });
|
|
|
+ if (exist_index !== -1) {
|
|
|
+ dealBillList.splice(exist_index, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
|
|
|
+ for (const gcl of changeListData) {
|
|
|
+ gcl.unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
|
|
|
+ gcl.quantity = gcl.quantity !== 0 && gcl.quantity !== null && gcl.quantity !== undefined ? (gcl.unit !== '' ? ZhCalc.round(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity).toString() : '0';
|
|
|
+ gcl.unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? ZhCalc.round(gcl.unit_price, unitPriceUnit) : 0;
|
|
|
+ // 用id值区分签约清单和台账
|
|
|
+ if (gcl.id) {
|
|
|
+ const cInfo = gcl.id ? _.find(changeList, { lid: gcl.id }) : null;
|
|
|
+ gcl.is_change = cInfo ? 1 : 0;
|
|
|
+ } else {
|
|
|
+ const index = gcl.leafXmjs && gcl.leafXmjs.length !== 0 ? _.findIndex(gcl.leafXmjs, function (item) {
|
|
|
+ return _.findIndex(changeList, { gcl_id: item.gcl_id }) !== -1;
|
|
|
+ }) : -1;
|
|
|
+ gcl.is_change = index !== -1 ? 1 : 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(changeListData);
|
|
|
+ SpreadJsObj.loadSheetData(gclSpreadSheet, SpreadJsObj.DataType.Data, changeListData);
|
|
|
+ gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
|
|
|
+ });
|
|
|
+ gclSpread.bind(spreadNS.Events.SelectionChanged, gclSpreadObj.selectionChanged);
|
|
|
+
|
|
|
+ $.divResizer({
|
|
|
+ select: '#revise-right-spr',
|
|
|
+ callback: function () {
|
|
|
+ gclSpread.refresh();
|
|
|
+ xmjSpread.refresh();
|
|
|
+ if (searchGcl) searchGcl.spread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $.subMenu({
|
|
|
+ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
|
|
|
+ toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
|
|
|
+ key: 'menu.1.0.0',
|
|
|
+ miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
|
|
|
+ callback: function (info) {
|
|
|
+ if (info.mini) {
|
|
|
+ $('.panel-title').addClass('fluid');
|
|
|
+ $('#sub-menu').removeClass('panel-sidebar');
|
|
|
+ } else {
|
|
|
+ $('.panel-title').removeClass('fluid');
|
|
|
+ $('#sub-menu').addClass('panel-sidebar');
|
|
|
+ }
|
|
|
+ autoFlashHeight();
|
|
|
+ gclSpread.refresh();
|
|
|
+ xmjSpread.refresh();
|
|
|
+ if (searchGcl) searchGcl.spread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ gclSpread.refresh();
|
|
|
+ xmjSpread.refresh();
|
|
|
+
|
|
|
+ // 展开收起标准节点
|
|
|
+ $('a', '#side-menu').bind('click', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ const tab = $(this), tabPanel = $(tab.attr('content'));
|
|
|
+ // 展开工具栏、切换标签
|
|
|
+ if (!tab.hasClass('active')) {
|
|
|
+ const close = $('.active', '#side-menu').length === 0;
|
|
|
+ $('a', '#side-menu').removeClass('active');
|
|
|
+ tab.addClass('active');
|
|
|
+ $('.tab-content .tab-pane').removeClass('active');
|
|
|
+ tabPanel.addClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ if (tab.attr('content') === '#search') {
|
|
|
+ if (!searchGcl) {
|
|
|
+ searchGcl = $.listSearch({
|
|
|
+ selector: '#search',
|
|
|
+ searchSpread: gclSpread,
|
|
|
+ searchOver: true,
|
|
|
+ searchEmpty: true,
|
|
|
+ resultSpreadSetting: {
|
|
|
+ cols: [
|
|
|
+ {title: '清单编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
|
|
|
+ {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
|
|
|
+ {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
|
|
|
+ {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
|
|
|
+ {title: '数量', field: 'quantity', hAlign: 2, width: 50},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ headColWidth: [30],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ readOnly: true,
|
|
|
+ },
|
|
|
+ afterLocated: function () {
|
|
|
+ gclSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(gclSpreadSheet));
|
|
|
+ },
|
|
|
+ check: function(data, keyword) {
|
|
|
+ return !keyword ||
|
|
|
+ (data.code && data.code.indexOf(keyword) > -1) ||
|
|
|
+ (data.name && data.name.indexOf(keyword) > -1);
|
|
|
+ },
|
|
|
+ customSearch: [
|
|
|
+ {
|
|
|
+ key: 'revise', title: '新增部位', valid: true, parent: true,
|
|
|
+ check: function (node) {
|
|
|
+ if (node.formc || node.cid) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ searchGcl.spread.refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {// 收起工具栏
|
|
|
+ tab.removeClass('active');
|
|
|
+ tabPanel.removeClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ }
|
|
|
+ gclSpread.refresh();
|
|
|
+ xmjSpread.refresh();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 回车提交
|
|
|
+ $('#list-input').on('keypress', function () {
|
|
|
+ if(window.event.keyCode === 13) {
|
|
|
+ $(this).blur();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#list-input').on('blur', function () {
|
|
|
+ const select = parseInt($('#select-list').val());
|
|
|
+ const value = _.trim($(this).val());
|
|
|
+ const valueList = _.slice(_.without(_.uniq(_.replace(_.replace(value, /\'|\"/g, ''), /\t/g, ' ').split(' ')), ''), 0, 10);
|
|
|
+ // console.log(valueList);
|
|
|
+ // 判断是否存在多个分词,以换行或空格分隔,多个则显示左侧菜单
|
|
|
+ if (value !== '' && valueList.length > 1) {
|
|
|
+ if (_.without(_.uniq(value.split(' ')), '').length > 10) {
|
|
|
+ toastr.warning('最多筛选以空格分割的前10个不重复关键词');
|
|
|
+ }
|
|
|
+ $('#table-list').addClass('col-9').removeClass('col-12');
|
|
|
+ $('#table-list').siblings('.col-3').show();
|
|
|
+ $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary"><td class="border-primary">全部</td></tr>');
|
|
|
+ for (const v of valueList) {
|
|
|
+ $('#list-search-keyword').append(`<tr data-keyword="${v}" class=""><td>${v}</td></tr>`);
|
|
|
+ }
|
|
|
+ $('#list-input').val(valueList.join(' '));
|
|
|
+ } else {
|
|
|
+ $('#table-list').addClass('col-12').removeClass('col-9');
|
|
|
+ $('#table-list').siblings('.col-3').hide();
|
|
|
+ $('#list-search-keyword').html('<tr data-keyword="" class="text-white bg-primary border-primary"><td class="border-primary">全部</td></tr>');
|
|
|
+ }
|
|
|
+ let showListData = changeListData;
|
|
|
+ if (select === 1 && value !== '') {
|
|
|
+ $(this).siblings('a').show();
|
|
|
+ showListData = _.filter(changeListData, function (c) {
|
|
|
+ let flag = false;
|
|
|
+ if (c.cid) {
|
|
|
+ for(const v of valueList) {
|
|
|
+ if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ // return ((c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1)) && c.cid;
|
|
|
+ });
|
|
|
+ } else if (select === 1 && value === '') {
|
|
|
+ $(this).siblings('a').hide();
|
|
|
+ showListData = _.filter(changeListData, function (c) {
|
|
|
+ return c.cid;
|
|
|
+ });
|
|
|
+ } else if (value !== '') {
|
|
|
+ $(this).siblings('a').show();
|
|
|
+ showListData = _.filter(changeListData, function (c) {
|
|
|
+ let flag = false;
|
|
|
+ for(const v of valueList) {
|
|
|
+ if ((c.code && c.code.indexOf(v) !== -1) || (c.name && c.name.indexOf(v) !== -1)) {
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ // return (c.code && c.code.indexOf(value) !== -1) || (c.name && c.name.indexOf(value) !== -1);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ $(this).siblings('a').hide();
|
|
|
+ }
|
|
|
+ makeListTable(changeListData, showListData);
|
|
|
+ $('#table-list-select tr').removeClass('table-warning');
|
|
|
+ $('#code-input').val('');
|
|
|
+ $('#code-input').siblings('a').hide();
|
|
|
+ $('#code-list').html('');
|
|
|
+ $('#code-select-all').prop('checked', false);
|
|
|
+ });
|
|
|
+ // 双击编辑搜索值
|
|
|
+ $('body').on('dblclick', '#list-search-keyword tr', function () {
|
|
|
+ if ($(this).attr('data-keyword') !== '') {
|
|
|
+ $(this).children('td').html(`<input class="form-control form-control-sm" value="">`);
|
|
|
+ $(this).find('input').focus();
|
|
|
+ $(this).find('input').val($(this).attr('data-keyword'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 光标离开
|
|
|
+ $('body').on('blur', '#list-search-keyword tr td input', function () {
|
|
|
+ let val = $(this).val();
|
|
|
+ const oldVal = $(this).parents('tr').attr('data-keyword');
|
|
|
+ if (_.trim(val) === '') {
|
|
|
+ toastr.warning('不能为空');
|
|
|
+ val = oldVal;
|
|
|
+ } else if (_.trim(val) === oldVal) {
|
|
|
+ val = oldVal;
|
|
|
+ } else {
|
|
|
+ const value = _.trim($('#list-input').val());
|
|
|
+ const valueList = _.slice(_.without(_.uniq(_.replace(value, /\t/g, ' ').split(' ')), ''), 0, 10);
|
|
|
+ // console.log(_.indexOf(valueList, oldVal), valueList, val, oldVal);
|
|
|
+ if (_.indexOf(valueList, val) !== -1) {
|
|
|
+ toastr.warning('已存在相同的检索词');
|
|
|
+ val = oldVal;
|
|
|
+ }
|
|
|
+ valueList.splice(_.indexOf(valueList, oldVal), 1, val);
|
|
|
+ $('#list-input').val(valueList.join(' '));
|
|
|
+ const select = parseInt($('#select-list').val());
|
|
|
+ const showListData = _.filter(changeListData, function (c) {
|
|
|
+ return ((c.code && c.code.indexOf(val) !== -1) || (c.name && c.name.indexOf(val) !== -1)) && (select === 1 ? c.cid : 1);
|
|
|
+ });
|
|
|
+ makeListTable(changeListData, showListData);
|
|
|
+ $('#table-list-select tr').removeClass('table-warning');
|
|
|
+ $('#code-input').val('');
|
|
|
+ $('#code-input').siblings('a').hide();
|
|
|
+ $('#code-list').html('');
|
|
|
+ $('#code-select-all').prop('checked', false);
|
|
|
+ }
|
|
|
+ $(this).parents('tr').attr('data-keyword', val);
|
|
|
+ $(this).parents('td').html(`${val}`);
|
|
|
+ });
|
|
|
+ $('body').on('keypress', '#list-search-keyword tr td input', function () {
|
|
|
+ if(window.event.keyCode === 13) {
|
|
|
+ $(this).blur();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $("#addlist").draggable({ handle: '.modal-header, .modal-footer'});
|
|
|
+ // 检索关键字切换
|
|
|
+ $('body').on('click', '#list-search-keyword tr', function () {
|
|
|
+ if (!$(this).hasClass('bg-primary')) {
|
|
|
+ const keyword = $(this).attr('data-keyword');
|
|
|
+ $(this).siblings().removeClass('text-white bg-primary');
|
|
|
+ $(this).siblings().children('td').removeClass('border-primary');
|
|
|
+ $(this).addClass('text-white bg-primary');
|
|
|
+ $(this).children('td').addClass('border-primary');
|
|
|
+ if (keyword === '') {
|
|
|
+ $('#list-input').blur();
|
|
|
+ } else {
|
|
|
+ const select = parseInt($('#select-list').val());
|
|
|
+ const showListData = _.filter(changeListData, function (c) {
|
|
|
+ return ((c.code && c.code.indexOf(keyword) !== -1) || (c.name && c.name.indexOf(keyword) !== -1)) && (select === 1 ? c.cid : 1);
|
|
|
+ });
|
|
|
+ makeListTable(changeListData, showListData);
|
|
|
+ $('#table-list-select tr').removeClass('table-warning');
|
|
|
+ $('#code-input').val('');
|
|
|
+ $('#code-input').siblings('a').hide();
|
|
|
+ $('#code-list').html('');
|
|
|
+ $('#code-select-all').prop('checked', false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 回车提交
|
|
|
+ $('#code-input').on('keypress', function () {
|
|
|
+ if(window.event.keyCode === 13) {
|
|
|
+ $(this).blur();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#code-input').on('blur', function () {
|
|
|
+ const value = $(this).val();
|
|
|
+ if (value !== '') {
|
|
|
+ $(this).siblings('a').show();
|
|
|
+ } else {
|
|
|
+ $(this).siblings('a').hide();
|
|
|
+ }
|
|
|
+ makeCodeTable($(this).val());
|
|
|
+ checkSelectAll();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.remove-btn').on('click', function () {
|
|
|
+ $(this).hide();
|
|
|
+ $(this).siblings('input').val('');
|
|
|
+ if ($(this).data('btn') === 'list') {
|
|
|
+ const select = parseInt($('#select-list').val());
|
|
|
+ let showListData = changeListData;
|
|
|
+ if (select === 1) {
|
|
|
+ showListData = _.filter(changeListData, function (c) {
|
|
|
+ return c.cid;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ makeListTable(changeListData, showListData);
|
|
|
+ $('#table-list-select tr').removeClass('table-warning');
|
|
|
+ $('#code-list').html('');
|
|
|
+ $('#table-list').addClass('col-12').removeClass('col-9');
|
|
|
+ $('#table-list').siblings('.col-3').hide();
|
|
|
+ $('#list-search-keyword').html('');
|
|
|
+ $('#list-search-keyword').siblings('a').addClass('active');
|
|
|
+ } else {
|
|
|
+ makeCodeTable();
|
|
|
+ }
|
|
|
+ checkSelectAll();
|
|
|
+ });
|
|
|
+ // 全选及取消
|
|
|
+ $('#code-select-all').click(function () {
|
|
|
+ // 全选checkbox
|
|
|
+ let index = $('#code-list').attr('data-index');
|
|
|
+ if (index) {
|
|
|
+ if ($(this).is(':checked')){
|
|
|
+ $('#code-list tr').each(function () {
|
|
|
+ if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
|
|
|
+ $(this).find('input').prop('checked', true);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ $('#code-list tr').each(function () {
|
|
|
+ if ($(this).css('display') !== 'none' && $(this).find('input').prop('disabled') !== true) {
|
|
|
+ $(this).find('input').prop('checked', false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 判断还有无选中项目节编号
|
|
|
+ if ($('#code-list input').is(':checked')) {
|
|
|
+ // 去除部分data-detail值
|
|
|
+ let data_bwmx = [];
|
|
|
+ let data_charu = [];
|
|
|
+ $('#code-list input:checked').each(function () {
|
|
|
+ const tr = $(this).parents('tr');
|
|
|
+ const length = tr.children('td').length;
|
|
|
+ const gcl_id = tr.attr('gcl_id');
|
|
|
+ const mx_id = tr.attr('mx_id');
|
|
|
+ const bwmx = length === 9 ?
|
|
|
+ tr.children('td').eq(1).text() + '!_!' +
|
|
|
+ tr.children('td').eq(2).text() + '!_!' +
|
|
|
+ tr.children('td').eq(3).text() + '!_!' +
|
|
|
+ tr.children('td').eq(4).text() + '!_!' +
|
|
|
+ tr.children('td').eq(5).text() + '!_!' + gcl_id + '!_!' + mx_id + '!_!' +
|
|
|
+ (tr.children('td').eq(6).text() !== '' ? tr.children('td').eq(6).text() : tr.children('td').eq(2).text()) : '0';
|
|
|
+ const quantity = tr.attr('quantity');
|
|
|
+ const de_qu = bwmx + '*;*' + quantity;
|
|
|
+ data_bwmx.push(de_qu);
|
|
|
+ if (changeOrder && $(this).prop('disabled') !== true) {
|
|
|
+ data_charu.push(de_qu);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data_bwmx = data_bwmx.join('$#$');
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', data_bwmx);
|
|
|
+ if (changeOrder) {
|
|
|
+ data_charu = data_charu.join('$#$');
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', data_charu);
|
|
|
+ }
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').addClass('table-success');
|
|
|
+ } else {
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').removeClass('table-success');
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').attr('data-bwmx', '');
|
|
|
+ if (changeOrder) {
|
|
|
+ $('#table-list-select tr[data-index="' + index + '"]').attr('data-charu', '');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 选中所有新增部位/清单
|
|
|
+ $('#select-all-revise').click(function() {
|
|
|
+ const qtySpr = '*;*', infoSpr = '!_!', recSpr = '$#$';
|
|
|
+ const gclTr = $('#table-list-select tr');
|
|
|
+ for (const tr of gclTr) {
|
|
|
+ const lid = $(tr).data('lid');
|
|
|
+ let gcl = _.find(gclGatherData, function (item) {
|
|
|
+ return item.leafXmjs && item.leafXmjs[0].gcl_id === lid;
|
|
|
+ });
|
|
|
+ if (!gcl) gcl = gclGatherData[$(this).data('gcl')];
|
|
|
+ if (!gcl || !gcl.cid) continue;
|
|
|
+
|
|
|
+ let data_bwmx = [];
|
|
|
+ if ($(tr).attr('data-bwmx') !== '') {
|
|
|
+ data_bwmx = $(tr).attr('data-bwmx').split(recSpr);
|
|
|
+ data_bwmx = data_bwmx.filter(x => {
|
|
|
+ const rec = x.split(qtySpr);
|
|
|
+ const info = rec[0].split(infoSpr);
|
|
|
+ if (info.length < 8) return true;
|
|
|
+
|
|
|
+ const leaf = gcl.leafXmjs.find(lx => { return lx.mx_id === info[6]});
|
|
|
+ return !leaf || !leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ let hasNew = false;
|
|
|
+ for (const [index, leaf] of gcl.leafXmjs.entries()) {
|
|
|
+ if (!leaf.cid || leaf.ccid !== window.location.pathname.split('/')[4]) continue;
|
|
|
+ const bwmx = [leaf.code, leaf.jldy || '', leaf.dwgc || '', leaf.fbgc || '', leaf.fxgc || '', leaf.gcl_id, leaf.mx_id, leaf.bwmx || leaf.jldy || ''];
|
|
|
+ const de_qu = bwmx.join(infoSpr) + qtySpr + (leaf.quantity || 0);
|
|
|
+ if (data_bwmx.indexOf(de_qu) < 0) data_bwmx.push(de_qu);
|
|
|
+ hasNew = true;
|
|
|
+ }
|
|
|
+ if (hasNew) $(tr).attr('data-bwmx', data_bwmx.join(recSpr)).addClass('table-success');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 触发点击当前清单,重载当前全部部位
|
|
|
+ const dataIndex = $('#code-list').attr('data-index');
|
|
|
+ if (dataIndex) {
|
|
|
+ $(`tr[data-index=${dataIndex}]`).trigger('click');
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|
|
|
+function checkSelectAll() {
|
|
|
+ let check = $('#code-list tr').length > 0 ? true : false;
|
|
|
+ const codeNum = $('#code-list tr').length;
|
|
|
+ let i = 0;
|
|
|
+ $('#code-list tr').each(function () {
|
|
|
+ if ($(this).css('display') !== 'none' && !$(this).find('input').is(':checked')) {
|
|
|
+ check = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if ($(this).css('display') === 'none') {
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (check && i === codeNum) {
|
|
|
+ check = false;
|
|
|
+ }
|
|
|
+ $('#code-select-all').prop('checked', check);
|
|
|
+}
|
|
|
+function findDecimal(unit) {
|
|
|
+ let value = precision.other.value;
|
|
|
+ const changeUnits = precision;
|
|
|
+ for (const d in changeUnits) {
|
|
|
+ if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
|
|
|
+ value = changeUnits[d].value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+}
|