zzr99
2021-08-24 5a430f05a47048180472be67af70ff6fc972b3af
WebTM/views/É豸¹ÜÀí/Sb_EquipDotCheckBillEdit.html
@@ -71,7 +71,7 @@
                                                <div class="layui-input-inline">
                                                    <input type="hidden" name="HEquipID" id="HEquipID" class="layui-input" value="" style="float:left;width:150px;">
                                                    <input type="text" name="HEquipName" id="HEquipName" class="layui-input" value="" style="float:left;width:150px;">
                                                    <button type="button" lay-submit="" class="layui-btn layui-btn-primary" lay-filter="ProductModulList" style="width:40px;">
                                                    <button type="button" lay-submit="" class="layui-btn" lay-filter="ProductModulList" style="width:40px;">
                                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn" style="margin-left:-9px;"></i>
                                                    </button>
                                                </div>
@@ -139,13 +139,23 @@
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        //获取参数
        var params = get_UrlVars();
        if (typeof (params[params[0]]) == "undefined") {
            var OperationType = 1;//操作类型
        } else {
            var OperationType = params[params[0]];//操作类型
            var linterid = params[params[1]];//源单id
            var HSouceBillType = params[params[2]];//源单类型
        }
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
           //#region å…¬ç”¨å˜é‡
            //#region å…¬ç”¨å˜é‡
            var $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
@@ -154,62 +164,37 @@
                , laydate = layui.laydate
                , element = layui.element;
            var option;
            var option=[];
            var sBillType = "3903";
            var TabRow = { "HDotCheckItem": "", "HDotCheckPart": "", "HClaim": "", "HManagerID": 0, "HManagerCode":"","HManagerName":"", "HRemark": "" };
            var Sctag = "0";
            var columns = "";
            var TabRow = { /*"HDotCheckID": 0, "HDotCheckCode": "",*/"HDotCheckItem": "", "HDotCheckPart": "", "HClaim": "", "HManagerID": 0, "HManagerCode": "", "HManagerName": "", "HRemark": "" };
            var date = new Date();
            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();
            var shijian = year + "-" + month + "-" + day;
            //#endregion
           //#endregion
           //#region è¿›å…¥é¡µé¢å³åŠ è½½
            //判断是否登录 æœªç™»å½•则跳到登录页
            //get_LoginIs();
            //#region è¿›å…¥é¡µé¢å³åŠ è½½
            //初始化表单插件
            set_InitFrom();
            //初始化表格
            set_InitGrid();
            //获取页面跳转参数
            var params = get_UrlVars();
            if (typeof (params[params[0]]) == "undefined") {
                var OperationType = 1;//操作类型
            } else {
                var OperationType = params[params[0]];//操作类型
                var linterid = params[params[1]];//源单id
                var HSouceBillType = params[params[2]];//源单类型
            }
            //判断操作类型
            if (OperationType == 1) {//无源新增
                $("#HItemID").val(0);
                set_AddFNew();
            }
            else if (OperationType == 3) {//编辑
                $("#HItemID").val(linterid);//修改时主表ID
                //编辑状态时,根据内码,获取信息并写入界面
                set_EditFromGrid(linterid);
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
            }
            //#endregion
        //#endregion
           //#region è§¦å‘事件:包括form.on(){}格式的所有点击事件、选择事件等
            //#region å¤´å·¥å…·æ äº‹ä»¶
            //#region è§¦å‘事件:包括form.on(){}格式的所有点击事件、选择事件等
            //头工具栏事件
            table.on('toolbar(mainTable)', function (obj) {
                var rowid = 0;
                var checkStatus = table.checkStatus('mainTable')
                    , data = checkStatus.data;;
                var AddRow = table.cache['mainTable'];
                    , data = checkStatus.data;
                var NewRow = TabRow;
                switch (obj.event) {
                    //新增一行
@@ -220,16 +205,13 @@
                        break;
                }
            });
            //#endregion
            //#region è¡Œå†…事件
            //行内事件
            table.on('tool(mainTable)', function (obj) {
                set_GridDelete(obj);   //行内删除
                set_GridCellCheck(obj); //行内快捷键筛选
            });
            //#endregion
            //#region è¡¨å¤´ä¿¡æ¯è®¾å¤‡å¼¹çª—
            //表头信息设备弹窗
            form.on('submit(ProductModulList)', function () {
                //页面层-自定义
                layer.open({
@@ -263,57 +245,56 @@
                    }
                });
            });
            //#endregion
            //#region æäº¤ä¿å­˜
            // æäº¤ä¿å­˜
            form.on('submit(set_SaveBill)', function (data) {//保存
                //debugger;
                data.field.HMaker = sessionStorage["HUserName"];//制单人
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(table.cache['mainTable']);
                var sMainSub = sMainStr + ';' + sSubStr;
                $.ajax(
                    {
                        type: "POST",
                        url: GetWEBURL() + "/Sb_EquipDotCheckBill/SaveEquipDotCheckBillList", //方法所在页面和方法名
                        async: true,
                        data: { "msg": sMainSub },
                        dataType: "json",
                        success: function (data) {
                            if (data.count == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                                layer.msg(data.Message, { time: 1 * 1000, icon: 1 }, function () {
                                    $('#add-btn').addClass("layui-btn-disabled").attr("disabled", true);
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index); //再执行关闭 Â  Â  Â  Â  Â Â  Â Â Â  Â 
                                });
                            }
                            else {
                if (AllowLoadData(sSubStr)) {
                    $.ajax(
                        {
                            type: "POST",
                            url: GetWEBURL() + "/Sb_EquipDotCheckBill/SaveEquipDotCheckBillList", //方法所在页面和方法名
                            async: true,
                            data: { "msg": sMainSub },
                            dataType: "json",
                            success: function (data) {
                                if (data.count == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                                    layer.msg(data.Message, { time: 1 * 1000, icon: 1 }, function () {
                                        $('#add-btn').addClass("layui-btn-disabled").attr("disabled", true);
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index); //再执行关闭 Â  Â  Â  Â  Â Â  Â Â Â  Â 
                                    });
                                }
                                else {
                                f_alert(data.Message);
                                console.log("Reason" + sMainStr + "sub:" + JSON.stringify(layui.table.cache.mainTable));
                            }
                            layer.closeAll("loading");
                        },
                        error: function (err) {
                                    f_alert(data.Message);
                                    console.log("Reason" + sMainStr + "sub:" + JSON.stringify(layui.table.cache.mainTable));
                                }
                                layer.closeAll("loading");
                            },
                            error: function (err) {
                            f_alert("错误:" + err);
                            console.log("Reason" + sMainStr);
                        }
                    });
                                f_alert("错误:" + err);
                                console.log("Reason" + sMainStr);
                            }
                        });
                }
            })
            //#endregion
            //#region é€€å‡ºæŒ‰é’®
            //退出按钮
            form.on('submit(Cancel)', function () {
                Pub_Close(1);
            })
            //#endregion
        //#endregion
           //#region æœ¬é¡µé¢æ‰€æœ‰è¢«è°ƒç”¨çš„æ–¹æ³•
            //#region åˆå§‹åŒ–表单
            //#region æœ¬é¡µé¢æ‰€æœ‰è¢«è°ƒç”¨çš„æ–¹æ³•
            //初始化表单
            function set_InitFrom() {
                laydate.render({
                    elem: '#HDate',
@@ -325,18 +306,19 @@
                    elem: '#HEndDate'
                });
            }
            //#endregion
            //#region åˆå§‹åŒ–表格
            //初始化表格
            function set_InitGrid() {
                //表头
                columns = [
                    { type: 'checkbox', fixed: 'left' }
                    , { templet: '#xuhao', title: '序号', sort: true, fixed: 'left', event: "qwe" }
                    //, { field: 'HDotCheckID', title: '点检项目代码', edit: 'text', hide: true }
                    //, { field: 'HDotCheckCode', title: '点检项目代码', edit: 'text', event: "HDotCheckCode" }
                    , { field: 'HDotCheckItem', title: '点检项目', edit: 'text', event: "" }
                    , { field: 'HDotCheckPart', title: '点检部位', edit: 'text', event: "" }
                    , { field: 'HClaim', title: '具体要求', edit: 'text' }
                    , { field: 'HManagerID', title: '负责人代码', edit: 'text', hide: true}
                    , { field: 'HManagerCode', title: '负责人代码', edit: 'text', event: 'HManagerCode'}
                    , { field: 'HManagerID', title: '负责人代码', edit: 'text', hide: true }
                    , { field: 'HManagerCode', title: '负责人代码', edit: 'text', event: 'HManagerCode' }
                    , { field: 'HManagerName', title: '负责人名称', edit: 'text' }
                    , { field: 'HRemark', title: '备注', event: "", edit: 'text' }
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
@@ -345,7 +327,7 @@
                    id: 'mainTable'
                    , elem: '#mainTable'
                    , toolbar: '#toolbarDemo'
                    , page: false
                    , page: true
                    , cellMinWidth: 120
                    , height: 500
                    , cols: [columns]
@@ -354,17 +336,13 @@
                    }
                };
            }
            //#endregion
            //#region è¡¨æ ¼å¢žåŠ è¡Œäº‹ä»¶
            //增加一行事件
            function btnAddLine(NewRow) {
                table.cache["mainTable"].push(NewRow);
                option.data = table.cache["mainTable"];
                table.render(option);
            }
            //#endregion
            //#region è¡¨æ ¼å¤åˆ¶è¡Œäº‹ä»¶
            //表格复制一行事件
            function btnCopyLine(data) {
                var copydata = JSON.stringify(data);
                if (data.length <= 0) {
@@ -381,31 +359,66 @@
                    table.render(option);//将数据渲染到表格上
                }
            }
            //#endregion
            //#region è¡¨æ ¼è¡Œå†…事件删除
            // è¡¨æ ¼è¡Œå†…事件删除
            function set_GridDelete(obj) {
                var data = obj.data;
                var rowIndex = $(obj.tr).attr("data-index");
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        console.log("索引为:" + rowIndex);
                        if (rowIndex === '0') {
                            layer.msg('首行无法删除!!!');
                        } else {
                            obj.del();
                            option.data = table.cache["mainTable"];//将数据绑定到data上
                            table.reload(option);
                            //obj.del();
                            //layer.close(index);
                            var oldData = table.cache["mainTable"];
                            oldData.splice(obj.tr.data('index'), 1);
                            table.reload('mainTable', { data: oldData });
                            layer.close(index);
                        }
                    });
                }
            }
            //#endregion
            //#region è¡¨æ ¼è¡Œå†…事件快捷键筛选
            // è¡¨æ ¼è¡Œå†…事件快捷键筛选
            function set_GridCellCheck(obj) {
                $(document).off('keydown', ".layui-table-edit").on('keydown', '.layui-table-edit', function (e) {
                    if (event.key == "F7") {
                        //if (obj.event === 'HDotCheckCode')  //点检项目代码
                        //{
                        //    //页面层-自定义
                        //    layer.open({
                        //        type: 2,
                        //        skin: 'layui-layer-rim', //加上边框
                        //        title: '物料列表',
                        //        closeBtn: 1,
                        //        shift: 2,
                        //        area: ['90%', '90%'],
                        //        maxmin: true,
                        //        content: ['../PublicPage/CheckItemInformation.html', 'yes'],
                        //        btn: ['确定', '取消']
                        //        , btn1: function (index, layero) {
                        //            //按钮【按钮一】的回调
                        //            var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
                        //            var checkStatus = iframeWindow.layui.table.checkStatus('mainTable');//获取table的elem:"#test"
                        //            if (checkStatus.data.length === 0) {
                        //                return layer.msg('请选择数据');
                        //            }
                        //            //同步更新表格和缓存对应的值
                        //            obj.update({
                        //                HDotCheckID: checkStatus.data[0].HItemID,
                        //                HDotCheckCode: checkStatus.data[0].HNumber,
                        //                HDotCheckItem: checkStatus.data[0].HName
                        //            });
                        //            layer.close(layer.index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                        //        }
                        //        , btn2: function (index, layero) {
                        //            //按钮【按钮二】的回调
                        //            //return false å¼€å¯è¯¥ä»£ç å¯ç¦æ­¢ç‚¹å‡»è¯¥æŒ‰é’®å…³é—­
                        //        },
                        //        end: function () {
                        //        }
                        //    });
                        //}
                        if (obj.event === 'HManagerCode')  //负责人代码
                        {
                            //页面层-自定义
@@ -448,9 +461,7 @@
                    }
                })
            }
             //#endregion
            //#region èŽ·å–æœ€å¤§å•æ®å·
            //获取最大单据号及默认值赋值
            function get_MAXNum() {
                //获取最大单据号 new
                $("#HInterID").val("0");
@@ -460,36 +471,30 @@
                    type: "GET",
                    data: { "HBillType": sBillType },
                    success: function (d) {
                        //console.log(d.data);
                        $("#HBillNo").val(d.data[0].HBillNo);
                        $("#HDate").val(shijian);
                        $("#HBeginDate").val(shijian);
                        $("#HEndDate").val(shijian);
                        $("#HCheckBeginDate").val(shijian);
                        $("#HDate").val(Pub_Format(new Date(), "yyyy-MM-dd"));
                        $("#HBeginDate").val(Pub_Format(new Date(), "yyyy-MM-dd"));
                        $("#HEndDate").val(Pub_Format(new Date(), "yyyy-MM-dd"));
                        $("#HInterID").val(0);
                    }
                });
            }
            //#endregion
            //#region æ— æºå•新增
            //无源单新增
            function set_AddFNew() {
                //获取最大单据号
                get_MAXNum();
                option.data = [TabRow];
                table.render(option);
            }
            //#endregion
            //#region ç¼–辑获取表头、获取表体
            //编辑获取表头、获取表体
            function set_EditFromGrid(linterid) {
                set_EditForm(linterid);  //编辑获取表头
                set_EditGrid(linterid);  //编辑获取表体
                option.data = [TabRow];
                table.render(option);
            }
            //#endregion
            //#region ç¼–辑获取表头
            //编辑获取表头
            function set_EditForm(linterid) {
                $.ajax({
                    url: GetWEBURL() + "Sb_EquipDotCheckBill/Sb_EquipDotCheckBillListCheckDetai",
@@ -521,9 +526,7 @@
                    }
                });
            }
            //#endregion
            //#region ç¼–辑获取表体
            // ç¼–辑获取表体
            function set_EditGrid(linterid) {
                $("#HInterID").val(linterid);//修改时主表ID
                //编辑加载数据
@@ -546,9 +549,7 @@
                    }
                });
            }
            //#endregion
            //#region è¡¨å•数据编辑时间格式化
            // è¡¨å•数据编辑时间格式化
            function formatDate(date) {
                var d = new Date(date),
                    month = '' + (d.getMonth() + 1),
@@ -560,11 +561,39 @@
                return [year, month, day].join('-');
            }
           //#endregion
           //#endregion
            //数据验证
            function AllowLoadData(sSubStr) {
                if ($("#HEquipName").val() == '') {
                    layer.msg("设备没有选择", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    return false;
                }
                //判断物料明细项
                if (typeof (sSubStr) == "undefined" || sSubStr == "" || sSubStr == "[]") {
                    layer.msg("没有物料明细记录", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    return false;
                }
                if (typeof (sSubStr) != "undefined" && typeof (sSubStr) != "") {
                    sSubStr = JSON.parse(sSubStr);
                    for (var i = 0; i < sSubStr.length; i++) {
                        //if (sSubStr[i].HDotCheckCode == "") {
                        //    layer.msg("明细记录第" + (i + 1) + "行,点检项目代码信息为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        //    return false;
                        //}
                        if (sSubStr[i].HDotCheckItem == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,点检项目代码信息为空!", { icon: 5, btn: ['确认'], time: 2000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return false;
                        }
                        if (sSubStr[i].HManagerCode == "") {
                            layer.msg("明细记录第" + (i + 1) + "行,负责人代码信息为空!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                            return false;
                        }
                        else {
                            return true;
                        }
                    }
                }
            }
            //#endregion
        });
    </script>