| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 | 'use strict';/** * 变更令详细页js * * @author EllisRan. * @date 2018/11/22 * @version */$(document).ready(() => {    const changeSpreadSetting = {        cols: [            {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: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount'},            {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(data.lid != 0) return;                        return '#007bff';                    }                },            },        ],        localCache: {            key: 'changes-spread',            colWidth: true,        }    };    for (const aid of aidList) {        const userinfo = _.find(auditList2, { 'uid': aid });        const newColcount = {            title: userinfo.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'});    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.oamount, 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);            },            oamount: function (data) {                return ZhCalc.round(data.oamount, 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.add(ZhCalc.round(data.oamount, findDecimal(data.unit)), ZhCalc.round(data.changed_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.changed_amount, findDecimal(data.unit))), totalPriceUnit));            },        },    };    const changeSpreadObj = {        makeSjsFooter: function () {            // 增加汇总行并设为锁定禁止编辑状态            changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');            changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);            changeSpreadObj.countSum();        },        resetXmjSpread: function(data = null) {            const xmj = [];            if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {                if (data.bwmx === data.xmj_jldy) {                    data.bwmx = '';                }                xmj.push(data);            }            SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);        },        selectionChanged: function (e, info) {            const data = SpreadJsObj.getSelectObject(info.sheet);            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, 3),                        amount: parseFloat(changeSpreadSheet.getValue(i, 12 + parseInt(j)*2)),                    };                    const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);                    changeSpreadSheet.setValue(i, 13 + 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, 7));                cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));                sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 11));                cdSum = ZhCalc.add(cdSum, changeSpreadSheet.getValue(i, (13 + aidList.length*2)));            }            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11, sSum !== 0 ? sSum : null);            changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, (13 + 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, 13 + j*2));                }                changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 13 + j*2, audit_sum !== 0 ? audit_sum : null);            }        },        showHideAudit: function (show = false) {            const count = changeSpreadSetting.cols.length;            for (let i = 12; i < count - 2; i++) {                changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);            }            changeSpreadSheet.setColumnVisible(10, !show, GC.Spread.Sheets.SheetArea.viewport);            changeSpreadSheet.setColumnVisible(11, !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").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');                }            }        });    });});/** * 获取成功后的操作 * * @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);}
 |