<?php

namespace App\Admin\Actions\Device;

use App\Model\DeliverInfo;
use App\Model\DeviceInfo;
use App\Server\DeviceServer;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class DeviceOperator extends RowAction
{
    public $name = '设备管理';

    public function handle(Model $model)
    {
        // $model ...
//        $row = $this->getRow();
        $device = new DeviceServer();
//        $s =  request('runningStatus');
//        if ($row['runningStatus'] != $s)
//            $device->switchDevice($row['iot_id'],$s);
//        $s =  request('deliver_lock_switch');
//        if ($row['deliver_lock_switch'] != $s)
//            $device->doorInOperation($row['iot_id'],$s);
//        $s =  request('lock_switch');
//        if ($row['lock_switch'] != $s)
//            $device->doorInOperation($row['iot_id'],$s);

        return $this->response()->info('操作成功')->refresh();
    }



    public function form()
    {
        $row = $this->getRow();
//        $s = 1;
//        if ($row['runningStatus'] == DeviceInfo::DISABLE)
//            $s = 0;
//        $this->radio('runningStatus', '锁定设备')->options(['打开','关闭'])->default($s);
//        $s = 1;
//        if ($row['deliver_lock_switch'] == 0)
//            $s = 0;
//        $this->radio('deliver_lock_switch', '投递门状态')->options(['打开','关闭'])->default($s);
//        $s = 1;
//        if ($row['lock_switch'] == 0)
//            $s = 0;
//        $this->radio('lock_switch', '收运门状态')->options(['打开','关闭'])->default($s);
        $this->html("<div>设备开关不会影响真实数据，只做临时调试用。不能用来收运，不能用来收运，不能用来收运，否者会导致后台账目混乱，并且称读数也不会清零！</div>",'提示:');
//        $this->H("<div><a href='javascript:setDeviceStatus(\"switchDevice\",\"{$row['iot_id']}\",1);' class='btn btn-success'>启用</a>&nbsp;<a href='javascript:setDeviceStatus(\"switchDevice\",\"{$row['iot_id']}\",0);' class='btn btn-danger'>禁用</a></div>",'设备:');
//        $this->H("<div><a href='javascript:setDeviceStatus(\"doorOperation\",\"{$row['iot_id']}\",2);' class='btn btn-success'>打开</a></div>",'收运门:');
//        $this->H("<div><a href='javascript:setDeviceStatus(\"doorOperation\",\"{$row['iot_id']}\",1);' class='btn btn-success'>打开</a>&nbsp;<a href='javascript:setDeviceStatus(\"doorOperation\",\"{$row['iot_id']}\",0);' class='btn btn-danger'>关闭</a></div>",'投递门:');


    }

}
