<table class="table table-sm table-striped table-bordered table-hover card-body p-0 m-0">
    <tr class="text-center">
        <th><label for="selectAll"></label><input type="checkbox" class="form-check" name="selectAll" id="selectAll" @click="checkAll"></th>
        <th>序号</th>
        <th>预约时间</th>
        <th>客户名称</th>
        <th>仓库</th>
        <th>作业名称</th>
        <th>入库单号</th>
        <th>数量</th>
        <th>单位</th>
        <th>单价</th>
        <th>收费</th>
        <th>状态</th>
        <th>备注</th>
        <th>操作</th>
        <th>创建时间</th>
    </tr>
    <template v-if="dischargeTasks.length > 0">
        <tr v-for="(dischargeTask,index) in dischargeTasks" :key="index" class="text-center"  @click.self="selectTr===index+1?selectTr=0:selectTr=index+1" :class="selectTr===index+1?'focusing' : ''">
            <td><label>
                    <input type="checkbox" class="form-check" :value="dischargeTask.id" v-model="checkData">
                </label></td>
            <td>
                @{{index+1}}
                <template v-if="dischargeTask.status===0">
                    <span class="badge badge-pill badge-secondary">未指定装卸队</span>
                </template>
                <template v-else-if="dischargeTask.status===1">
                    <span class="badge badge-pill badge-warning">任务已指定</span>
                </template>
                <template v-else-if="dischargeTask.status===2">
                    <span class="badge badge-pill badge-success">进行中</span>
                </template>
                <template v-else-if="dischargeTask.status===3">
                    <span class="badge badge-pill badge-success">完成</span>
                </template>
            </td>
            <td><template v-if="dischargeTask.status === 3">
                    <button class="btn btn-sm btn-success" style="opacity: 0.7" @click="showReceipt(dischargeTask)"
                            @mouseenter="dischargeTask.btnText = '查看'" @mouseleave="dischargeTask.btnText = '查'">@{{ dischargeTask.btnText }}</button>
                </template>@{{ dischargeTask.income_at }}</td>
            <td>@{{ dischargeTask.owner ? dischargeTask.owner.name : '' }}</td>
            <td>
                @can('人事管理-卸货-编辑')
                    <select :value="dischargeTask.warehouse_id" class="form-control form-control-sm" :disabled="dischargeTask.status>0" @change="updateCurrentTaskColumn(dischargeTask,index,'warehouse_id',$event)">
                        <option v-for="(type,i) in warehouses" :value="type.id">@{{ type.name }}</option>
                    </select>
                @else
                        @{{ dischargeTask.warehouse ? dischargeTask.warehouse.name : '' }}
                @endcan
            </td>
            <td>
                @can('人事管理-卸货-编辑')
                    <select :value="dischargeTask.type" class="form-control form-control-sm" :disabled="dischargeTask.status>0" @change="updateCurrentTaskColumn(dischargeTask,index,'type',$event)">
                        <option v-for="(type,i) in taskTypes" :value="type.name">@{{ type.value }}</option>
                    </select>
                @else
                    <span v-html="getType(dischargeTask.type)"></span>
                @endcan
            </td>
            <td>
                @can('人事管理-卸货-编辑')
                    <input type="text" :value="dischargeTask.numbers" class="form-control form-control-sm" :disabled="dischargeTask.status>0" @change="updateCurrentTaskColumn(dischargeTask,index,'numbers',$event)">
                @else
                    @{{ dischargeTask.numbers }}
                @endcan
            </td>
            <td>@{{ dischargeTask.income_amount }}</td>
            <td>
                @can('人事管理-卸货-编辑')
                    <select  :value="dischargeTask.income_unit" class="form-control form-control-sm" :disabled="dischargeTask.status>0" @change="updateCurrentTaskColumn(dischargeTask,index,'income_unit',$event)">
                        <option v-for="(unit,i) in units" :value="unit.name" v-html="unit.value"></option>
                    </select>
                @else
                    <span v-html="getUnit(dischargeTask.income_unit)"></span>
                @endcan
            </td>
            <td>@{{ dischargeTask.income_unit_price }}</td>
            <td>@{{ dischargeTask.income_total_cost }}</td>
            <td>
                @can('人事管理-卸货-编辑')
                    {{--  dischargeTask.status===3 完成时不可编辑状态 --}}
                    <select :value="dischargeTask.status" class="form-control form-control-sm" :disabled="dischargeTask.status===3" @change="updateCurrentTaskColumn(dischargeTask,index,'status',$event)">
                        <option v-for="(type,i) in status" :value="type.name" v-html="type.value" :disabled="dischargeTask.status > type.name"></option>
                    </select>
                @else
                    <span>@{{ dischargeTask.status }}</span>
                @endcan
            </td>
            <td>
                @can('人事管理-卸货-编辑')
                    <textarea class="form-control" cols="15" rows="2" :value="dischargeTask.income_remark" :disabled="dischargeTask.status>0" @change="updateCurrentTaskColumn(dischargeTask,index,'income_remark',$event)"></textarea>
                @else
                    @{{ dischargeTask.income_remark }}
                @endcan
            </td>
            <td>
                @can('人事管理-卸货-编辑')
                <button class="btn btn-sm btn-outline-primary" @click="showExecutingTaskModal(index,true,dischargeTask)" v-show="dischargeTask.status===0">指定服务商</button>
                @endcan
                @can('人事管理-卸货-编辑')
                <button class="btn btn-sm btn-outline-primary" @click="showUpdateTaskModal(index,true,dischargeTask)" v-show="dischargeTask.status<=1">编辑</button>
                @endcan
                @can('人事管理-卸货-删除')
                <button class="btn btn-sm btn-outline-danger" @click="deleteTask(index,dischargeTask)">删除</button>
                @endcan
            </td>

            <td>@{{ dischargeTask.created_at }}</td>
        </tr>
    </template>
    <template v-else>
        <tr>
            <td colspan="15">
                <div class="alert alert-info text-lg-center">卸货任务数据为空</div>
            </td>
        </tr>
    </template>
</table>
{{ $dischargeTasks->withQueryString()->links() }}

