{layout name="manager/layout"}

<div class="layuimini-container location-operate-page location-add-page">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">

            <div class="layui-form-item">
                <label class="layui-form-label">消息标题</label>
                <div class="layui-input-block">
                    <input type="text" name="item[title]" placeholder="请输入消息标题" class="layui-input" maxlength="100">
                </div>
            </div>

            <!--
            <div class="layui-formitem">
                <label class="layui-form-label">消息简述</label>
                <div class="layui-input-block">
                    <input type="text" name="item[summary]" placeholder="请输入消息简述" class="layui-input" >
                </div>
            </div>
            -->

            <div class="layui-form-item field-div">
                <label class="layui-form-label required">消息类型</label>
                <div class="layui-input-block">
                    <select class="layui-select" name="item[type]">
                        {foreach $typeList as $ki => $kv}
                        <option value="{$ki}">{$kv}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">目标人群</label>
                <div class="layui-input-block">
                    <select name="item[target]" lay-filter="target">
                        {foreach $targetList as $ki => $kv}
                        <option value="{$ki}">{$kv}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item target-list layui-hide">
                <label class="layui-form-label required">接收用户</label>
                <div class="layui-input-block">
                    <div id="receive-users"></div>
                </div>
            </div>

            <div id="row">
                <div class="layui-row" id="row_one" style="border: rgba(139,174,255,0.51) 1px solid;padding: 20px ;;margin: 20px auto ">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择发送时间</label>
                        <div class="layui-input-block">
                            <input type="text"   name="fdata[0][send_at]" placeholder="" class="send_at layui-input msg-send-at"
                                autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label ">话术模板</label>
                        <div class="layui-input-block">
                            <select  class="script_management"  lay-filter="script_management">
                                <option value="">请选择</option>
                                {foreach  $script_management as $ki => $kv}
                                <option value="{$ki}">{$kv.title}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label required">消息内容</label>
                        <div class="layui-input-block">
                            <textarea name="fdata[0][content]" class="layui-textarea content"  placeholder="请输入消息内容" rows="10"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required"></label>
                        <div class="layui-input-block">
                            <button class="del-row layui-btn layui-btn-danger layui-hide" lay-submit lay-filter="del_row">删除节点</button>
                        </div>
                    </div>

                </div>

            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" data-url="/manager/message/add" lay-submit lay-filter="saveBtn">确认保存</button>
                    <button class="layui-btn layui-btn-primary" lay-submit lay-filter="add_row">添加节点</button>
                </div>
            </div>

        </div>
    </div>
</div>
<script>
    layui.use([ 'jquery', 'form',"xmSelect","laydate"], function () {
        let $ = layui.jquery,
            xmSelect = layui.xmSelect,
            laydate = layui.laydate,
            form = layui.form;

        // var timexmSelect =  xmSelect.render({
        //     el: '#send_at',
        //     paging: false,
        //     autoRow: true,
        //     name: 'item[send_at]',
        //     tips: '请选择时间',
        //     direction: 'auto',
        //     height: 'auto',
        //     model: {
        //         icon: 'hidden',
        //     },
        //     prop: {
        //         name: 'title',
        //         value: 'key',
        //     },
        //     theme: {
        //         color: '#1e84ff',
        //     },
        //     data: [
        //         // {title: '张三', value: 1},
        //     ],
        // });



        var script_management_json = {$script_management_json|raw};
        // console.log(script_management_json)
        // 监听搜索操作
        form.on('select(script_management)', function (data) {
                // console.log(data.value);
                // console.log(script_management_json);
                // console.log(script_management_json[data.value].content);
            console.log($(this).parents(".layui-row")
                .children(".layui-form-item")
                .children(".layui-input-block")
                .children(".content")
                .length);

            $(this).parents(".layui-row").children(".layui-form-item").children(".layui-input-block").children(".content").val(script_management_json[data.value].content)
                // $("textarea[name='item[content]']").val();
            return false;
        });
        let curDateTime = date('Y-m-d H:i:s');
        laydate.render({
            elem: '.msg-send-at'
            ,type: 'datetime'
            ,min: curDateTime
            ,done: function(value, date){ //监听日期被切换

                //执行函数

                // var timeArray = timexmSelect.getValue();
                //
                // timeArray.forEach((elem, index) => {
                //     elem["selected"] = true;
                // });
                // timeArray.push({"title": value, "key": value,"selected": true});
                //
                // console.log(timeArray);
                //
                // timexmSelect.update({
                //     data: timeArray
                // });
            }
        });

    })
</script>
<script src="__MANAGER__/js/message.js?v={:mt_rand()}"></script>