$(function () {
    var $iosActionsheet = $('#iosActionsheet');
    var $iosMask = $('#iosMask');

    function hideActionSheet() {
        $iosActionsheet.removeClass('weui-actionsheet_toggle');
        $iosMask.fadeOut(200);
    }

    $iosMask.on('click', hideActionSheet);
    $('#iosActionsheetCancel').on('click', hideActionSheet);
    $(".list").on("click", function () {
        $iosActionsheet.addClass('weui-actionsheet_toggle');
        $iosMask.fadeIn(200);

        $iosActionsheet.attr('data-id',$(this).attr('data-id'))
        $iosActionsheet.attr('data-qrcode',$(this).attr('data-qrcode'))
    });

    //搜索
    $('#searchInput').on('change',function(){
        $('form').submit()
    })
    //编辑 //统计
    let href=['release_vote_mobile?edit=','vote_statistics_mobile?id=','','','vote_management_mobile?clear=','vote_management_mobile?delete=']
    $('.release_vote_btn,.vote_statistics_btn').on('click',function(){
        let id = $iosActionsheet.attr('data-id')
        if(id){
            window.location.href=href[$(this).index()]+id
        }      
    })
    //二维码
    $('.qrcode_btn').on('click',function(){
        let qrcode = $iosActionsheet.attr('data-qrcode')
        layer.open({
            type: 1,
			title: false,
			closeBtn: 0,
			shadeClose: true,
            content:'<img src="'+qrcode+'" onload="kg.img_auto_size(this)" height="250">'
        })
    })
   //清理投票
   $('.clear_btn').on('click',function(){
        let id = $iosActionsheet.attr('data-id')
        layer.open({
            type: 0,
            btn: ['确定', '取消'],
            title: false,
            closeBtn: 0,
            shadeClose: true,
            content:'确定要清理投票数据吗',
            yes: function (index) {
                layer.close(index);
                window.location.href=href[4]+id;
            }
        })
    })

    //删除投票
   $('.delete_btn').on('click',function(){
    let id = $iosActionsheet.attr('data-id')
        layer.open({
            type: 0,
            btn: ['确定', '取消'],
            title: false,
            closeBtn: 0,
            shadeClose: true,
            content:'确定要删除该投票吗',
            yes: function (index) {
                layer.close(index);
                window.location.href=href[5]+id;
            }
        })
    })

});