<!doctype html>
  <html class="no-js">
  <head>

    <include file="Common/head" />
    <style type="text/css">
      .am-form{width:500px;margin-left:20px;float: left;}
      #editor {font-size: 12px;}
      .am-form label span{font-size: 13px;font-weight:normal;}
      .am-form label p{display: inline;color: #f00;}
      .am-form .am-form-inline-2 input[type=file]{width: 246px}
      .am-form .am-form-inline-3 input[type=text]{width: 160px}
      .am-form .am-form-inline-3 select{width: 160px}
      .am-form .am-form-inline-4 input[type=text]{width: 120px}
      .am-form .am-form-inline-4 select{width: 120px}
      .two-input {display: flex;}
      .am-form .am-form-inline-4 .two-input input[type=text]{width: 50px;}
      .am-form .am-form-inline-4 .two-input input[type=text]:nth-of-type(2){width: 20px;padding: 8px 2px;cursor: default;background: #fff; border-left: 0; border-right: 0;}

      .am-form input[type=file]{display:none;}
      .am-form .am-form-group img{height: 60px;min-width: 60px;max-width: 100px;margin-top: 2px;display: block;cursor: pointer;}
      input[readonly]{background-color: #fff!important;cursor: default!important;}
      .am-form-group input{
        height: 30px;font-size: 14px;margin-bottom: 10px !important;
      }
      .am-form-group select{
        height: 30px;font-size: 14px;margin-bottom: 10px !important;
      }
    </style>
  </head>
  <body>
  <include file="Common/header" />
  <div class="am-cf admin">
    <include file="Common/sidebar" nav="$nav" navv="$nav"/>
    <div class="content-page" style="background: white;">
      <div class="admin-content" style="background: white;">
        <div class="admin-content-body">
          <div class="am-cf am-padding">
            <div class="am-fl am-cf">
              <strong class="am-text-primary am-text-lg">决策支持</strong> /
              <small>销售统计</small>
            </div>
          </div>
          <hr style="margin-top:0px;">
          <div class="am-g" style="padding: 0 1.6rem;">
          <div class="am-panel am-panel-secondary">
            <div class="am-panel-hd">按年、月、日统计商城交易额、交易量</div>
            <div class="am-panel-bd">
              <form action="" method="GET" class="am-form">
                <div class="am-g">
                  <div class="am-form-group">
                    <div class="am-u-sm-1 txtr">日期</div>
                    <div class="am-u-sm-2">
                      <select name="yy">
                        <?php
                          $year_first = date('Y',M('order')->order('create_time')->getField('create_time'));
                          $year_now = date('Y');
                          for ($i=$year_now; $i >= $year_first; $i--) { ?>
                          <option value="{$i}">{$i}年</option>
                        <?php } ?>
                      </select>
                    </div>
                    <div class="am-u-sm-2">
                      <select name="mm">
                        <option value="0">全年</option>
                        <?php for ($i=1; $i <= 12; $i++) { ?>
                          <option value="{$i}">{$i}月</option>
                        <?php } ?>
                      </select>
                    </div>
                    <div class="am-u-sm-2">
                      <select name="dd">
                        <option value="0">全月</option>
                      </select>
                    </div>
                    <div class="am-u-sm-5" style="line-height: 37px;">&nbsp;</div>
                    <!-- 不选择月 表示年统计，不选择日 表示月统计 -->
                  </div>
                  <div class="am-form-group" style="padding-top: 35px;">
                    <div class="am-u-sm-1 txtr">类型</div>
                    <div class="am-u-sm-2">
                      <label style="font-weight: normal;">
                        <input type="radio" name="type" value="1" {:I('type')!=2?'checked':''}> 交易额
                      </label>
                      <label style="font-weight: normal;">
                        <input type="radio" name="type" value="2" {:I('type')==2?'checked':''}> 交易量
                      </label>
                    </div>
                    <div class="am-u-sm-1">&nbsp;</div>
                  </div>
                  <div class="am-form-group" style="padding-top: 16px;">
                    <div class="am-u-sm-1">&nbsp;</div>
                    <div class="am-u-sm-3">
                      <button type="submit" class="am-btn am-btn-default" onclick="$('#op').val('')">搜索</button>
                      <button type="submit" class="am-btn am-btn-secondary" onclick="$('#op').val('export')">导出Excel</button>
                      <input type="hidden" name="op" id="op">
                    </div>
                    <div class="am-u-sm-1">&nbsp;</div>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <div class="am-panel am-panel-default">
            <div class="am-panel-hd">
              数据统计
              <?php if($_GET['type']==2){ ?>
                总交易量：{$count_sum}
              <?php }else{ ?>
                总交易额：{$money_sum}
              <?php } ?>
            </div>
            <div class="am-panel-bd">
              <table class="am-table">
                <thead>
                  <tr>
                    <th width="10%">{$title_name}</th>
                    <th width="10%">{:I('type')==2?'交易量':'交易额'}</th>
                    <th width="50%">所占比例</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach($data as $vo){ ?>
                  <tr>
                    <td>{$vo.title}</td>
                    <?php if($_GET['type']!=2){ ?>
                    <td>{$vo.money}</td>
                    <td>
                      <div class="am-progress">
                        <div class="am-progress-bar am-progress-bar-secondary" style="width: {$vo.money_scale}%">{$vo.money_scale}%</div>
                      </div>
                    </td>
                    <?php }else if($_GET['type']==2){ ?>
                    <td>{$vo.count}</td>
                    <td>
                      <div class="am-progress">
                        <div class="am-progress-bar am-progress-bar-secondary" style="width: {$vo.count_scale}%">{$vo.count_scale}%</div>
                      </div>
                    </td>
                    <?php } ?>
                  </tr>
                  <?php } ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <include file="Common/footer" />
  </body>
  <script type="text/javascript">
  $(function(){
    var oyy = "{:I('yy')}";
    var omm = "{:I('mm')}";
    var odd = "{:I('dd')}";
    if(oyy > 0){ $('select[name=yy]').val(oyy);
      if(omm > 0){ $('select[name=mm]').val(omm); setDays();
        if(odd > 0) $('select[name=dd]').val(odd);
      }
    }
    $('select').css('cssText','color:#555!important');

    $('select[name=yy]').on('change',function(){
      $('select[name=mm]').val(0).change();
    });
    $('select[name=mm]').on('change',function(){
      setDays();
    });
    function setDays(){
      var yy = $('select[name=yy]').val();
      var mm = $('select[name=mm]').val();
      var html = '<option value="0">全月</option>';
      if(yy > 0 && mm > 0 && mm <= 12){
        var temp = new Date(yy,mm,0); 
        var days = temp.getDate();
        for (var i = 1; i <= days; i++) {
          html += '<option value="'+i+'">'+i+'日</option>';
        }
      }
      $('select[name=dd]').html(html);
    }
  });
  </script>
  </html>