<?xml version="1.0" encoding="UTF-8"?>
<h:screen xmlns:h="http://www.hand-china.com/hap">
    <script src="${base.contextPath}/common/code?channelNoticeTypeData=SYS.CHANNEL_NOTICE_TYPE" type="text/javascript"></script>
    <script type="text/javascript"><![CDATA[
    /*=============数据源定义==============================================================================================*/
    var sendNoticeType;
    /*=============基础函数================================================================================================*/
    var viewModel = kendo.observable({
        model: {},
        query : function () {
            viewModel.model.fromChannel = $("#fromChannel").val();
            $("#gridId").data("kendoGrid").dataSource.page(1);
        }
    });
    function parameterMap (options,type) {
        if(type != "read" && options.models) {
            var datas = options.models;
            if(type == "create" || type == "update") {
                datas = options.models.map(function (data) {
                    data["__status"] = (type == "create" ? "add" : "update");
                    return data;
                });
            }
            return kendo.stringify(datas);
        } else if(type == "read") {
            var map = {};
            map.page = options.page;
            map.pagesize = options.pageSize;
            map.fromChannel = viewModel.model.fromChannel;
            for(var k in map) {
                if(map[k] == "" || map[k] == null || map[k] == undefined) {
                    delete map[k];
                }
            }
            return map;
        }
    };
    function dsEditable() {
        return true;
    }
    function gridLocate(e){
        var d = this.dataItem(e.element);
    }
    /*==========字段函数===================================================================================================*/
    function toChannelType(dataItem) {
        $.ajax({
            type: "post",
            url: "${base.contextPath}/sys/channel/pass/manage/query",
            dataType: "json",
            async:false,
            contentType: 'application/json',
            success: function (datas) {
                if (datas.total !== 0) {
                    sendNoticeType = datas.rows;
                }

            }
        });
        var meaning = '';
        sendNoticeType.forEach(function (value, key, map) {
            if((dataItem.toChannel) && (value.passValue == dataItem.toChannel)){
                meaning = value.passName;
            }
        });
        return meaning
    }
    function sendSuccessFn(dataItem) {
        return (dataItem.sendSuccess!="true")?"发送失败":"发送成功";
    }
    function sendMsgTypeFn(dataItem) {
        if(dataItem.sendMsgType == 'USER_DEFINED_SEND'){
            return '自定义渠道发送';
        }else {
            var meaning = '';
            channelNoticeTypeData.forEach(function (value, key, map) {
                if((dataItem.sendMsgType) && (value.value == dataItem.sendMsgType)){
                    meaning = value.meaning;
                }
            });
            return meaning
        }
    }

    /*======查询函数=======================================================================================================*/

    /*========弹出框=======================================================================================================*/
    function sss(data) {
        var i=0;
    }

    ]]></script>
    <div id="blacklist"></div>
    <h:dataSource id="DataSource" batch="true" pageSize="20" serverPaging="true">
        <h:transport parameterMap="parameterMap">
            <h:read url="${base.contextPath}/sys/channel/notice/query?toChannel=wechat" type="POST" dataType="json"/>
        </h:transport>
        <h:schema data="rows" total="total">
            <h:model id="channelNoticeId" editable="dsEditable">
                <h:fields>
                </h:fields>
            </h:model>
        </h:schema>
    </h:dataSource>
    <h:hlsGridBox hlsGridId="gridId" title="" hlsBtnType="query" queryIds="fromChannel"
                  queryPlaceHolders="消息类型">
        <h:hlsGrid id="gridId" dataSource="DataSource" dataBound="sss" navigatable="true" locate="gridLocate" height="400px"
                   editable="false" hlsBtnType="" resizable="true">
            <h:pageable pageSizes="5,10,20,50,all" buttonCount="2" refresh="true">
            </h:pageable>
            <h:columns>
                <h:column field="fromChannel" title='<@spring.message "发件人"/>' width="120" >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="content" title='<@spring.message "内容"/>' width="120" >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="openId" title='<@spring.message "联系方式"/>' width="220" >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="creationDate" title='<@spring.message "发送时间"/>' width="150" >
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="toChannel" title='<@spring.message "发送渠道"/>' width="120" template="fn:toChannelType">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="sendMsgType" title='<@spring.message "消息类型"/>' width="100" template="fn:sendMsgTypeFn">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
                <h:column field="sendSuccess" title='<@spring.message "发送结果"/>' width="100" template="fn:sendSuccessFn">
                    <h:headerAttributes style="text-align:center"/>
                    <h:attributes style="text-align:center"/>
                </h:column>
            </h:columns>
        </h:hlsGrid>
    </h:hlsGridBox>
</h:screen>