| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 | 'use strict';/** * 变更令详细页js * * @author EllisRan. * @date 2018/11/22 * @version */$.event.special.valuechange = {    teardown: function (namespaces) {        $(this).unbind('.valuechange');    },    handler: function (e) {        $.event.special.valuechange.triggerChanged($(this));    },    add: function (obj) {        $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)    },    triggerChanged: function (element) {        var current = element[0].contentEditable === 'true' ? element.html() : element.val()            , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');        if (current !== previous) {            element.trigger('valuechange', [element.data('previous')]);            element.data('previous', current);        }    }};$(document).ready(() => {    const changeSpreadSetting = {        cols: [            {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: true},            {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@'},            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@'},            {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@'},            {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},            {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@'},            {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@'},            {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, formatter: '@', visible: openChangeState},            {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount2'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp'},            {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},            {title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},            {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.sa_tp'},        ],        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 (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {                            return '#dc3545';                        }                        if(data.lid != 0) return;                        return '#007bff';                    }                },            },        ],        localCache: {            key: 'changes-spread',            colWidth: true,        }    };    for (const aid of aidList) {        // const userinfo = _.find(auditList2, { 'uid': aid });        const audit = _.find(auditors2, function(item){            return _.findIndex(item, { audit_order: aid }) !== -1;        });        const newColcount = {            title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',            colSpan: '2|1', rowSpan: '1|1',            field: 'audit_amount_' + aid,            hAlign: 2, width: 60, type: 'Number',        };        const newColTp = {            title: '|金额',            colSpan: '|1', rowSpan: '|1',            field: 'sa_tp_' + aid,            hAlign: 2, width: 80, type: 'Number',        };        changeSpreadSetting.cols.push(newColcount);        changeSpreadSetting.cols.push(newColTp);    }    changeSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.changed_amount'});    changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.changed_tp'});    changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {        return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;    }    const changeCol = {        getValue: {            unit_price: function(data) {                return ZhCalc.round(data.unit_price, unitPriceUnit);            },            oa_tp: function (data) {                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);            },            ca_tp: function (data) {                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);            },            oamount2: function (data) {                return ZhCalc.round(data.oamount2, findDecimal(data.unit));            },            camount: function (data) {                return ZhCalc.round(data.camount, findDecimal(data.unit));            },            samount: function (data) {                return ZhCalc.round(data.samount, findDecimal(data.unit));            },            sa_tp: function (data) {                return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit);            },            changed_amount: function (data) {                // return ZhCalc.round(ZhCalc.add(data.oamount, data.spamount), findDecimal(data.unit));                return ZhCalc.round(ZhCalc.add(data.oamount2, data.checked_amount), findDecimal(data.unit));            },            changed_tp: function (data) {                // return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit),                //     ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.spamount, findDecimal(data.unit))), totalPriceUnit));                return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),                    ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.checked_amount, findDecimal(data.unit))), totalPriceUnit));            },        },    };    const changeSpreadObj = {        makeSjsFooter: function () {            // 增加汇总行并设为锁定禁止编辑状态            changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');            const cellType1 = new GC.Spread.Sheets.CellTypes.Text();            changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);            changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);            changeSpreadObj.countSum();        },        resetXmjSpread: function(data = null) {            const xmj = [];            if (data && data.lid != 0) {                if (data.bwmx === data.xmj_jldy) {                    data.bwmx = '';                }                xmj.push(data);            }            SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);        },        selectionChanged: function (e, info) {            const sel = info.sheet.getSelections()[0];            const col = info.sheet.zh_setting.cols[sel.col];            const data = SpreadJsObj.getSelectObject(info.sheet);            if (col && col.field === 'camount' && data) {                $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);            } else {                $('#camount-expr').val('');            }            changeSpreadObj.resetXmjSpread(data);        },        setAuditValue: function () {            const rowCount = changeSpreadSheet.getRowCount();            // 用户的数据合计            for (const j in aidList) {                for(let i = 0; i <= rowCount - 1; i++){                    const data = {                        unit_price: changeSpreadSheet.getValue(i, 4),                        amount: parseFloat(changeSpreadSheet.getValue(i, startLimit + 5 + parseInt(j)*2)),                    };                    const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);                    changeSpreadSheet.setValue(i, startLimit + 6 + j*2, sum !== 0 ? sum : null);                }            }        },        countSum: function() {            const rowCount = changeSpreadSheet.getRowCount();            let oSum = 0,                cSum = 0,                sSum = 0,                cdSum = 0;            for(let i = 0; i < rowCount - 1; i++){                oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, startLimit));                cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, startLimit + 2));                sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, startLimit + 4));                cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, (startLimit + 6 + aidList.length*2)));            }            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit, oSum !== 0 ? oSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 2, cSum !== 0 ? cSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 4, sSum !== 0 ? sSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (startLimit + 6 + aidList.length*2), cdSum !== 0 ? cdSum : null);            // 用户的数据合计            for (const j in aidList) {                let audit_sum = 0;                for(let i = 0; i < rowCount - 1; i++){                    audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, startLimit + 6 + j*2));                }                changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, startLimit + 6 + j*2, audit_sum !== 0 ? audit_sum : null);            }        },        showHideAudit: function (show = false) {            const count = changeSpreadSetting.cols.length;            for (let i = startLimit + 5; i < count - 2; i++) {                changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);            }            changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);            changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);        }    };    SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);    SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);    for (const c  of changeList) {        for (const j of aidList) {            c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], c.unit_price), totalPriceUnit);        }    }    SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);    // changeSpreadObj.setAuditValue();    changeSpreadObj.makeSjsFooter();    changeSpreadObj.showHideAudit();    changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));    changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);    // 审批流程展示与隐藏    $('#show-table-detail').on('click', function (e) {        if($(e.target).is('label')){            return;        }        changeSpreadObj.showHideAudit($(this).is(':checked'));    });    // 重新审批获取手机验证码    // 获取验证码    let isPosting = false;    $(".get-code").on('click', function() {        if (isPosting) {            return false;        }        const btn = $(this);        $.ajax({            url: '/profile/code?_csrf_j=' + csrf,            type: 'post',            data: { mobile: authMobile, type: 'shenpi' },            dataTye: 'json',            error: function() {                isPosting = false;            },            beforeSend: function() {                isPosting = true;            },            success: function(response) {                isPosting = false;                if (response.err === 0) {                    codeSuccess(btn);                    $("input[name='code']").removeAttr('readonly');                    $("#re-shenpi-btn").removeAttr('disabled');                    $("#re-shenpi-btn2").removeAttr('disabled');                } else {                    toast(response.msg, 'error');                }            }        });    });    // 记录变更信息操作    $('body').on('valuechange', '#w_code', function (e, previous) {        const new_w_code = $(this).val();        if (new_w_code !== w_code) {            $('#show-save-btn').show();            $('#sp-btn').hide();            $('.title-main').addClass('bg-warning');        } else {            $('#show-save-btn').hide();            $('#sp-btn').show();            $('.title-main').removeClass('bg-warning');        }    });    // 保存修改ajax提交(不刷新页面)    $('.save_change_btn').on('click', function () {        const new_w_code = $('#w_code').val();        // 后改为br        // 更新至服务器        postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {            toastr.success(result ? result.msg : '');            $('#show-save-btn').hide();            $('#sp-btn').show();            $('.title-main').removeClass('bg-warning');            w_code = new_w_code;        });        return false;    });    $('#cancel_change').on('click', function () {        $('#show-save-btn').hide();        $('#sp-btn').show();        $('.title-main').removeClass('bg-warning');        $('#w_code').val(w_code);        // toastr.success('已还原到上次保存状态');    });});/** * 获取成功后的操作 * * @param {Object} btn - 点击的按钮 * @return {void} */function codeSuccess(btn) {    let counter = 60;    btn.addClass('disabled').text('重新获取 ' + counter + 'S');    btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');    const bindBtn = $("#bind-btn");    bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');    const countDown = setInterval(function() {        const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';        // 倒数结束后        if (countString === '') {            clearInterval(countDown);            btn.removeClass('disabled');        }        const text = '重新获取' + countString;        btn.text(text);        counter -= 1;    }, 1000);}
 |