<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContractSigningFileUp.aspx.cs" Inherits="M_Main.CostManageNew.ContractSigningFileUp" %>
 
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>合同附件详细页面</title>
    <link href="../css/button.css" rel="stylesheet" />
    <script type="text/javascript" src="../Jscript/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../Jscript/json2.js"></script>
    <script src="../jscript/jquery.tool.new.js" type="text/javascript"></script>
    <script type="text/javascript" src="../jscript/help.js"></script>
    <script src="../jscript/Dialog.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../Jscript-Ui/jquery-easyui-1.4.4/themes/icon.css" />
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Jscript-Ui/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="../css/framesearch.css" type="text/css" rel="stylesheet" />
    <script type="text/javascript" src="../Jscript-Ui/JQForm/JQForm.js"></script>
    <script type="text/javascript" src="../jscript/DateFormat.js"></script>
    <script type="text/javascript" src="../jscript/jquery.form.js"></script>
    <style type="text/css">
      
 

        .SearchTable tr td {
            color: #666;
            padding: 5px;
            background: #F8F8F8;
            border-right: 1px solid #E7EAEC;
            border-bottom: 1px solid #E7EAEC;
        }

        .SearchTable tr .TdTitle {
            width: 8%;
            text-align: right;
            background: #F8F8F8;
        }

         

        
    </style>
</head>
<body style="overflow: auto; margin: 0px; padding: 0px;">
 

    <fieldset class="frame-fieldset" style="border: 1px solid #cccccc;">
        <legend class="frame-legend">附件</legend>
        <div id="mainTableContainer">
            <form id="fileForm">
                 <div id="up_div">
                    <a id="tip" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'"></a>
                    <input type="hidden" name="FileType" id="FileType" />
                    <input type="hidden" name="FilePath" id="FilePath" />
                    <input type="hidden" name="FileCode" id="FileCode" />  
                    <input id="uploadFile" name="uploadFile" class="easyui-filebox" data-options="width:'210px',buttonText:'选择文件',prompt:'请选择一个文件...'" />
                    <input id="FileName" name="FileName" class="easyui-textbox" data-options="width:'250px',prompt:'文件名称'" />
                    <a href="#" id="btn_upload" onclick="SaveFile()" class="easyui-linkbutton" data-options="iconCls:'icon-save',width:80">上传</a>
                </div>
                <table id="TableContainer" style="width: 100%; height: 190px;"></table>
            </form>
        </div>
    </fieldset>

    <div style="text-align: center; width: 100%; padding: 5px 0;">
        <input type="button" class="button" value="确定" id="BtnSave" onclick="Save();" runat="server" /> 
    </div>

    <input type="hidden" id="ID" name="ID" runat="server" />
    <input type="hidden" id="Status" name="Status" runat="server" />
    <input type="hidden" id="OpType" name="OpType" runat="server" />
    <input type="hidden" id="Flag" name="Flag" value="0" runat="server" />
    <input type="hidden" id="Type" name="Type" value="" runat="server" />
    <script language="javascript" type="text/javascript">
        function btnClose() {
            HDialog.Close("");
        }
         
        //加载页面数据
        function LoadBaseData() {
 
            //加载附件
            LoadFile();
        }
        //保存
        function Save() {
            HDialog.Close(""); 
        }
        var column = [[
            {
                field: 'FilesNO', title: '附件编号', width: 100, align: 'left', sortable: false, formatter: function (value, row, index) {
                    if (value.lastIndexOf('.') == -1) {
                        return value;
                    } else {
                        var arr = value.split('.');
                        return arr[0]; 
                    }
                  
                }
            },
            {
                field: 'FilesName', title: '附件名称', width: 160, align: 'left', sortable: false, formatter: function (value, row, index) {
                    value = GetAHtml(row.FilesPath, value);
                    return value;
                }
            },
            { field: 'Fix', title: '附件类型', width: 40, align: 'center', sortable: false },
            { field: 'AddTime', title: '添加日期', width: 60, align: 'center', sortable: false },
            {
                field: 'Opt', title: '操作', width: 40, align: 'center', sortable: false, formatter: function (value, row, index) { 
                        return "<a href=\"javascript:DelFile('" + row.CFilesId + "')\" >删除</a>"; 
                }
            }
        ]];
        function GetAHtml(url, fileName) {
            var html = "";
            if (url && url != "") {
                var arr = url.split('/');
                var name = arr[arr.length - 1];
                arr = name.split('.');
                var IdNew = arr[arr.length - 2];
                html = "<a target=\"_blank\" id=\"11831617369\" href=\"" + url + "\" class=\"HrefStyle\" url=\"" + url + "\">" + fileName + "</a>";
            }
            return html;
        }

        //上传附件
        function SaveFile() {
            var file = $("input[name='uploadFile']")[0].files[0];
            if (file) {
                if ($("#FileName").textbox("getValue") == "") {
                    HDialog.Info("请输入附件名称");
                    return;
                }
                var maxsize = 2 * 1024 * 1024;
                var tipFileSize = 2;
                var fileType = file.type;

                if (file.size > parseInt(maxsize)) {
                    HDialog.Info("不能上传超过" + tipFileSize + "M的附件！");
                    return false;
                }

                $.tool.pageLoadInfo("上传中，请等待");
                var options = {
                    type: "POST",
                    url: "../AjaxUploadFile.aspx?Cmd=ins&FileType=ContractSigningFile&FileURL=",
                    //data: "upfile=" + $("#uploadfile").val(),
                    success: function (data, status) {
                        $.tool.pageUnLoading();
                        var stringArray = data.split("|");
                        var FileName = stringArray[1];
                        var FileError = stringArray[2];
                        var FileURL = stringArray[3];
                        var FileServerName = stringArray[4];
                        if (stringArray[0] == "1") {
                            //stringArray[0]    成功状态(1为成功，0为失败)
                            //stringArray[1]    文件名
                            //stringArray[2]    消息提示
                            //stringArray[3]    文件路径
                            UploadCallBack(FileURL, FileName);
                        }
                        else {
                            HDialog.Info(FileError);
                        }

                    },
                    error: function (data, status, e) {
                        HDialog.Info(e.toString());
                        $.tool.pageUnLoading();
                    }
                };
                $('#fileForm').ajaxSubmit(options);
                return false;//.NET按钮控件取消提交
            } else {
                HDialog.Info("请选择附件");
            }
        }

        //上传文件相关绑定
        function UploadCallBack(url, Name) {
            var parameterStr = {
                FileCode: Name,
                FilesPath: url,
                CId: $('#ID').val(),
                Fix: $("#FileType").val(),
                HidFilesName: $("#FileName").textbox("getValue"),
                HidRemark: "",
                Sort:"1"
            };
            $.dataPostJson('CsCost', 'SaveContractFilesDetail', parameterStr, true, false,
                function Init() {
                },
                function callback(data) {
                    if (data=="true") {
                        $('#uploadFile').filebox('clear');
                        $('#FileName').textbox('clear');
                        $("#TableContainer").datagrid("reload");
                    } else {
                        $.messager.alert('温馨提示', "上传成功");
                        $("#TableContainer").datagrid("reload");
                    }
                },
                function completeCallback() {

                }, function errorCallback() {

                });
        }

        //删除附件
        function DelFile(idList) {
            if ($('#AuditStatus').val() == "已审核" || $('#Flag').val() == "1") {
                return;
            }
            $.messager.confirm('温馨提示', '确定删除?', function (r) {
                if (r) {
                    $.dataPostJson('CsCost', 'DelContractFiles', { "CFilesId": idList }, true, false,
                        function Init() {
                        },
                        function callback(data) { 
                                $("#TableContainer").datagrid("reload"); 
                        },
                        function completeCallback() {
                        }, function errorCallback() {
                        });
                }
            });
        }

        //加载附件
        function LoadFile() {
            $("#TableContainer").datagrid({
                url: '/HM/M_Main/HC/DataPost.aspx',
                method: "post",
                nowrap: false,
                pageSize: top.ListPageSize,
                pageList: top.ListPageList,
                columns: column,
                rownumbers: true,
                fitColumns: true,
                checkbox: true,
                singleSelect: true,
                checkOnSelect: false,
                selectOnCheck: false,
                border: true,
                pagination: true,
                width: "100%",
                sortOrder: "desc",
                height:"570",
                remoteSort: false,
                onBeforeLoad: function (param) { 
                    param.CId = $('#ID').val();
                    param = $.getDataGridParam("CsCost", "GetContractFilesList", param);

                },
                onLoadSuccess: function (data) {
                },
                onLoadError: function (data) {

                }
            });
        }

        $(function () {
            $('#tip').tooltip({
                position: 'top',
                content: '<div><p>1、文件限制最大为2M。</p></div>',
            });
            $('#uploadFile').filebox({
                onChange: function (newValue, oldValue) {
                    if (newValue != "") {
                        var s = newValue.lastIndexOf("\\");
                        var e = newValue.lastIndexOf(".");
                        var fileName = newValue.substring(s + 1, e);//文件名不带后缀
                        var fileType = newValue.substring(e + 1, newValue.length);//文件后缀
                        $("#FileType").val(fileType);
                        $("#FileName").textbox("setValue", fileName);
                    }
                }
            });
            //console.log($("#Status").val());
            //if ($("#Status").val() == "已审核")
            //{
            //    $("#up_div").hide(); 
            //}
            LoadBaseData();
        });
    </script>

</body>
</html>
