<%@ Page Language="C#" MasterPageFile="Main.Master" AutoEventWireup="true" CodeFile="templateDesign.aspx.cs" Inherits="eFrameWork.Manage.templateDesign" %>
<%@ Register Src="GroupMenu.ascx" TagPrefix="uc1" TagName="GroupMenu" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<uc1:GroupMenu runat="server" ID="GroupMenu" />
<link rel="stylesheet" href="../Plugins/luckysheet/pluginsCss.css" />
<link rel="stylesheet" href="../Plugins/luckysheet/plugins.css" />
<link rel="stylesheet" href="../Plugins/luckysheet/luckysheet.css" />
<link rel="stylesheet" href="../Plugins/luckysheet/iconfont.css" />
<script src="../Plugins/luckysheet/plugin.js"></script>
<script src="../Plugins/luckysheet/luckysheet.umd.js"></script>
<script>
    function templateView(TemplateID) {
        var url = "templateView.aspx?TemplateID=" + TemplateID;
        layer.open({
            anim: 4,//设置出现的动画效果 4 1 2 0
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            title: "查看模板",
            maxmin: false,
            shadeClose: true, //点击遮罩关闭层
            area: ['75%', '80%'],
            content: url,
            success: function (layero, index) { },
            cancel: function (index, layero) { },
            end: function (index) { }
        });
    };
</script>
<div class="nav">您当前位置：<a href="Default.aspx">首页</a> -> 数据模板<a class="button" href="javascript:;" onclick="bindField();"><span><i class="add">绑定数据</i></span></a><a class="button" href="javascript:;" onclick="templateView('<%=TemplateID %>');"><span><i class="view">查看</i></span></a></div>
    
<div style="margin:10px;">
<h2 style="margin-bottom:8px;"><%=template.Name %></h2>
<div id="luckysheet" style="margin:0px;padding:0px;width:100%;height:500px;"></div>
</div>

<script>
    function setFunction(schr,echr)
    {
        var range = luckysheet.getRange();
        if(range)
        {
            var v=luckysheet.getCellValue(range[0].row[0],range[0].column[0]);
            if(v==null || v.length==0)
            {
                layer.msg('请先引用数据!');
                return;
            }
            if(v.indexOf(schr)>-1)
            {
                layer.msg('请勿重复引用!');
                return;
            }
            luckysheet.setCellValue(range[0].row[0],range[0].column[0],schr + v + echr);
        }
    }
    function setValue(v)
    {
        var range = luckysheet.getRange();
        if(range)
        {
            luckysheet.setCellValue(range[0].row[0],range[0].column[0],v);
        }
    }
    function appendValue(v)
    {  
        var range = luckysheet.getRange();
        if(range)
        {
            var ov=luckysheet.getCellValue(range[0].row[0],range[0].column[0])||'';
            luckysheet.setCellValue(range[0].row[0],range[0].column[0],ov+v);
        }
    }
    function bindField()
    {
        var url = "setReocrdField.aspx?TemplateID=" + document.location.href.getquerystring("TemplateID");
        layer.open({
            anim: 4,//设置出现的动画效果 4 1 2 0
            type: 2,
            title: "绑定数据",
            shade:0,
            shadeClose: true ,//点击遮罩关闭层
            area: ["380px", "100%"],
            offset: 'r',
            content: url,
            success: function (layero, index) {
              arrLayerIndex.push(index);
          },
          cancel: function (index, layero) {
              arrLayerIndex.pop();
          }

        });
    };

    function updata()
    {
        timer.pause();
        var url = document.location.href;
        url = url.addquerystring("act", "update");
        var designJson = luckysheet.getAllSheets();
        var designData = luckysheet.toJson();
        $.ajax({
            type: 'post',
            url: url,
            data: { designJson: JSON.stringify(designJson),designData: JSON.stringify(designData.data)},
            dataType: "json",
            success: function (data) {
                timer.start();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                timer.start();
            }
        });
    };

    var timer = new eTimer();
    timer.interval = 30000;
    timer.timer = function () {
        //updata();
    }

    $(function ()
    {
        //timer.start();

     $("#luckysheet").css("height",( $(".eLayout_body").height()-100) + 'px');
        var options = { // 公共配置项
            container: 'luckysheet', // luckysheet为容器id
            lang: 'zh', // 设定表格语言
            title: '', // 设定表格名称
            forceCalculation: true,
            index: '0',
            status: '1',
            order: '0',
            hide: '0',
            column: 25, // 列数
            row: 30, // 行数
            showtoolbar: true, // 工具栏
            showinfobar: false, // 信息栏
            showsheetbar: false, // 底部sheet页
            sheetFormulaBar: true, // 是否显示公式栏
            showsheetbarConfig: {},// 自定义底部sheet页
            sheetRightClickConfig: {},//自定义底部sheet页右击菜单 
            //showtoolbarConfig:{}, // 自定义配置工具栏
            //showtoolbarConfig: { undoRedo: false, paintFormat: false }, // 隐藏撤销重做和格式刷
            //showtoolbar: false,
            //showtoolbarConfig: { toolbar: ['undo', 'redo', 'bold', 'italic'] }, // 仅保留撤销、重做、加粗、斜体

            hook: {
                updated: function (operate) {
                    updata();
                },

            },
            cellRightClickConfig:{}, // 右键配置

            data:<%=template.designJson%>,
            data2: [  // 表格sheet的个数和配置项
                {
                    "name": "Sheet1",
                    "defaultRowHeight": 25
                },


            ]
        };


        // 初始化表格
        luckysheet.create(options);
        //luckysheet.bind("cellEdit", callback);
        luckysheet.bind("cellEdit", function () { document.title = "OKK"; })

    });
</script>


</asp:Content>