<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase2.php');?>
<style>
    .layui-form-select{max-width: 80px !important;}
    .layui-input{max-width: 150px !important;}
</style>
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-form">
        <table class="layui-table" style="width: 400px !important;">
            <thead>
            <tr>
                <th style="width: 75px !important;">
                    <select class="w100" id="year" class="w50"  lay-filter="testId">
                        <?php foreach($year_list as $k=>$v){?>
                            <option value="<?php echo $v;?>"<?php if(isset($param['year']) && $param['year'] == $v) echo ' selected'; ?>><?php echo $v;?></option>
                        <?php }?>
                    </select>
                </th>
                <th>总目标</th>
                <th>总销售(<?php echo $param['year'] - 1?>)</th>
                <th>总增长率</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td style="color: red;width: 75px !important;">汇总</td>
                <td style="color: red;"><?php echo $arr['count']; ?></td>
                <td style="color: red;"><?php echo $arr['zxs']; ?></td>
                <td style="color: red;"><?php echo $arr['zzl']; ?></td>
            </tr>
            <?php foreach ($list as $key => $value): ?>
                <tr>
                    <td style="width: 75px !important;"><?php echo $key .'月';?></td>
                    <td><input type="number" class="layui-input w100" value="<?php echo $value['zmb'] ?: ''; ?>"></td>
                    <td><?php echo $value['money'] ?: '';  ?></td>
                    <td><?php echo $value['zzl'] ?: '';  ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <button class="layui-btn" type="button" onclick="add()">保存</button>
        </div>
    </div>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>

<script>
    layui.use(['form'], function () {
        var form = layui.form;
        form.on('select(testId)', function(data){
            window.location.href = ADMIN_URI+'pjl/addComPage?year='+data.value;
        })
    })
    function add() {
        var arr = {};
        var temp = 0;
        var month = $('#year').val();
        $('table tbody tr').each(function(i){
            if(i < 1) {
                return true;
            }
            arr[i] = {};
            temp = parseInt($(this).find('td:eq(0)').text());
            if(temp < 10){
                temp = '0'+temp;
            }
            arr[i]['bct_month'] = parseInt(month+temp);
            arr[i]['bct_money'] = $(this).find('td:eq(1) input').val();
        });
        $.ajax({
            url: ADMIN_URI + 'pjl/addComMb?isAjax=1',
            type: 'POST',
            data: arr,
            dataType: "json",
            success: function (res) {
                if(res.status){
                    layer.msg('操作成功');
                } else{
                    layer.msg(res.data);
                }
            }
        });
    }

</script>
