<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link href="{{asset('css/style.min862f.css?v=4.1.0')}}" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{asset('oss/style.css?v=1')}}"/>
<style type="text/css">
    .person {
        display: flex;
        text-align: center;
        align-items: center;
        justify-content: center;
        margin: 5px
    }

    .workingHours {
        display: block;
        padding: 0 10px;
    }


    h1 {
        font: 400 16px 'Open Sans';
        text-transform: uppercase;
        color: #999;
        text-shadow: 1px 1px 1px #fff;
        margin-bottom: 30px;
    }

    .tableBox table {
        width: 100%;
    }

    .tableBox thead {
        width: 100%;
        border-top: 1px solid #9dcc7a;
        border-left: 1px solid #9dcc7a;
    }

    .tableBox tbody td, .tableBox thead th {
        height: 30px;
        line-height: 30px;
        text-align: center;
        font-size: 12px;
        color: #404040;
    }

    .tableBox thead th {
        background-color: #abd28e;
        border-bottom: 1px solid #9dcc7a;
        border-right: 1px solid #9dcc7a;
    }

    .tableBox tbody {
        border-left: 1px solid #abd28e;
    }

    .tableBox tbody td {
        border-bottom: 1px solid #abd28e;
        border-right: 1px solid #abd28e;
        border-left: 1px solid #abd28e;
        border-spacing: 0;
    }

    .tableBox thead th {
        background-color: #abd28e;
        border-bottom: 1px solid #9dcc7a;
        border-right: 1px solid #9dcc7a;
        border-left: 1px solid #9dcc7a;
        border-spacing: 0;

    }

    .tableBox table {
        border-spacing: 0;
        border-collapse: collapse;
    }

    /*    .tableBox tbody tr:nth-child(even) td {
            background-color: rgb(246, 246, 246);
        }*/

    .tableBox table td, .tableBox table th {
        vertical-align: middle;
    }

    .file {
        background-color: #4ea397;
    }

    #tableid tr {
        background-color: #ffff;
    }

</style>

<form action="{{url('/admin/flow/siteConstructionProcess/'.$siteId.'/type/1')}}" method="post" id="form1">
    <div class="tableBox">
        <table id="tableid" border="0" cellspacing="0" cellpadding="0" style=" border-collapse: collapse;">
            <thead>
            <tr>
                @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                    <th colspan="14" style="text-align: center">
                        {{$siteInfo->cn_title??''}} 建站流程表 进度【{{$count-$toBeCompletedCount}}/{{$count}}】 (ctrl+s保存)
                    </th>
                @else
                    <th colspan="9" style="text-align: center">
                        {{$siteInfo->cn_title??''}} 建站流程表 进度【{{$count-$toBeCompletedCount}}/{{$count}}】 (ctrl+s保存)
                    </th>
                @endif
            </tr>
            <tr>
                <th style="width: 6%;">状态/时间</th>
                <th style="width: 6%;">具体事项</th>
                <th style="width: 6%;">事项备注</th>
                <th style="width: 7%;">负责人/工时(单位:天)</th>
                @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                    <th style="width: 6%;">验收标准</th>
                @endif
                <th style="width: 6%;">文件(小于8M)</th>
                <th style="width: 6%;">节点时间</th>
                @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                    <th style="width: 5%;">逾期时间</th>
                @endif
                <th style="width: 6%;">逾期原因</th>
                <th style="width: 5%;">打分节点(客户)</th>
                @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                    <th style="width: 5%;">质检打分</th>
                    <th style="width: 5%;">质检人员</th>
                @endif
                <th style="width: 6%;">备注</th>
                @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                    <th style="width: 3%;">操作</th>
                @endif
            </tr>
            </thead>
            <tbody id="tbody">
            @foreach($flowList as $item)
                <tr>
                    <td>
                        @if(empty($item->status))
                            <button type="button" style="margin:0 auto;" class="btn"
                                    name="btnReset"
                                    onclick="taskByStatus(this,'#{{$item->id.'-status'}}')">
                                未完成
                            </button>
                        @else
                            <div style="text-align: center">{{$item->status}}</div>
                            <button type="button" style="margin:0 auto;" class="btn2"
                                    name="btnReset"
                                    onclick="taskByStatus(this,'#{{$item->id.'-status'}}')">
                                完成
                            </button>
                        @endif
                        <input type="hidden" name="{{$item->id.'-status'}}"
                               id="{{$item->id.'-status'}}"
                               value="{{$item->status?? ''}}">
                    </td>
                    <td>
                        <input type="hidden" name="{{$item->id.'-id'}}" id="{{$item->id.'-id'}}"
                               value="{{$item->id?? 0}}">

                        <span style="font-weight:bold">{{$item->title??''}}</span><br>
                        <span style="color:{{$item->color??'red'}}; font-weight:bold">【{{$item->rank??''}}】</span>
                    </td>
                    <td>
                        {{$item->memo??''}}
                    </td>
                    <td>
                        @foreach($item->roles as $key=>$value)
                            @if($key==\App\Http\Models\Role::TYPE_CUSTOMER)
                                {{--客户--}}
                                <div class="person">
                                <span class="workingHours">
                                    @if($roles->role_id ==\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <span style="color:#893448 ">{{$siteName}}</span> @else {{$siteName}}
                                    @endif
                                </span>
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_SELLER)
                                {{--销售--}}
                                <div class="person">
                                    <span class="workingHours">
                                        <input type="hidden"
                                               id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_SELLER}}"
                                               name="{{$item->id.'-user_id-1'}}" value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                            <span
                                                style="color:#893448 ">{{$value->user_id??''}}</span> @else {{$value->nickname??''}} @endif
                                    </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_SELLER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_SELLER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_SERVER)
                                {{--项目管家--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden"
                                           id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_SERVER}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_SERVER}}"
                                           value="{{$value->user_id??''}}">
                                    @if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span style="color:#893448 ">{{$value->nickname??'未分配项目管家'}}</span>
                                    @else {{$value->nickname??''}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_SERVER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_SERVER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_MANAGE_HELPER)
                                {{--项目经理--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden"
                                           id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_MANAGE_HELPER}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_MANAGE_HELPER}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配项目经理'}}</span> @else {{$value->nickname??'未分配项目经理'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_MANAGE_HELPER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_MANAGE_HELPER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_PLANNER)
                                {{--策划--}}
                                <div class="person">
                            <span class="workingHours">
                                <input type="hidden" id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_PLANNER}}"
                                       name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_PLANNER}}"
                                       value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                    <span
                                        style="color:#893448 ">{{$value->nickname??'未分配策划'}}</span> @else {{$value->nickname??'策划'}} @endif
                            </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_PLANNER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_PLANNER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_AE)
                                {{--采编--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden" id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_AE}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_AE}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配采编'}}</span> @else {{$value->nickname??'未分配采编'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_AE}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_AE}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_WEB)
                                {{--前端--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden" id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_WEB}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_WEB}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配采编'}}</span> @else {{$value->nickname??'未分配采编'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_WEB}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_WEB}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_DESIGNER)
                                {{--设计--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden"
                                           id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_DESIGNER}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_DESIGNER}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配设计'}}</span> @else {{$value->nickname??'未分配设计'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_DESIGNER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_DESIGNER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_QUALITY)
                                {{--质检--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden"
                                           id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_QUALITY}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_QUALITY}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配质检'}}</span> @else {{$value->nickname??'未分配质检'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_QUALITY}}"
                                               id="{{$item->id.'-working_hours-&'.\App\Http\Models\Role::TYPE_QUALITY}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif
                            @if($key==\App\Http\Models\Role::TYPE_OPTIMIZER)
                                {{--优化--}}
                                <div class="person">
                                <span class="workingHours">
                                    <input type="hidden"
                                           id="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_OPTIMIZER}}"
                                           name="{{$item->id.'-user_id-'.\App\Http\Models\Role::TYPE_OPTIMIZER}}"
                                           value="{{$value->user_id??''}}">@if(!empty($value->user_id) && $roles->id == $value->user_id)
                                        <span
                                            style="color:#893448 ">{{$value->nickname??'未分配优化师'}}</span> @else {{$value->nickname??'未分配优化师'}} @endif
                                </span>
                                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                                        <input type="text" class="form-control" style="width:50%;"
                                               name="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_OPTIMIZER}}"
                                               id="{{$item->id.'-working_hours-'.\App\Http\Models\Role::TYPE_OPTIMIZER}}"
                                               value="{{$value->working_hours??''}}">
                                    @endif
                                </div>
                            @endif

                        @endforeach
                    </td>

                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                        <td>
                            {{$item->acceptance??''}}
                        </td>
                    @endif
                    <td>
                        {{$item->file??''}}
                        @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                            <div style="display: flex;justify-content: center;padding: 0 0 20px 0;">
                                <button type="button" class="btn" name="file_upload"
                                        style="float: left;margin-top: 5px; margin-right:10px;width: 70px">上传
                                </button>
                                <input type="file" value="" style="display: none" name="uploadFile"
                                       data-for="{{$item->id.'-file_path'}}">
                                <input type="hidden" id="{{$item->id.'-file_path'}}"
                                       name="{{$item->id.'-file_path'}}"
                                       value="{{$item->file_path??''}}">
                                <button type="button" class="btn" name="download"
                                        onclick="downloadSiteFile({{$item->id}})"
                                        style="float: left;margin-top: 5px;width: 70px; @if(!empty($item->file_path)) background-color:#4ea397;@endif">
                                    下载
                                </button>
                            </div>
                        @endif
                    </td>
                    {{--    <td>
                            {{$item->file??''}}
                            <div style="display: flex">
                                <button type="button" class="site" name="file_upload"
                                        style="float: left;margin-top: 5px; width: 70px">上传
                                </button>
                                <input type="file" value="" style="display: none" name="uploadFile"
                                       data-for="{{$item->id.'-client_file_path'}}">
                                <input type="hidden" id="{{$item->id.'-client_file_path'}}"
                                       name="{{$item->id.'-client_file_path'}}"
                                       value="{{$item->client_file_path??''}}">
                                <button type="button" class="site" name="download"
                                        onclick="downloadSiteFile({{$item->id}})"
                                        style="float: left;margin-top: 5px; width: 70px; @if(!empty($item->client_file_path))background: linear-gradient(to bottom, #1ebea5 0%, #1ebea5 100%);border-bottom: 4px solid #1ebea5;border-bottom: 4px solid #11998e;@endif">
                                    下载
                                </button>
                                --}}{{--@if(!empty($item->master_plate_path))--}}{{--
                                <button type="button" class="site" name="download"
                                        onclick="downloadSiteFile('{{$item->id}}',1)"
                                        style="float: left;margin-top: 5px;width: 70px; @if(!empty($item->master_plate_path))background: linear-gradient(to bottom, #1ebea5 0%, #1ebea5 100%);border-bottom: 4px solid #1ebea5;border-bottom: 4px solid #11998e;@endif">
                                    模版
                                </button>
                                --}}{{--@endif--}}{{--
                            </div>
                        </td>--}}
                    <td>
                        {{$item->node??''}}
                        <br>
                        @if(strtotime($item->node_date)<strtotime($date))
                            <span
                                style="color:#c1232b;font-size: 14px;font-weight:bold;">{{$item->node_date??''}}</span>
                        @else
                            <span
                                style="color:#4ea397;font-size: 14px;font-weight:bold;">{{$item->node_date??''}}</span>
                        @endif
                        <input type="hidden"
                               name="{{$item->id.'-node_date'}}"
                               id="{{$item->id.'-node_date'}}"
                               value="{{$item->node_date??''}}">
                    </td>
                    <td style="padding-left: 10px">
                        @php
                            if(!empty($item->status) && strtotime($item->node_date)< strtotime(date('Y-m-d',strtotime($item->status)))){
                                 $beOverdueDay=(strtotime(date('Y-m-d',strtotime($item->status)))-strtotime($item->node_date))/3600/24;
                                    echo '逾期'.round($beOverdueDay).'天';
                            }else{
                                 if(!empty($item->node_date) && strtotime($item->node_date)< strtotime(date('Y-m-d'))){
                                 $beOverdueDay=(strtotime(date('Y-m-d'))-strtotime($item->node_date))/3600/24;
                                    echo '逾期'.round($beOverdueDay).'天';
                                }
                            }
                        @endphp
                        <input type="hidden" name="{{$item->id.'-overdue_day'}}"
                               id="{{$item->id.'-overdue_day'}}" value="{{round($beOverdueDay??0)}}">
                    </td>
                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                        <td>
                            <select class="form-control" style="width:100%;"
                                    name="{{$item->id.'-reasons_for_overdue'}}"
                                    id="{{$item->id.'-reasons_for_overdue'}}">
                                @foreach($reasonsForOverdueList as  $k=>$v)
                                    <option value="{{$k}}"
                                            @if(!empty($item->reasons_for_overdue) && $item->reasons_for_overdue==$k) selected @endif>{{$v}}</option>
                                @endforeach
                            </select>
                        </td>
                    @endif
                    <td>
                        <select class="form-control" style="width:100%;"
                                name="{{$item->id.'-client_score'}}"
                                id="{{$item->id.'-client_score'}}">
                            <option value="0">请选择分数</option>
                            @foreach($scoreList as  $k=>$v)
                                <option value="{{$k}}"
                                        @if(!empty($item->client_score) &&!empty($item->client_score) && $item->client_score==$k) selected @endif>{{$v}}</option>
                            @endforeach
                        </select>
                    </td>
                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                        <td>
                            <select class="form-control" style="width:100%;"
                                    name="{{$item->id.'-inspection_score'}}"
                                    id="{{$item->id.'-inspection_score'}}">
                                <option value="0">请选择分数</option>
                                @foreach($scoreList as  $k=>$v)
                                    <option value="{{$k}}"
                                            @if(!empty($item->inspection_score) &&!empty($item->inspection_score) && $item->inspection_score==$k) selected @endif>{{$v}}</option>
                                @endforeach
                            </select>
                        </td>
                    @endif
                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                        <td>
                            @foreach($item->roles as $key=>$value)
                                @if($item->level==1 && $key==\App\Http\Models\Role::TYPE_SERVER)
                                    <input type="hidden" name="{{$item->id.'-inspection'}}"
                                           id="{{$item->id.'-inspection'}}"
                                           value="{{$value->user_id?? 0}}">{{$value->nickname??''}}
                                @endif

                                @if(in_array($item->level,[2,3,4,5,7]) && $key==\App\Http\Models\Role::TYPE_MANAGE_HELPER)
                                    <input type="hidden" name="{{$item->id.'-inspection'}}"
                                           id="{{$item->id.'-inspection'}}"
                                           value="{{$value->user_id?? 0}}">{{$value->nickname??''}}
                                @endif

                                @if($item->level==6 && $key==\App\Http\Models\Role::TYPE_WEB)
                                    <input type="hidden" name="{{$item->id.'-inspection'}}"
                                           id="{{$item->id.'-inspection'}}"
                                           value="{{$value->user_id?? 0}}">{{$value->nickname??''}}
                                @endif

                                @if(in_array($item->level,[8,9]) && $key==\App\Http\Models\Role::TYPE_OPTIMIZER)
                                    <input type="hidden" name="{{$item->id.'-inspection'}}"
                                           id="{{$item->id.'-inspection'}}"
                                           value="{{$value->user_id?? 0}}">{{$value->nickname??''}}
                                @endif
                            @endforeach
                        </td>
                    @endif
                    <td>
                        <textarea name="{{$item->id.'-overdue_memo'}}" id="{{$item->id.'-overdue_memo'}}"
                                  style="border: none;width: 100%;height: 60px">{{$item->overdue_memo}}</textarea>
                    </td>
                    @if($roles->role_id !=\App\Http\Models\Role::TYPE_CUSTOMER)
                        <td>
                            <button type="button" class="btn" onclick="taskResetting({{$item->id}})"
                                    style="width: 70px; margin:0 auto;">重置
                            </button>
                        </td>
                    @endif
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    <button type="submit" class="btn" style="float: left;margin-top: 5px;margin-right:10px; width: 70px">
        保存
    </button>
    {{--    <button type="button" class="site" style="float: left;margin-top: 5px;margin-right:10px; width: 70px"
                onclick="resetting({{$siteId}})">
            重置
        </button>--}}
</form>
<script src="{{asset('js/plugins/layDate-v5.2.1/laydate/laydate.js')}}"></script>
<script src="{{asset('js/jquery.min.js?v=2.1.4')}}"></script>
<script src="{{asset('js/plugins/layer-v3.1.1/layer/layer.js')}}"></script>
<script src="{{asset('js/tools/tips.js')}}"></script>
<script>

    window.onload = function () {
        var tfrow = document.getElementById('tableid').rows.length;
        var tbRow = [];
        for (var i = 1; i < tfrow; i++) {
            tbRow[i] = document.getElementById('tableid').rows[i];
            tbRow[i].onmouseover = function () {
                this.style.backgroundColor = '#f3f8aa';
            };
            tbRow[i].onmouseout = function () {
                this.style.backgroundColor = '#ffffff';
            };
        }
    };

    $(document).on('click', '[name=file_upload]', function () {
        $(this).next().trigger('click');
    });
    $(document).on('change', '[name=uploadFile]', function () {
        var _this = this;
        if (!$(this)[0].files[0]) {
            return;
        }

        var formData = new FormData();
        formData.append('file', $(this)[0].files[0]);
        var size = $(this)[0].files[0].size;
        if (size > (8 * 1024 * 1024)) {
            layer.alert("文件不能大于8MB", {icon: 5});
            return;
        }

        var ln;
        $.ajax({
            url: '/admin/flow/uploadSiteFile',
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            beforeSend: function () {
                ln = layer.load();
            },
            complete: function () {
                layer.close(ln);
            },
            success: function (result) {
                var data = result.data;
                $(_this).next().val(data.file_url);
                $(_this).prev().addClass('file');

                layer.alert('上传成功');
            },
            error: function (XMLHttpRequest) {
                if (XMLHttpRequest.status === 500) {
                    layer.alert("异步请求失败", {icon: 5});
                    return;
                }
                layer.alert(JSON.parse(XMLHttpRequest.responseText).message, {icon: 0});
            }
        });
    });

    function downloadSiteFile(id, type = 0) {
        var url = "/admin/flow/downloadSiteFile/" + id + "/type/" + type;
        window.open(url);
    }

    // 滑动滚动条
    tableHeader()

    function tableHeader() {
        $("#tableid").parent().prepend(
            '<table id="tableid_" border="0" cellspacing="0" cellpadding="0"><thead>' + $("#tableid thead").html() + '</thead></table>'
        ).css({
            'position': 'relative',
            'height': '90%',
            'overflow-y': 'auto'
        })
        $("#tableid_").find('th').each(function (i) {
            $(this).css('width', $('#tableid').find('th:eq(' + i + ')').width());
        });
        $("#tableid_").find('th').each(function (i) {
            $(this).css('width', $('#tableid').find('th:eq(' + i + ')').width());
        });
        $("#tableid_").css({
            'position': 'sticky',
            'top': '0',
            'left': 0,
            'z-index': 2
        })
        $("#tableid").css({
            'position': 'absolute',
            'top': 0,
            'left': 0
        })
    }

    function taskByStatus(tis, input) {
        if ($(tis).hasClass('btn')) {
            $(tis).removeClass('btn');
            $(tis).addClass('btn2');
            $(tis).text('完成');
            $(input).attr('value', '{{$date}}');
        } else {
            $(tis).removeClass('btn2');
            $(tis).addClass('btn');
            $(tis).text('未完成');
            $(input).attr('value', 0);
        }
    }

    window.addEventListener("keydown", function (e) {
        //可以判断是不是mac,如果是mac,ctrl变为花键
        //event.preventDefault() 方法阻止元素发生默认的行为。
        if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
            e.preventDefault();
            // Process event...
            $('#form1').submit();
            //window.location.reload();
        }

    }, false);

    /*    function resetting(siteId) {
            layer.confirm('确定重置吗?', {icon: 3, title: '重置'}, function (index, layero) {
                var ajaxConfig = {
                    url: '/admin/flow/resetting',
                    type: 'put',
                    data: {siteId: siteId},
                    success: function () {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1500 //2秒关闭(如果不配置,默认是3秒)
                        }, function () {
                            window.location.href = "{{url('/admin/flow/siteConstructionProcess/'.$siteId.'/type/1')}}";
                    });
                }
            };
            tips.ajax(ajaxConfig);
        });
    }*/

    function taskResetting(taskId) {
        layer.confirm('确定重置此条任务吗?', {icon: 3, title: '重置此条任务'}, function (index, layero) {
            var ajaxConfig = {
                url: '/admin/flow/taskResetting',
                type: 'put',
                data: {taskId: taskId},
                success: function () {
                    layer.msg('操作成功', {
                        icon: 1,
                        time: 1500 //2秒关闭(如果不配置,默认是3秒)
                    }, function () {
                        window.location.href = "{{url('/admin/flow/siteConstructionProcess/'.$siteId.'/type/1')}}";
                    });
                }
            };
            tips.ajax(ajaxConfig);
        });
    }
</script>