function logger(msg) {
    document.getElementById("logger").innerHTML =  msg;
}

function addPhoto(base64) {
    picLayout = document.getElementById("pic-layout");
    var li = document.createElement("li");
    var img = document.createElement("img");
    img.setAttribute("src", base64);
    li.appendChild(img);
    picLayout.appendChild(li);
}


//离开页面关闭高拍仪
function checkLeave() {
    send_command(
        "closeCamera",
        "nothing"
        );
}

//打开高拍仪、设置相对位置、窗口大小
function openCameras() {

    //重复打开，打开前先关闭
    function checkLeave() {
        send_command(
            "closeCamera",
            "nothing"
        );
    }
    checkLeave();

    logger('打开高拍仪');
    //var layout = { 'layoutX': 50, 'layoutY': 200, 'layoutWidth': 690, 'layoutHeight': 550 };
    var layout = { 'layoutX': 100, 'layoutY': 230, 'layoutWidth': 627, 'layoutHeight': 500 };
    var jsonlayout=JSON.stringify(layout);
    send_command(
        "openCamera",
        jsonlayout,
        function (receivedData) {
            // logger(receivedData);
            // logger('回调成功');
        });
}

//开始拍照
function takePhotos() {
    logger('开始拍照');
    send_command(
        "takePhoto",
        "nothing",
        function (receivedData) {
            var photoBean = JSON.parse(receivedData);
            if (photoBean.status == 100) {
                logger('status=100');
                base64="data:image/jpeg;base64," + photoBean.imgStr;
                addPhoto(base64);
            }
        });
}

//关闭相机
function closeCameras() {
    var msg = "";
    var msgUrl = "";
    //logger('关闭');

    var imgpath= [];
    var i=0;
    var lis = $('#pic-layout li img');
    msg += "一共" + lis.length+"张图片;";
    lis.each(function () {
        imgpath[i]=$(this).attr('src');
        i = i + 1;
        msgUrl += i;
    });
    //msg += imgpath.length+"url";
    //logger(imgpath.length+"url");

    var m_info = "";

    function saveInfo() {
      // m_info=imgpath[0];
        //save_info(m_info);
       // var m_info = "";
        for (var i = 0; i < imgpath.length; i++) {
            //m_info = imgpath[0];
            if (imgpath.length == 1) {
                //logger("first1");
                msg += "first1";
                m_info = imgpath[0];
            }
            else {
                msg += "第" + (i + 1) + "张";
                m_info += "*$*"+imgpath[i];
            }
           
        }
        save_info(m_info);
      
    }
    
    saveInfo();

    msg += msgUrl;
    logger(msg);


    send_command(
        "closeCamera",
        "nothing"
    );
    function jump() {
        //window.location.href = 'sweepattachment.html';
        window.location.href = 'CLlist';
    }
    jump();
}

openCameras();