1
pzy
2024-08-11 db08b0f3239df006eadea02d004451ab6a90eb5f
WebTM/views/É豸¹ÜÀí/Sb_EquipDotCheckBillEdit.html
@@ -44,10 +44,10 @@
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                <!--<ul class="layui-tab-title">
                                <li class="layui-this">基本信息</li>-->
                                <!--<li>其他信息</li>-->
                                <!--</ul>-->
                                <ul class="layui-tab-title">
                                    <li class="layui-this">基本信息</li>
                                    <li>附件信息</li>
                                </ul>
                                <h1 style="text-align: center; padding: 10px 0;"><b>设备点检记录单</b></h1>
                                <div class="layui-tab-content">
                                    <div class="layui-tab-item layui-show">
@@ -172,6 +172,29 @@
                                            </div>
                                        </div>
                                    </div>
                                    <!--附件信息-->
                                    <div class="layui-tab-item">
                                        <div class="layui-form-item" style="padding-top: 10px;">
                                            <div class="layui-upload">
                                                <button type="button" class="layui-btn" id="testList">选择文件</button><input class="layui-upload-file" type="file" accept="" name="file" multiple="">
                                                <div class="layui-upload-list">
                                                    <table class="layui-table" lay-filter="fileTable">
                                                        <thead>
                                                            <tr>
                                                                <th>文件名</th>
                                                                <th>图片</th>
                                                                <th>大小</th>
                                                                <th>状态</th>
                                                                <th>操作</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody id="ProImgByList" class="ProImgByList">
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
@@ -221,7 +244,7 @@
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
        }).use(['index', 'form', 'laydate', 'table', 'element', 'upload'], function () {
            //#region å…¬ç”¨å˜é‡
            var $ = layui.$
@@ -230,6 +253,7 @@
                , table = layui.table
                , form = layui.form
                , laydate = layui.laydate
                , upload = layui.upload
                , element = layui.element;
            var option = [];
@@ -255,9 +279,14 @@
            //判断操作类型
            if (OperationType == 1) {//无源新增
                set_AddFNew();
                //文件选择初始化
                PicUpload();
            }
            else if (OperationType == 3) {//编辑
                set_EditFromGrid(linterid);
                //文件选择初始化
                PicUpload();
                getFile();
            }
            else {
                layer.alert("未知操作类型!", { icon: 5 });
@@ -546,7 +575,7 @@
            });
            function get_DocCheckItem3() {
                var HPlanID = $("#HPlanNo").val() //点检计划ID
                var HPlanID = $("#HEquipDotCheckPlanInterID").val() //点检计划ID
                var HDate = $("#HDate").val(); //当天日期
                $.ajax({
                    url: GetWEBURL() + "/Sb_EquipDotCheckPlanBill/Sb_EquipDotCheckPlanBill_PlanList",
@@ -988,6 +1017,7 @@
                    data: {
                        "HID": linterid
                    },
                    async: false,
                    success: function (result) {
                        if (result.code == 1) { // è¯´æ˜ŽéªŒè¯æˆåŠŸäº†ï¼Œ
                            var data = result.data.h_v_Sb_EquipDotCheckBillList[0];
@@ -1062,6 +1092,113 @@
                    }
                });
            }
            //#region æ–‡ä»¶ä¸Šä¼ 
            function PicUpload() {
                //多图片上传
                //多文件列表示例
                var ProImgByList = $('#ProImgByList')
                    , uploadListIns = upload.render({
                        elem: '#testList'
                        , url: GetWEBURL() + "/Sb_EquipDotCheckBill/UploadFile"
                        , accept: 'file'
                        , multiple: true
                        , auto: false
                        //, bindAction: '#testListAction' //按扭绑定
                        , data: { "HBillNo": $("#HBillNo").val(), "HRemark": $("#HRemark").val(), "HUserName": sessionStorage["HUserName"] }
                        , choose: function (obj) {
                            var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                            //读取本地文件
                            obj.preview(function (index, file, result) {
                                var tr = $(['<tr id="upload-' + index + '">'
                                    , '<td>' + file.name + '</td>'
                                    , '<td>' + '<img onclick=\"previewImg(this)\" id="showImg" class="ImgClass" style="width: 150px; margin:10px;cursor:pointer;"src="' + result + '" alt="' + file.name + '">' + '</td>'
                                    , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                                    , '<td>等待上传</td>'
                                    , '<td>'
                                    , '<button class="layui-btn layui-btn-xs demo-reload ">上传</button>'
                                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                    , '</td>'
                                    , '</tr>'].join(''));
                                //单个重传
                                tr.find('.demo-reload').on('click', function () {
                                    obj.upload(index, file);
                                    return false;
                                });
                                //删除
                                tr.find('.demo-delete').on('click', function () {
                                    delete files[index]; //删除对应的文件
                                    tr.remove();
                                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file å€¼ï¼Œä»¥å…åˆ é™¤åŽå‡ºçŽ°åŒåæ–‡ä»¶ä¸å¯é€‰
                                });
                                ProImgByList.append(tr);
                            });
                        }
                        , done: function (res, index, upload) {
                            if (res.code == 1) { //上传成功
                                var tr = ProImgByList.find('tr#upload-' + index)
                                    , tds = tr.children();
                                tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
                                tds.eq(4).html(''); //清空操作
                                return delete this.files[index]; //删除文件队列已经上传成功的文件
                            }
                            this.error(index, upload);
                        }
                        , error: function (index, upload) {
                            var tr = ProImgByList.find('tr#upload-' + index)
                                , tds = tr.children();
                            tds.eq(2).html('<span style="color: #FF5722;">上传失败[检查文件名及文件格式]</span>');
                            tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示上传
                        }
                    });
            }
            //#endregion
            //#region ç¼–辑时,获取已上传的文件列表
            function getFile() {
                var ProImgByList = $('#ProImgByList')
                $.ajax({
                    url: GetWEBURL() + '/Sb_EquipDotCheckBill/Filelist',
                    type: "GET",
                    data: { "HBillNo": $("#HBillNo").val() },
                    success: function (data1) {
                        if (data1.count == 1) {
                            var index = 0;
                            for (var i = 0; i < data1.data.length; i++) {
                                var tr = $(['<tr id="upload-' + i + '">'
                                    , '<td style="display:none">' + data1.data[i].HItemID + '</td>'
                                    , '<td style="display:none">' + data1.data[i].HSourceBillNo + '</td>'
                                    , '<td>' + data1.data[i].HFileName + '</td>'
                                    , '<td>' + '<img onclick=\"previewImg(this)\" id="showImg' + i + '" class="ImgClass" style="width: 150px; margin:10px;cursor:pointer;"src="' + data1.data[i].HFilePath + '" alt="' + data1.data[i].HFileName + '">' + '</td>'
                                    , '<td>' + (data1.data[i].HFileSize / 1014).toFixed(1) + 'kb</td>'
                                    , '<td style="color: #5FB878;">上传成功</td>'
                                    , '<td style="display:none">' + data1.data[i].url + '</td>'
                                    , '<td>'
                                    , '<button class="layui-btn layui-btn-xs  demo-dowload" type="button" id="deltefile" onclick="javascript:dowload(this)"><i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>下载</button>'
                                    , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" type="button" id="deltefile" onclick="javascript:toManager(this)"><i class="layui-icon layui-icon-delete layuiadmin-button-btn"></i>删除</button>'
                                    , '</td>'
                                    , '</tr>'].join(''));
                                $('#ProImgByList').append(tr);
                            }
                        } else {
                            layer.alert(data1.code + data1.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            }
            //#endregion
            // è¡¨å•数据编辑时间格式化
            function formatDate(date) {
                var d = new Date(date),
@@ -1143,6 +1280,72 @@
        function GetHManagerValue(obj) {
            OptionData = obj;
        }
        function previewImg(obj) {
            var img = new Image();
            img.src = obj.src;
            var height = img.height * 1.2; //获取图片高度
            var width = img.width * 1.2; //获取图片宽度
            var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%'/>";
            //弹出层
            layer.open({
                type: 1,
                shade: 0.8,
                offset: 'auto',
                area: ['80%', '80%'],
                shadeClose: true,
                scrollbar: false,
                title: "图片预览", //不显示标题
                content: imgHtml, //捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响
                cancel: function () {
                    //layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', { time: 5000, icon: 6 });
                }
            });
        }
        //#region ä¸‹è½½å·²ä¸Šä¼ çš„æ–‡ä»¶
        function dowload(r) {
            //得到当前所在行
            var rows = r.parentNode.parentNode.rowIndex;
            //得到所在行的第五列的内容:文件地址
            var url = $("#ProImgByList tr:eq(" + (rows - 1) + ") td:eq(6)").html();
            /*window.location.href = url;*/
            window.open(url)
        }
        //#endregion
        //#region åˆ é™¤å·²ä¸Šä¼ çš„æ–‡ä»¶
        function toManager(r) {
            //得到当前所在行
            var rows = r.parentNode.parentNode.rowIndex;
            //得到所在行的第一列的内容:主键ID
            var HItemID = $("#ProImgByList tr:eq(" + (rows - 1) + ") td:eq(0)").html();
            //得到所在行的第二列的内容:单据号
            var HSourceBillNo = $("#ProImgByList tr:eq(" + (rows - 1) + ") td:eq(1)").html();
            //得到所在行的第三列的内容:文件名称
            var HFileName = $("#ProImgByList tr:eq(" + (rows - 1) + ") td:eq(2)").html();
            layer.confirm("确认要删除吗,删除后不能恢复", { title: "删除确认" }, function (index) {
                //删除已上传文件
                $.ajax({
                    url: GetWEBURL() + '/Sb_EquipDotCheckBill/DeleteFilelist',
                    type: "GET",
                    data: { "HItemID": HItemID, "HSourceBillNo": HSourceBillNo, "HFileName": HFileName },
                    success: function (data1) {
                        if (data1.count == 1) {
                            layer.alert(data1.Message, { icon: 1 });
                            $("#ProImgByList tr").eq((rows - 1)).remove();
                        }
                        else {
                            layer.alert(data1.code + data1.Message, { icon: 5 });
                        }
                    }, error: function () {
                        layer.alert("接口请求失败!", { icon: 5 });
                    }
                });
            })
        }
        //#endregion
    </script>
</body>
</html>