<?php

namespace App\Models;

class Device extends BaseModel
{
    // 设备类型

    public function getDeviceOptions()
    {
        $items = Device::select('name as text', 'id as value')->get();
        $items = $items->prepend($this->transObject(['text' => '设备类型', 'value' => '']));
        foreach ($items as $item) {
            $names = DeviceName::where('device_id', $item->value)->select('name as text', 'id as value')->get();
            $item->names = $names->prepend($this->transObject(['text' => '设备名称', 'value' => '']));
            foreach($item->names as $name) {
                $specs  = Spec::where('device_name_id', $name->value)->select('name as text', 'id as value')->get();
                $name->specs = $specs->prepend($this->transObject(['text' => '规格型号', 'value' => '']));
            }
        }
        return $items;
    }


    public function transObject($items)
    {
        return json_decode(json_encode($items));
    }
}
