PHP日程计划管理功能之设置页面(2)

在上一篇笔记《PHP日程计划管理功能之日期计算器(1)》中波波记录了日程计划中核心的日期计算方法,本篇笔记记录日程计划设置的HTML页面。

由于本源码是结合PHP数据渲染编写的,故而在源代码中可能包含一部分PHP表示的变量,包括一些下拉框也是采用PHP输出的。分享本源码的意义仅供参考。以及layui如何实现点击单选框显示不同的表单。

  1. {block name="content"}
  2. <form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='form-horizontal layui-form' style='padding-top:20px;height: 500px'>
  3.     <div class="layui-form-item">
  4.         <label class="layui-form-label">计划类型</label>
  5.         <div class="layui-input-block">
  6.             <input type="radio" name="type" value="year" title="年" {if isset($sched.type) and $sched.type eq 'year'}checked{/if} lay-filter="ttype">
  7.             <input type="radio" name="type" value="month" title="月" {if isset($sched.type) and $sched.type eq 'month'}checked{/if} lay-filter="ttype">
  8.             <input type="radio" name="type" value="week" title="周" {if isset($sched.type) and $sched.type eq 'week'}checked{/if} lay-filter="ttype">
  9.             <input type="radio" name="type" value="day" title="日" {if isset($sched.type) and $sched.type eq 'day'}checked{/if} lay-filter="ttype">
  10.             <input type="radio" name="type" value="hour" title="运行时长" {if isset($sched.type) and $sched.type eq 'hour'}checked{/if} lay-filter="ttype">
  11.         </div>
  12.     </div>
  13.     <!--分割线-->
  14.     <div class="hr-line-dashed"></div>
  15.     <div class="form-group" data-storage-type="year">
  16.         <div class="layui-form-item">
  17.             <div class="layui-input-block">
  18.                 <input type="radio" name="cycle_type" value="week" title="按周" {if isset($sched.cycle_type) and $sched.cycle_type eq 'week'}checked{/if} lay-filter="cycle_type">
  19.                 <input type="radio" name="cycle_type" value="month" title="按月" {if isset($sched.cycle_type) and $sched.cycle_type eq 'month'}checked{/if} lay-filter="cycle_type" >
  20.             </div>
  21.         </div>
  22.     </div>
  23.     <div class="form-group" data-storage-type="year-week" lay-filter="year-week">
  24.         <div class="layui-form-item">
  25.             <label class="layui-form-label">每隔</label>
  26.             <div class='layui-input-inline'>
  27.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  28.             </div>
  29.             <div class="layui-form-mid">年重复,</div>
  30.         </div>
  31.         <div class="layui-form-item">
  32.             <label class="layui-form-label">在</label>
  33.             <div class="layui-input-inline">
  34.                 <select name="month" style="width: 30%" required="required" lay-filter="selc_month">
  35.                     <option value="0">请选择</option>
  36.                     <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>一月</option>
  37.                     <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>二月</option>
  38.                     <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>三月</option>
  39.                     <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>四月</option>
  40.                     <option value="5" {if isset($sched.month) and $sched.month eq 1}selected{/if}>五月</option>
  41.                     <option value="6" {if isset($sched.month) and $sched.month eq 1}selected{/if}>六月</option>
  42.                     <option value="7" {if isset($sched.month) and $sched.month eq 1}selected{/if}>七月</option>
  43.                     <option value="8" {if isset($sched.month) and $sched.month eq 1}selected{/if}>八月</option>
  44.                     <option value="9" {if isset($sched.month) and $sched.month eq 1}selected{/if}>九月</option>
  45.                     <option value="10" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十月</option>
  46.                     <option value="11" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十一月</option>
  47.                     <option value="12" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十二月</option>
  48.                 </select>
  49.             </div>
  50.             <div class="layui-input-inline">
  51.                 <select name="week" style="width: 30%" required="required" lay-filter="selc_week">
  52.                     <option value="0">请选择</option>
  53.                     <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第一周</option>
  54.                     <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第二周</option>
  55.                     <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第三周</option>
  56.                     <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第四周</option>
  57.                 </select>
  58.             </div>
  59.             <div class="layui-input-inline">
  60.                 <select name="weekday" style="width: 30%" required="required" lay-filter="selc_weekday">
  61.                     <option value="0">请选择</option>
  62.                     <option value="monday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期一</option>
  63.                     <option value="tuesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期二</option>
  64.                     <option value="wednesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期三</option>
  65.                     <option value="thursday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期四</option>
  66.                     <option value="friday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期五</option>
  67.                     <option value="saturday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期六</option>
  68.                     <option value="sunday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期日</option>
  69.                 </select>
  70.             </div>
  71.         </div>
  72.         <div class="layui-form-item">
  73.             <label class="layui-form-label">开始时间</label>
  74.             <div class="layui-input-inline">
  75.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  76.             </div>
  77.         </div>
  78.     </div>
  79.     <div class="form-group" data-storage-type="year-month" lay-filter="year-month">
  80.         <div class="layui-form-item">
  81.             <label class="layui-form-label">每隔</label>
  82.             <div class='layui-input-inline'>
  83.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  84.             </div>
  85.             <div class="layui-form-mid">年重复,</div>
  86.         </div>
  87.         <div class="layui-form-item">
  88.             <label class="layui-form-label">在</label>
  89.             <div class="layui-input-inline">
  90.                 <select name="month" style="width: 30%" required="required" lay-filter="selc_month">
  91.                     <option value="0">请选择</option>
  92.                     <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>一月</option>
  93.                     <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>二月</option>
  94.                     <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>三月</option>
  95.                     <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>四月</option>
  96.                     <option value="5" {if isset($sched.month) and $sched.month eq 1}selected{/if}>五月</option>
  97.                     <option value="6" {if isset($sched.month) and $sched.month eq 1}selected{/if}>六月</option>
  98.                     <option value="7" {if isset($sched.month) and $sched.month eq 1}selected{/if}>七月</option>
  99.                     <option value="8" {if isset($sched.month) and $sched.month eq 1}selected{/if}>八月</option>
  100.                     <option value="9" {if isset($sched.month) and $sched.month eq 1}selected{/if}>九月</option>
  101.                     <option value="10" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十月</option>
  102.                     <option value="11" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十一月</option>
  103.                     <option value="12" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十二月</option>
  104.                 </select>
  105.             </div>
  106.             <div class="layui-form-mid">第</div>
  107.             <div class="layui-input-inline">
  108.                 <select name="day" style="width: 15%" lay-filter="selc" required>
  109.                     {if isset($sched.day)}{:dayOptions($sched.day)}{else /}{:dayOptions()}{/if}
  110.                 </select>
  111.             </div>
  112.             <div class="layui-form-mid">天,</div>
  113.             <label class="layui-form-mid">开始时间</label>
  114.             <div class="layui-input-inline">
  115.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  116.             </div>
  117.         </div>
  118.     </div>
  119.     <div class="form-group" data-storage-type="month">
  120.         <div class="layui-form-item">
  121.             <div class="layui-input-block">
  122.                 <input type="radio" name="cycle_type" value="week" title="按周" {if isset($sched.cycle_type) and $sched.cycle_type eq 'week'}checked{/if} lay-filter="cycle_type">
  123.                 <input type="radio" name="cycle_type" value="day" title="按天" {if isset($sched.cycle_type) and $sched.cycle_type eq 'day'}checked{/if} lay-filter="cycle_type">
  124.             </div>
  125.         </div>
  126.     </div>
  127.     <div class="form-group" data-storage-type="month-week" lay-filter="month-week" style="margin-left: 40px">
  128.         <div class="layui-form-item">
  129.             <label class="layui-form-label">每隔</label>
  130.             <div class='layui-input-inline'>
  131.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  132.             </div>
  133.             <div class="layui-form-mid text-explode">月重复,</div>
  134.         </div>
  135.         <div class="layui-form-item">
  136.             <label class="layui-form-label">在</label>
  137.             <div class="layui-input-inline">
  138.                 <select name="week" style="width: 30%" lay-filter="selc_week">
  139.                     <option value="0">请选择</option>
  140.                     <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第一周</option>
  141.                     <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第二周</option>
  142.                     <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第三周</option>
  143.                     <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第四周</option>
  144.                 </select>
  145.             </div>
  146.             <div class="layui-input-inline">
  147.                 <select name="weekday" style="width: 30%" lay-filter="selc_weekday">
  148.                     <option value="0">请选择</option>
  149.                     <option value="monday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期一</option>
  150.                     <option value="tuesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期二</option>
  151.                     <option value="wednesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期三</option>
  152.                     <option value="thursday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期四</option>
  153.                     <option value="friday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期五</option>
  154.                     <option value="saturday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期六</option>
  155.                     <option value="sunday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期日</option>
  156.                 </select>
  157.             </div>
  158.             <label class="layui-form-label">开始时间</label>
  159.             <div class="layui-input-inline">
  160.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  161.             </div>
  162.         </div>
  163.     </div>
  164.     <div class="form-group" data-storage-type="month-day" lay-filter="month-day" style="margin-left: 40px">
  165.         <div class="layui-form-item">
  166.             <label class="layui-form-label">每隔</label>
  167.             <div class='layui-input-inline'>
  168.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  169.             </div>
  170.             <div class="layui-form-mid">月重复,</div>
  171.        </div>
  172.         <div class="layui-form-item">
  173.             <label class="layui-form-label">在第</label>
  174.             <div class="layui-input-inline">
  175.                 <select name="day" lay-filter="selc">
  176.                     {if isset($sched.day)}{:dayOptions($sched.day)}{else /}{:dayOptions()}{/if}
  177.                 </select>
  178.             </div>
  179.             <div class="layui-form-mid">天,</div>
  180.             <label class="layui-form-label">开始时间</label>
  181.             <div class="layui-input-inline">
  182.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  183.             </div>
  184.         </div>
  185.     </div>
  186.     <div class="form-group" data-storage-type="day">
  187.         <div class="layui-form-item">
  188.             <label class="col-sm-2 control-label">每隔</label>
  189.             <div class='layui-input-inline'>
  190.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  191.             </div>
  192.             <div class="layui-form-mid text-explode">天重复,开始时间</div>
  193.             <div class="layui-input-inline">
  194.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  195.             </div>
  196.         </div>
  197.     </div>
  198.     <div class="form-group" data-storage-type="week">
  199.         <div class="layui-form-item">
  200.             <label class="col-sm-2 control-label">每隔</label>
  201.             <div class='layui-input-inline'>
  202.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  203.             </div>
  204.             <div class="layui-form-mid text-explode">周重复,开始时间</div>
  205.             <div class="layui-input-inline">
  206.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  207.             </div>
  208.         </div>
  209.         <div class="layui-form-item">
  210.             <label class="col-sm-2 control-label" required="required">选择星期:</label>
  211.                 <div class="layui-input-block">
  212.                     <input type="checkbox" name="cweek[monday]" lay-skin="primary" title="星期一" {if isset($sched.week.monday) and $sched.week.monday eq 1}checked{/if}>
  213.                     <input type="checkbox" name="cweek[tuesday]" lay-skin="primary" title="星期二" {if isset($sched.week.tuesday) and $sched.week.tuesday eq 1}checked{/if}>
  214.                     <input type="checkbox" name="cweek[wednesday]" lay-skin="primary" title="星期三" {if isset($sched.week.wednesday) and $sched.week.wednesday eq 1}checked{/if}>
  215.                     <input type="checkbox" name="cweek[thursday]" lay-skin="primary" title="星期四" {if isset($sched.week.thursday) and $sched.week.thursday eq 1}checked{/if}>
  216.                     <input type="checkbox" name="cweek[friday]" lay-skin="primary" title="星期五" {if isset($sched.week.friday) and $sched.week.friday eq 1}checked{/if}>
  217.                     <input type="checkbox" name="cweek[saturday]" lay-skin="primary" title="星期六" {if isset($sched.week.saturday) and $sched.week.saturday eq 1}checked{/if}>
  218.                     <input type="checkbox" name="cweek[sunday]" lay-skin="primary" title="星期日" {if isset($sched.week.sunday) and $sched.week.sunday eq 1}checked{/if}>
  219.                 </div>
  220.         </div>
  221.     </div>
  222.     <div class="form-group" data-storage-type="hour">
  223.         <div class="layui-form-item">
  224.             <label class="col-sm-2 control-label">每隔</label>
  225.             <div class='layui-input-inline'>
  226.                 <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
  227.             </div>
  228.             <div class="layui-form-mid text-explode">小时重复,开始时间</div>
  229.             <div class="layui-input-inline">
  230.                 <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
  231.             </div>
  232.         </div>
  233.     </div>
  234.     <div class="layui-form-item">
  235.         <label class="layui-form-label">开始日期</label>
  236.         <div class="layui-input-inline">
  237.             <input name="start_time" id="start_time" value="{$vo.start_time|default=''}" required="required" title="请设置开始时间" class="layui-input">
  238.         </div>
  239.         <label class="layui-form-label">结束时间</label>
  240.         <div class="layui-input-inline">
  241.             <input name="finish_time" id="finish_time" value="{$vo.finish_time|default=''}" required="required" title="请设置结束时间" class="layui-input">
  242.         </div>
  243.     </div>
  244.     <div class="hr-line-dashed"></div>
  245.     <div class="col-sm-4 col-sm-offset-2">
  246.         <div class="layui-form-item text-center">
  247.             {if isset($id)}<input type='hidden' value='{$id}' name='id'/>{/if}
  248.             <button class="layui-btn" type="submit">保存计划</button>
  249.             <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消日程设置吗?" data-close>取消日程</button>
  250.         </div>
  251.     </div>
  252. </form>
  253. {/block}
  254. {block name="script"}
  255. <script>
  256.     window.form.render();
  257.     //表单初始化
  258.     var type_value = "{$sched.type|default='day'}";
  259.     var elem_hide = $("[data-storage-type='" + type_value + "']");
  260.     $("[data-storage-type]").not(elem_hide.show()).hide();
  261.     //解决input内容改变值不变BUG
  262.     $("input[name=gap]").change(function(e){
  263.         $("input[name=gap]").val(e.delegateTarget.value);
  264.     })
  265.     layui.use(['form','jquery','laydate'],function (){
  266.         var form = layui.form,$=layui.jquery,laydate=layui.laydate;
  267.         //点击type单选框切换表单
  268.         form.on('radio(ttype)',function (data){
  269.             var $tips = $("[data-storage-type='" + data.value + "']");
  270.             $("[data-storage-type]").not($tips.show()).hide();
  271.             form.render();
  272.         })
  273.         form.on('radio(cycle_type)',function (data){
  274.             var ttpye = $('[name=type]:checked').val();
  275.             var $tips = $("[data-storage-type='" + ttpye +"-" + data.value + "']");
  276.             $("[data-storage-type]").not($tips.show()).hide();
  277.             $("[data-storage-type='"+ttpye+"']").show();
  278.             form.render();
  279.         })
  280.         form.on('select(selc)',function (data){
  281.             $("select[name=day]").val(data.value);
  282.         })
  283.         form.on('select(selc_month)',function (data){
  284.             $("select[name=month]").val(data.value);
  285.         })
  286.         form.on('select(selc_week)',function (data){
  287.             $("select[name=week]").val(data.value);
  288.         })
  289.         form.on('select(selc_weekday)',function (data){
  290.             $("select[name=weekday]").val(data.value);
  291.         })
  292.         //阻止多个日期点击冒泡事件
  293.         $("#start_time").on("click",function(){
  294.             laydate.render({
  295.                 elem:'#start_time',format:'yyyy-MM-dd',closeStop:'#start_time',value:this.value
  296.             })
  297.         })
  298.         $("#finish_time").on("click",function(){
  299.             laydate.render({
  300.                 elem:'#finish_time',format:'yyyy-MM-dd',closeStop:'#finish_time',value:this.value
  301.             })
  302.         })
  303.         //阻止laydate冒泡事件
  304.         $("input[name='begin_time']").on('click',function (){
  305.             laydate.render({
  306.                 elem:this,
  307.                 type:'time',
  308.                 format:'HH:mm',
  309.                 value:this.value,
  310.                 change:function (value){
  311.                     $("input[name='begin_time']").val(value);
  312.                 }
  313.             });
  314.         })
  315.     })
  316. </script>
  317. {/block}

 

你想把广告放到这里吗?

发表评论

您必须 登录 才能发表留言!