/// <reference path="jquery-3.3.1.min.js" />

var img = $("#imgSelf");
var Upload = $("#imgUpload");
Upload.change(function () {
    var file = this.files[0];
    if (file.type.indexOf("image") == -1) {
        alert("请选择图片文件！");
        return;
    }
    if (file.size > 1024 * 1024 * 3) {
        alert("图片过大，请选择小于3M的图片");
        return;
    }
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (fl) {
        var ImgCoding = reader.result;
        $.ajax({
            type: "Post",
            url: "./Admin_UserEdit.aspx/SaveImg",
            data: "{ImgCoding:'" + ImgCoding + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            timeout: '5000',
            success: function (data) {
                if (data.d != "") {
                    img.attr("src", data.d);
                } else {
                    alert("图片保存失败！");
                }
            },
            error: function (err) {
                alert("图片上传出错！")
            }
        });
    }
})

var imgs = $("#imgSelfs");
var Uploads = $("#imgUploads");
Uploads.change(function () {
    var file = this.files[0];
    if (file.type.indexOf("image") == -1) {
        alert("请选择图片文件！");
        return;
    }
    if (file.size > 1024 * 1024 * 3) {
        alert("图片过大，请选择小于3M的图片");
        return;
    }
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (fl) {
        var ImgCodings = reader.result;
        $.ajax({
            type: "Post",
            url: "./Admin_UserEdit.aspx/SaveImgs",
            data: "{ImgCodings:'" + ImgCodings + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            timeout: '5000',
            success: function (data) {
                if (data.d != "") {
                    imgs.attr("src", data.d);
                } else {
                    alert("图片保存失败！");
                }
            },
            error: function (err) {
                alert("图片上传出错！")
            }
        });
    }
})

var imgz = $("#imgSelfz");
var Uploadz = $("#imgUploadz");
Uploadz.change(function () {
    var file = this.files[0];
    if (file.type.indexOf("image") == -1) {
        alert("请选择图片文件！");
        return;
    }
    if (file.size > 1024 * 1024 * 3) {
        alert("图片过大，请选择小于3M的图片");
        return;
    }
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (fl) {
        var ImgCodingz = reader.result;
        $.ajax({
            type: "Post",
            url: "./Admin_UserEdit.aspx/SaveImgz",
            data: "{ImgCodingz:'" + ImgCodingz + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            timeout: '5000',
            success: function (data) {
                if (data.d != "") {
                    imgz.attr("src", data.d);
                } else {
                    alert("图片保存失败！");
                }
            },
            error: function (err) {
                alert("图片上传出错！")
            }
        });
    }
})
