<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3>短信PUSH发送</h3>
            <ul class="tab-base">
                <li><a href="index.php?act=oper_sms&op=index"><span><?php echo $lang['nc_manage']?></span></a></li>
                <li><a href="index.php?act=oper_sms&op=send_sms_push" class="current"><span>短信push发送</span></a></li>
                <li><a href="index.php?act=oper_sms&op=awaken_user"><span>激活用户</span></a></li>
            </ul>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <form id="points_form" method="post" name="form1">
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2 nobdb">
            <tbody>
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation"><?php echo $lang['admin_points_membername']; ?>(搜索方式)：</label>
                    <select name="input_type" id="input_type">
                        <option value="mobiles">电话号码(会员名称)</option>
                        <option value="sql">SQL语句</option>
                    </select>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <textarea name="members" id="members" cols="100" rows="10" class="members"></textarea>
            </tr>
            <tr>
                <td><label>是否排除品牌方：<input type="checkbox" name="ex_brand"></label></td>
            </tr>
            <tr>
                <td><label>是否排除公司员工：<input type="checkbox" name="ex_lrlz"></label></td>
            </tr>
            <tr id="tr_memberinfo">
                <td colspan="2" style="font-weight:bold;" id="td_memberinfo"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label>发送类型:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><select id="operatetype" name="operatetype">
                        <option value="sms">短信发送</option>
                        <option value="push">push发送</option>
                    </select></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="push">
                <td colspan="2" class="required"><label class="validation">push内容:</label></td>
            </tr>
            <tr class="noborder push">
                <td class="vatop rowform"><textarea name="pushcontet" rows="6" class="tarea"></textarea></td>
            </tr>

            <tr style="background: rgb(255, 255, 255);" class="sms_template_choose">
                <td colspan="2" class="required"><label class="validation">短信模板选择:</label></td>
            </tr>
            <tr class="sms_template_choose">
                <td>
                    <select name="sms_template" id="sms_template">
                        <?php
                        $sms_tpls = $output['sms_tpls'];
                        foreach ($sms_tpls as $sms) {
                            echo "<option value=\"{$sms['yuntx_id']}\">{$sms['title']}</option>";
                        }
                        ?>
                    </select>
                </td>
            </tr>
            <tr class="sms_template_choose">
                <td colspan="2" class="required">模板内容：</td>
            </tr>
            <tr class="sms_template_choose">
                <td id="sms_content">
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="2" ><a href="JavaScript:void(0);" class="btn" id="submit_form"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript">
    function checkmember()
    {
        var membername = $.trim($("#member_name").val());
        if(membername == ''){
            $("#member_id").val('0');
            alert(<?php echo $lang['admin_points_addmembername_error']; ?>);
            return false;
        }
        $.getJSON("index.php?act=points&op=checkmember", {'name':membername}, function(data){
            if (data)
            {
                $("#tr_memberinfo").show();
                var msg= "<?php echo $lang['admin_points_member_tip']; ?> "+ data.name + "<?php echo $lang['admin_points_member_tip_2']; ?>" + data.points;
                $("#member_name").val(data.name);
                $("#member_id").val(data.id);
                $("#td_memberinfo").text(msg);
            }
            else
            {
                $("#member_name").val('');
                $("#member_id").val('0');
                alert("<?php echo $lang['admin_points_userrecord_error']; ?>");
            }
        });
    }
    $(function(){
        $("#tr_memberinfo").hide();

        $('#points_form').validate({
            rules : {
                member_name: {
                    required : true
                },
                member_id: {
                    required : true
                },
                bonus_rate   : {
                    required : true,
                    min : 1
                }
            },
            messages : {
                member_name: {
                    required : '<?php echo $lang['admin_points_addmembername_error'];?>'
                },
                member_id : {
                    required : '<?php echo $lang['admin_points_member_error_again'];?>'
                },
                bonus_rate  : {
                    required : '<?php echo $lang['admin_points_points_null_error']; ?>',
                    min : '<?php echo $lang['admin_points_points_min_error']; ?>'
                }
            }
        });
        $('#send_sms').on('click',function(){
            var $sms_template_choose=$('.sms_template_choose');
            if($(this).is(":checked")){
                $sms_template_choose.show('500');
            }
            else {
                $sms_template_choose.hide('500');
            }
        });

        var desc_array = {};
        <?php
            $sms_tpls = $output['sms_tpls'];
            foreach ($sms_tpls as $sms) {
                echo "desc_array[{$sms["yuntx_id"]}]=\"{$sms["content"]}\";";
            }
        ?>
        $('#sms_template').on('change',function()
        {
            type = $(this).val();
            desc = desc_array[type];
            $('#sms_content').text(desc);
        });
        $('#sms_template').trigger('change');
        function typeChange(){
            var operatetype=$('#operatetype').val();
            if(operatetype == 'sms'){
                $('.push').hide();
                $('.sms_template_choose').show();
            }
            else {
                $('.sms_template_choose').hide();
                $('.push').show();
            }
        }
        $('#operatetype').on('change',function(){
            typeChange();
        });
        $('#operatetype').trigger('change');
        $('#submit_form').on('click',function(){
            var confirm=window.confirm('确认提交？');
            if(confirm) {
                document.form1.submit();
            }
            else {
                return;
            }
        })
    });


</script>