首页 > 代码库 > easyUI 多功能datagrid 用户控件

easyUI 多功能datagrid 用户控件

技术分享
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Cell Editing in DataGrid - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="http://www.mamicode.com/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="http://www.mamicode.com/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="http://www.mamicode.com/demo.css">
    <script type="text/javascript" src="http://www.mamicode.com/jquery.min.js"></script>
    <script type="text/javascript" src="http://www.mamicode.com/jquery.easyui.min.js"></script>
</head>
<body>

    <div style="margin: 20px 0;"></div>
    <!-- 头部隐藏工具栏 -->
    <div class="showcolumnTools"></div>
    <!-- 中间数据表格 -->
    <table id="dg_Multi_function" style="height: auto"></table>
    <!-- 底部工具栏 -->
    <div class="bottomTools">
        <span style="float: right;">
            <select id="ddlType_Shuilv" class="easyui-combobox"
                data-options="editable : false,panelHeight:80">
                <option value="http://www.mamicode.com/0" selected="selected">选择税率</option>
                <option value="http://www.mamicode.com/0.03">普通税率(3%)</option>
                <option value="http://www.mamicode.com/0.17">增值税(17%)</option>
                <option value="http://www.mamicode.com/0.06">服务税(6%)</option>
            </select>
            <a id="buttonLoadDraft" href="javascript:FoldBill();" class="easyui-linkbutton floatRight" data-options="iconCls:‘icon-save‘">调入草稿</a>&nbsp;
                                <a id="buttonSaveDraft" href="javascript:AddSave(193);" class="easyui-linkbutton floatRight" data-options="iconCls:‘icon-save‘">存入草稿</a>&nbsp;
                                <a id="buttonSave" href="javascript:ProviderDatagrid();" class="easyui-linkbutton floatRight" data-options="iconCls:‘icon-save‘">保存入库</a>
        </span>
    </div>
    <script type="text/javascript">


        $.extend($.fn.datagrid.methods, {
            editCell: function (jq, param) {
                return jq.each(function () {
                    var opts = $(this).datagrid(‘options‘);
                    var fields = $(this).datagrid(‘getColumnFields‘, true).concat($(this).datagrid(‘getColumnFields‘));
                    for (var i = 0; i < fields.length; i++) {
                        var col = $(this).datagrid(‘getColumnOption‘, fields[i]);
                        col.editor1 = col.editor;
                        if (fields[i] != param.field) {
                            col.editor = null;
                        }
                    }
                    $(this).datagrid(‘beginEdit‘, param.index);
                    var ed = $(this).datagrid(‘getEditor‘, param);
                    if (ed) {
                        if ($(ed.target).hasClass(‘textbox-f‘)) {
                            $(ed.target).textbox(‘textbox‘).focus();
                        } else {
                            $(ed.target).focus();
                        }
                    }
                    for (var i = 0; i < fields.length; i++) {
                        var col = $(this).datagrid(‘getColumnOption‘, fields[i]);
                        col.editor = col.editor1;
                    }
                });
            },
            enableCellEditing: function (jq) {
                return jq.each(function () {
                    var dg = $(this);
                    var opts = dg.datagrid(‘options‘);
                    opts.oldOnClickCell = opts.onClickCell;
                    opts.onClickCell = function (index, field) {
                        if (opts.editIndex != undefined) {
                            if (dg.datagrid(‘validateRow‘, opts.editIndex)) {
                                dg.datagrid(‘endEdit‘, opts.editIndex);
                                opts.editIndex = undefined;
                            } else {
                                return;
                            }
                        }
                        dg.datagrid(‘selectRow‘, index).datagrid(‘editCell‘, {
                            index: index,
                            field: field
                        });
                        opts.editIndex = index;
                        opts.oldOnClickCell.call(this, index, field);
                    }
                });
            },
            //列显示隐藏逻辑
            showHidecolumns: function (jq) {
                //初次加载就把含税和大单位隐藏
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_hs‘); //大单价(含税)
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuilv‘); //税率
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuie‘); //税额
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_hs‘); //单价(含税)
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_je_hs‘); //金额(含税)
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_ws‘); //大单价(未税)
                $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw‘); //大单位
                $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_xdw‘); //小单位
                $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_dj_ws‘); //单价(未税)
                $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_je_ws‘); //金额(未税)
                var opts = $.data(jq[0], ‘datagrid‘).options;
                var dg = $(jq[0]); //获取到当前表格
                var arr = opts.hidecolumns; //隐藏列
                //勾选隐藏逻辑啊a[0]:表示编号,a[1]:表示名称
                for (i = 0; i < arr[0].length; i++) {
                    $(".showcolumnTools").append(‘<input type="checkbox" id="‘ + arr[0][i] + ‘" /><label>‘ + arr[1][i] + ‘</label>‘); //添加check元素
                    dg.datagrid(‘hideColumn‘, arr[0][i]); //初次加载先隐藏
                    //$(".showcolumnTools").append(‘<input type="checkbox" id="‘ + arr[0][i] + ‘" /><label>显示‘ + arr[1][i] + ‘</label>‘);
                    $("#" + arr[0][i]).click(function () {
                        var self = $(this);
                        var id = self.attr(‘id‘);
                        console.log(id);
                        if (id == ‘yongdadanwei‘ || id == ‘hanshui‘) {//含税,用大单位,特殊逻辑
                            var ddw_self = $("#yongdadanwei");//大单位check对象
                            var hs_self = $("#hanshui");//含税check对象
                            //大单位:tb_ddw,小单位:tb_xdw ,大单位(含税):tb_ddw_hs ,大单位(未税):tb_ddw_ws
                            //金额(含税):tb_jehs ,金额(未税):tb_je_ws ,tb_shuilv tb_shuie
                            if (hs_self.is(‘:checked‘) == true) { //含税+大单位
                                if (ddw_self.is(‘:checked‘) == true) {
                                    //用大单位+含税(显示:大单位(含税),税率,税额;隐藏:小单位,单价(未税),金额(未税))
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_ddw_hs‘);//大单价(含税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_shuilv‘);//税率
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_shuie‘);//税额
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_hs‘); //单价(含税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_je_hs‘); //金额(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_ws‘); //大单价(未税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_ddw‘);//大单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_xdw‘);//小单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_ws‘);//单价(未税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_je_ws‘);//金额(未税)
                                } else {//含税+小单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_hs‘); //大单价(含税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_shuilv‘);//税率
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_shuie‘);//税额
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_dj_hs‘); //单价(含税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_je_hs‘); //金额(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_ws‘); //大单价(未税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw‘);//大单位
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_xdw‘);//小单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_ws‘);//单价(未税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_je_ws‘);//金额(未税)
                                }
                            }
                            else {//不含税+大单位
                                if (ddw_self.is(‘:checked‘) == true) {
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_hs‘);//大单价(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuilv‘);//税率
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuie‘);//税额
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_hs‘); //单价(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_je_hs‘); //金额(含税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_ddw_ws‘); //大单价(未税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_ddw‘);//大单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_xdw‘);//小单位
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_dj_ws‘);//单价(未税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_je_ws‘);//金额(未税)
                                } else {//不含税+小单位
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_hs‘);//大单价(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuilv‘);//税率
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_shuie‘);//税额
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_dj_hs‘); //单价(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_je_hs‘); //金额(含税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw_ws‘); //大单价(未税)
                                    $("#dg_Multi_function").datagrid(‘hideColumn‘, ‘tb_ddw‘);//大单位
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_xdw‘);//小单位
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_dj_ws‘);//单价(未税)
                                    $("#dg_Multi_function").datagrid(‘showColumn‘, ‘tb_je_ws‘);//金额(未税)
                                }
                            }
                        } else {
                            self.is(‘:checked‘) == true ? $("#dg_Multi_function").datagrid(‘showColumn‘, id) : $("#dg_Multi_function").datagrid(‘hideColumn‘, id);
                        }
                    });
                }
            }
        });

        $(function () {
            $(‘#dg_Multi_function‘).datagrid().datagrid(‘enableCellEditing‘);
        })

        //数据网格加载
        $(‘#dg_Multi_function‘).datagrid({
            columns: [[
                { field: ‘Goods_Code‘, title: ‘编码‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘Goods_Name‘, title: ‘名称‘, width: 150, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘Goods_Aear‘, title: ‘产地‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: { type: ‘numberbox‘, options: { precision: 2 } } },
                { field: ‘tb_guige‘, title: ‘规格‘, width: 60, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_Type‘, title: ‘型号‘, width: 60, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_sjkc‘, title: ‘实际库存‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_ddw‘, title: ‘大单位‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_xdw‘, title: ‘小单位‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_Number‘, title: ‘数量‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_dj_ws‘, title: ‘单价(未税)‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_dj_hs‘, title: ‘单价(含税)‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_ddw_hs‘, title: ‘大单价(含税)‘, width: 100, align: ‘right‘, halign: ‘center‘, editor: { type: ‘numberbox‘, options: { precision: 2 } } },
                { field: ‘tb_ddw_ws‘, title: ‘大单价(未税)‘, width: 100, align: ‘right‘, halign: ‘center‘, editor: { type: ‘numberbox‘, options: { precision: 2 } } },
                { field: ‘tb_je_hs‘, title: ‘金额(含税)‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_je_ws‘, title: ‘金额(未税)‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_shuilv‘, title: ‘税率‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: { type: ‘numberbox‘, options: { precision: 2 } } },
                { field: ‘tb_shuie‘, title: ‘税额‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_zhekou‘, title: ‘折扣‘, width: 50, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_zkje‘, title: ‘折扣金额‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘tb_jsje‘, title: ‘结算金额‘, width: 80, align: ‘right‘, halign: ‘center‘, editor: { type: ‘numberbox‘, options: { precision: 2 } } },
                { field: ‘tb_beizhu‘, title: ‘备注‘, width: 120, align: ‘right‘, halign: ‘center‘, editor: ‘text‘ },
                { field: ‘operation‘, title: ‘操作‘, width: 60, align: ‘center‘, halign: ‘center‘, formatter: addOperationRow },
                { field: ‘yongdadanwei‘, title: ‘用大单位‘, hide: true },
                { field: ‘hanshui‘, title: ‘含税‘, hide: true }
            ]],
            showFooter: true, //尾行显示
            onl oadSuccess: function (data) {
                var length = $(‘#dg_Multi_function‘).datagrid(‘getRows‘).length;
                for (var i = 0; i < 6 - length; i++) {
                    addRow();//添加空白行
                }
                formatMoney();
            },
            fixed: true,
            rownumbers: true,
            hidecolumns: [
            [‘tb_guige‘, ‘tb_Type‘, ‘Goods_Aear‘, ‘tb_beizhu‘, ‘yongdadanwei‘, ‘hanshui‘],
            [‘显示规格‘, ‘显示型号‘, ‘显示产地‘, ‘显示备注‘, ‘用大单位‘, ‘含税‘]]//隐藏列配置
        });

        //添加数据表格操作列
        function addOperationRow(val, row, index) {
            return ‘<div style="margin-top:4px"><a href="javascript:void(0);" onclick="addRow()">‘ +
                               ‘<img src="http://www.mamicode.com/Images/add.png" width="16px" height="16px" alt="添加" title="添加"/></a>&nbsp;‘ +
                               ‘<a href="javascript:void(0);" onclick="delRow(‘ + index + ‘)">‘ +
                               ‘<img src="http://www.mamicode.com/Images/del.png" width="16px" height="16px" alt="删除" title="删除"/></a></div>‘;
        }
        $(‘#dg_Multi_function‘).datagrid(‘showHidecolumns‘); //显示and隐藏列功能

        var addRow = function () {
            $(‘#dg_Multi_function‘).datagrid(‘appendRow‘, {});
        };
        var delRow = function (index) {
            $(‘#dg_Multi_function‘).datagrid(‘deleteRow‘, index);
        };
        //自动求and格式化(求和列:tb_je_hs,tb_je_ws,tb_Number,tb_sjkc)
        function formatMoney() {
            var rows = $(‘#dg_Multi_function‘).datagrid(‘getRows‘);
            var tb_je_hs_total = 0;
            var tb_je_ws_total = 0;
            var tb_Number_total = 0;
            var tb_sjkc_total = 0;
            for (var i = 0; i < rows.length; i++) {
                tb_je_hs_total += isNaN(parseFloat(rows[i]["tb_je_hs"])) ? 0 : parseFloat(rows[i]["tb_je_hs"]);
                tb_je_ws_total += isNaN(parseFloat(rows[i]["tb_je_ws"])) ? 0 : parseFloat(rows[i]["tb_je_ws"]);
                tb_Number_total += isNaN(parseFloat(rows[i]["tb_Number"])) ? 0 : parseFloat(rows[i]["tb_Number"]);
                tb_sjkc_total += isNaN(parseFloat(rows[i]["tb_sjkc"])) ? 0 : parseFloat(rows[i]["tb_sjkc"]);
            }
            var footRows = $(‘#dg_Multi_function‘).datagrid(‘getFooterRows‘);
            footRows[0].tb_je_hs = toDecimal2(tb_je_hs_total);
            footRows[0].tb_je_ws = toDecimal2(tb_je_ws_total);
            footRows[0].tb_Number = tb_Number_total;
            footRows[0].tb_sjkc = tb_sjkc_total;
            $(‘#dg_Multi_function‘).datagrid(‘reloadFooter‘, footRows);
        };
        //制保留2位小数,如:2,会在2后面补上00.即2.00          
        function toDecimal2(x) {
            var f = parseFloat(x);
            if (isNaN(f)) {
                return 0.00;
            }
            var f = Math.round(x * 100) / 100;
            var s = f.toString();
            var rs = s.indexOf(‘.‘);
            if (rs < 0) {
                rs = s.length;
                s += ‘.‘;
            }
            while (s.length <= rs + 2) {
                s += ‘0‘;
            }
            return s;
        };
        //选择税率后修改表单
        $("#ddlType_Shuilv").combobox({
            onSelect: function (rec) {
                console.log(rec.value);
                var obj = $("#dg_Multi_function").datagrid(‘getData‘).rows;
                console.log(obj);
                for (var i = 0; i < obj.length; i++) {
                    if (obj[i].Goods_Code != "" && "Goods_Code" in obj[i]) {
                        obj[i].tb_shuilv= rec.value;//更改税率
                    var a=obj[i].tb_Number;    //a:数量;
                    var b1=obj[i].tb_dj_hs,b2=obj[i].tb_ddw_hs;    //b1:单价(含税); b2:大单价(含税);
                    var c1=obj[i].tb_dj_ws,c2=obj[i].tb_ddw_ws;    //c1:单价(不含税); c2:大单价(不含税);
                    var d=obj[i].tb_je_hs,e=obj[i].tb_je_ws;    //d:金额(含税),e:金额(不含税);
                    var f=rec.value,g=obj[i].tb_shuie;  //f:(税率),g:税额;
                    var n=10;//n 是大单位和单位的系数比:大单位/单位
                    
                         //场景8:修改税率 f
                        b1=c1/(1-f);
                        b2=c1*n/(1-f);
                        d=c1*a/(1-f);
                        e=a*c1;
                        g=c1*a*f/(1-f);

                    var rowObj = new Object();
                        rowObj.tb_Number=a;
                        rowObj.tb_dj_hs=b1;
                        rowObj.tb_ddw_hs=b2;
                        rowObj.tb_dj_ws=c1;
                        rowObj.tb_ddw_ws=c2;
                        rowObj.tb_je_hs=d;
                        rowObj.tb_je_ws=e;
                        rowObj.tb_shuilv=rec.value;
                        rowObj.tb_shuie=g;
                        console.log(rowObj);
                        $("#dg_Multi_function").datagrid(‘updateRow‘, {
                            index: i,
                            row: rowObj
                        });
                    }
                }

            }
        });
        //格式化获取表单值
        function ProviderDatagrid() {
            console.log(11);
            var obj = $("#dg_Multi_function").datagrid(‘getData‘).rows;
            var str = "";
            for (var i = 0; i < obj.length; i++) {
                for (var j in obj[i]) {//不使用过滤
                    // console.log(j, ":", obj[i][j]);
                    if (obj[i].Goods_Code != "") {
                        str += obj[i][j] + ",";
                    }
                }
                str += "|";
            }
            console.log(str);
            $("#datagridValue").val(str);
            return true;
        }
        /* 加载测试数据star */
        var ceshidata =http://www.mamicode.com/ {
            total: 1,
            rows: [{ Goods_Code: "", Goods_Name: "", Goods_Aear: "", tb_guige: "", tb_Type: "", tb_sjkc: "", tb_ddw: "", tb_dj_hs: "", tb_dj_ws: "", tb_xdw: "", tb_Number: "", tb_ddw_hs: "", tb_ddw_ws: "", tb_je_hs: "", tb_je_ws: "", tb_shuilv: "", tb_shuie: "", tb_zhekou: "", tb_zkje: "", tb_jsje: "", tb_beizhu: "" }],
            footer: [{ Goods_Name: "总计", tb_Number: "", id: "-1" }]
        };
        setTimeout(function () {
            $(‘#dg_Multi_function‘).datagrid(‘loadData‘, ceshidata)
        }
        , 100); //将数据绑定到datagrid 
        /* 加载测试数据end */

        //列编辑功能
        setTimeout(function () {
            var dg = $("#dg_Multi_function");
            var arrHideCol = [‘tb_zhekou‘, ‘tb_zkje‘, ‘tb_jsje‘]; //隐藏折扣,折扣金额,结算金额;
            for (var i = 0; i < arrHideCol.length; i++) {
                dg.datagrid(‘hideColumn‘, arrHideCol[i]); //列隐藏逻辑
            }
            //单列编辑
            dg.datagrid({
                onAfterEdit: function (rowIndex, rowData, changes) {
                    //console.log(rowData);
                    var a=rowData.tb_Number;    //a:数量;
                    var b1=rowData.tb_dj_hs,b2=rowData.tb_ddw_hs;    //b1:单价(含税); b2:大单价(含税);
                    var c1=rowData.tb_dj_ws,c2=rowData.tb_ddw_ws;    //c1:单价(不含税); c2:大单价(不含税);
                    var d=rowData.tb_je_hs,e=rowData.tb_je_ws;    //d:金额(含税),e:金额(不含税);
                    var f=rowData.tb_shuilv=="" ? 0 : rowData.tb_shuilv,g=rowData.tb_shuie;  //f:(税率),g:税额;
                    var n=10;//n 是大单位和单位的系数比:大单位/单位
                    var colname = ""; //操作的单元格key
                    for (var p1 in changes) {
                        colname = p1;
                    }
                    //场景1:修改数目 a
                    if (colname === "tb_Number") {
                        d=a*b1;
                        e=a*b1*(1-f);
                        g=a*b1*f;
                    }
                    //场景2:修改(含税)单价 b1
                    if (colname === "tb_dj_hs") {
                        b2=b1*n;
                        c1=b1*(1-f);
                        c2=b1*(1-f)*n;
                        d=a*b1;
                        e=a*b1*(1-f);
                        g=a*b1*f;
                    }
                    //场景3:修改(含税)大单价 b2
                    if (colname === "tb_ddw_hs") {
                        b1=b2/n;
                        c1=(b2/n)*(1-f);
                        c2=b2(1-f);
                        d=b2*a;
                        e=b2*a*(1-f);
                        g=b2*a*f;

                    }
                    //场景4:修改单价(未税)c1
                    if (colname === "tb_dj_ws") {
                        c2=c1*n;
                        b1=c1/(1-f);
                        b2=c1*n/(1-f);
                        d=c1*a/(1-f);
                        e=c1*a;
                        g=c1*f*a/(1-f);
                    }
                    //场景5:修改大单价(未税)c2
                    if (colname === "tb_ddw_ws") {
                        c1=c2/n;
                        b1=c2/n/(1-f);
                        b2=c2/(1-f);
                        d=c2*a/(1-f);
                        e=c2*a;
                        g=c2*a*f/(1-f);
                    }
                    //场景6:修改金额(含税)d
                    if (colname === "tb_je_hs") {
                        b1=d/a;
                        b2=d*n/a;
                        c1=d(1-f)/a;
                        c2=d(1-f)*n/a;
                        g=d*f;
                    }
                    //场景7:修改金额(未税)e
                    if (colname === "tb_je_ws") {
                        b1=e/(1-f)/a;
                        b2=e*n/(1-f)/a;
                        c1=e/a;
                        c2=e*n/a;
                        g=e*f/(1-f);
                    }
                    //场景8:修改税率 f
                    if (colname === "tb_shuilv") {
                        b1=c1/(1-f);
                        b2=c1*n/(1-f);
                        d=c1*a/(1-f);
                        e=a*c1;
                        g=c1*a*f/(1-f);
                    }
                     //场景9:修改税额 g
                    if (colname === "tb_shuie") {
                        b1=c1*e/(2*e-d);
                        b2=c1*e*n/(2*e-d);
                        g=d-e;
                        f=(d-e)/e;
                    }

                    if (colname === "tb_Number" || colname === "tb_dj_hs" || colname === "tb_ddw_hs"|| colname === "tb_dj_ws"|| colname === "tb_ddw_ws"|| colname === "tb_je_hs"|| colname === "tb_je_ws"|| colname === "tb_shuilv"|| colname === "tb_shuie") {
                        var rowObj = new Object();
                        rowObj.tb_Number=a;
                        rowObj.tb_dj_hs=b1;
                        rowObj.tb_ddw_hs=b2;
                        rowObj.tb_dj_ws=c1;
                        rowObj.tb_ddw_ws=c2;
                        rowObj.tb_je_hs=d;
                        rowObj.tb_je_ws=e;
                        rowObj.tb_shuilv=f;
                        rowObj.tb_shuie=g;
                        dg.datagrid(‘updateRow‘, {
                            index: rowIndex,
                            row: rowObj
                        });
                    }
                    formatMoney();
                }

            });
        }, 101);
    </script>
</body>
</html>
View Code

 

easyUI 多功能datagrid 用户控件