regionFee.php 9.11 KB
<?php

use yii\helpers\Url;
use app\ht\widgets\LinkPager;
use common\helpers\ImageManager;


$this->title = '地区及费用';
$this->params['breadcrumbs'][] =  '系统管理';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="panel panel-default">
    <div class="panel-heading  form-inline">
        <a href="javascript:void(0)" data-href="<?php echo Url::toRoute('/setting/system-setting/add-region-fee'); ?>" class="btn btn-success pull-left addRegionBtn">添加地区费用</a>&nbsp;&nbsp;
        <div style="clear:both;width:100%;"></div>
    </div>

    <div  class="panel-body">
        <?php if (!empty($rList)) : ?>
            <table class="table table-striped table-bordered"  id="brand-table">
                <thead>
                <tr>
                    <th style="width:5%;" class="text-center align-middle hqy-all-select">ID</th>
                    <th>地区</th>
                    <th style="width:10%;">上门费(元)</th>
                    <th style="width:10%;">工时费(元)</th>
                    <th style="width:10%;">派单半径(米)</th>
                    <th style="width:10%;">接单半径(米)</th>

                    <th style="width:14%;">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($rList as $item) : ?>
                    <tr>
                        <td class="text-center align-middle hqy-row-select"><?= $item['id'] ?></td>
                        <td>
                            <span class="city"><?= $item['city'] ?></span>
                        </td>
                        <td>
                            <span class="door_fee"><?= $item['door_fee'] ?></span>
                        </td>
                        <td >
                            <span class="man_hour_fee"><?= $item['man_hour_fee'] ?></span>
                        </td>
                        <td >
                            <span class="dispatch_order_radius"><?= $item['dispatch_order_radius'] ?></span>
                        </td>
                        <td >
                            <span class="pick_order_radius"><?= $item['pick_order_radius'] ?></span>
                        </td>

                        <td >
                            <a href="javascript:void(0)" data-id="<?= $item['id']  ?>" class="editBtns">编辑</a> &nbsp;|&nbsp;

                            <a href = "javascript:void(0)" data-id="<?= $item['id']  ?>" class="del-item">删除</a>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p class="text-center">
                没有找到数据
            </p>
        <?php endif; ?>
    </div>

    <div class="panel-footer">
        <div class="hqy-panel-pager">
            <?= LinkPager::widget([
                'pagination' => $pages,
            ]); ?>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加地区及费用</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="regionName">地区名称</label>
                        <input type="text" class="form-control" id="regionName" placeholder="地区名称">
                    </div>
                    <div class="form-group">
                        <label for="door_fee">上门费(元)</label>
                        <input type="number" class="form-control" id="door_fee" placeholder="上门费">
                    </div>
                    <div class="form-group">
                        <label for="man_hour_fee">工时费(元)</label>
                        <input type="number" class="form-control" id="man_hour_fee" placeholder="工时费">

                    </div>
                    <div class="form-group">
                        <label for="dispatch_order_radius">派单半径(米)</label>
                        <input type="number" min="1" class="form-control" id="dispatch_order_radius" placeholder="单位是米">

                    </div>
                    <div class="form-group">
                        <label for="pick_order_radius">接单半径(米)</label>
                        <input type="number" min="1" class="form-control" id="pick_order_radius" placeholder="单位是米">

                    </div>
                    <input type="hidden" class="form-control" id="region_fee_id" />
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    var regionFeeSaveUrl = '<?= Url::toRoute(['/setting/system-setting/add-region-fee']); ?>';
    var regionFeeUpdateUrl = '<?= Url::toRoute(['/setting/system-setting/update-region-fee']); ?>';
    var regionFeeDelUrl = '<?= Url::toRoute(['/setting/system-setting/del-region-fee']); ?>';
    var maxRadius = 40076000;
    $(function(){
        $('.addRegionBtn').click(function(){
            $('#region_fee_id').val(0);
            $('#myModal').modal('show');
        })

        $('#submitBtn').click(function(){
            var regionName = $('#regionName').val().replace(/\s+/g, "");

            var door_fee = $.trim($('#door_fee').val());
            var man_hour_fee = $.trim($('#man_hour_fee').val());
            var region_fee_id = $('#region_fee_id').val();

            var pick_order_radius = $('#pick_order_radius').val();
            var dispatch_order_radius = $('#dispatch_order_radius').val();

            if ('' == regionName ){
                alert('地区名不能为空');
                return false;
            }
            door_fee = door_fee * 1.00
            man_hour_fee  = man_hour_fee * 1.00
            if ( 0 == door_fee ){
                alert('上门费不能空也不能为0');
                return false;
            }
            if ( 0 == man_hour_fee ){
                alert('工时费不能空也不能为0');
                return false;
            }
            if ( 0 == dispatch_order_radius ){
                alert('派单半径不能为空');
                return false;
            }
            if (dispatch_order_radius > maxRadius) {
                alert('派单半径不能为超过'+maxRadius);
                return false;
            }
            if ( 0 == pick_order_radius ){
                alert('接单半径不能为空');
                return false;
            }
            if (pick_order_radius > maxRadius) {
                alert('接单半径不能为超过'+maxRadius);
                return false;
            }
            if (region_fee_id > 0){
                regionFeeSaveUrl = regionFeeUpdateUrl
            }
            $.post(regionFeeSaveUrl,{
                id: region_fee_id,
                region: regionName,
                door_fee: door_fee,
                man_hour_fee: man_hour_fee,
                dispatch_order_radius: dispatch_order_radius,
                pick_order_radius: pick_order_radius

            },function(res){
                    if (res.success){
                        $('#myModal').modal('hide')
                        window.location.reload();
                    }else{
                        alert(res.error);
                    }
            },'json')

        })

        $('.editBtns').click(function(){

            var trParents = $(this).parents('tr');
            var city = trParents.find('.city').html();
            var door_fee = trParents.find('.door_fee').html();
            var man_hour_fee = trParents.find('.man_hour_fee').html();
            var dispatch_order_radius = trParents.find('.dispatch_order_radius').html();
            var pick_order_radius = trParents.find('.pick_order_radius').html();
            var rf_id =  $(this).attr('data-id');
            $('#region_fee_id').val(rf_id);
            $('#regionName').val(city);
            $('#door_fee').val(door_fee);
            $('#man_hour_fee').val(man_hour_fee);
            $('#dispatch_order_radius').val(dispatch_order_radius);
            $('#pick_order_radius').val(pick_order_radius);
            $('#myModal').modal('show')

        })
        $('.del-item').click(function(){
            if (!confirm('确认删除该记录?')){
                return false;
            }
            var id = $(this).attr('data-id');
            $.post(regionFeeDelUrl,{id:id},function(res){
                if (res.success){
                    window.location.reload();
                }else{
                    alert(res.error);
                }
            },'json')
        })
    });
</script>