@extends('layouts.app')
@section('title')计费模型-仓储计费@endsection

@section('content')
    <div id="nav2">
        @component('maintenance.menu')@endcomponent
        @component('maintenance.priceModel.storage.menu')@endcomponent
    </div>
    <div class="container-fluid mt-2" id="container">
        @if(Session::has('successTip'))
            <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
        @endif
        <table class="table table-hover table-striped text-nowrap">
            <tr>
                <th>序号</th>
                <th>计费类型</th>
                <th>用仓类型</th>
                <th>最低起租面积</th>
                <th>单价</th>
                <th>减免类型</th>
                <th>减免值</th>
                <th>录入时间</th>
                <th>操作</th>
            </tr>
            <tr v-for="(model,i) in models">
                <td>@{{ i+1 }}</td>
                <td>@{{ model.counting_type }}</td>
                <td>@{{ model.using_type }}</td>
                <td>@{{ model.minimum_area }}</td>
                <td>@{{ model.price }}/@{{ model.unit_name }}</td>
                <td>@{{ model.discount_type }}</td>
                <td>@{{ model.discount_value }}</td>
                <td>@{{ model.created_at }}</td>
                <td>
                    @can("计费模型-仓储-编辑")<a :href="'{{url('maintenance/priceModel/storage')}}/'+model.id+'/edit'"><button class="btn btn-sm btn-outline-info">改</button></a>@endcan
                    @can("计费模型-仓储-删除")<button class="btn btn-sm btn-outline-danger" @click="destroy(model.id,i)">删</button>@endcan
                </td>
            </tr>
        </table>
        {{$models->links()}}
    </div>
@stop

@section("lastScript")
    <script>
        new Vue({
            el:"#container",
            data:{
                models : [
                    @foreach($models as $model)
                    {
                        id : "{{$model->id}}",
                        counting_type : "{{$model->counting_type}}",
                        using_type : "{{$model->using_type}}",
                        minimum_area : "{{$model->minimum_area}}",
                        price : "{{$model->price}}",
                        discount_type : "{{$model->discount_type}}",
                        discount_value : "{{$model->discount_value}}",
                        unit_name : "{{$model->unit ? $model->unit->name : ''}}",
                        created_at : "{{$model->created_at}}",
                    },
                    @endforeach
                ],
            },
            methods:{
                destroy(id,index){
                    window.tempTip.confirm("确定要删除该仓储计费吗？",()=>{
                        window.axios.delete("{{url('maintenance/priceModel/storage')}}/"+id)
                            .then(res=>{
                                if (res.data.success){
                                    this.$delete(this.models,index);
                                    window.tempTip.setDuration(2000);
                                    window.tempTip.showSuccess("删除成功");
                                    return;
                                }
                                window.tempTip.setDuration(3000);
                                window.tempTip.show(res.data.data);
                            }).catch(err=>{
                            window.tempTip.setDuration(3000);
                            window.tempTip.show("网络错误："+err);
                        })
                    })
                }
            },
        });
    </script>
@stop