<?php
namespace app\api\controller\v1;

use app\api\controller\Base;
use app\hander\HelpHander;
use think\Db;

class WorkNews extends Base
{

    // 新增
    public function save(){
        model('WorkNews')->add();
        HelpHander::success([],'操作成功');
    }

    // 详情
    public function detail(){
        $id = input('id/d',0);
        $ret = model('WorkNews')->info($id);
        HelpHander::success($ret);
    }

    // 我收到的汇报详情
    public function rdetail(){
        $id = input('id/d',0);
        $ret = model('WorkNews')->receiveInfo($id);
        HelpHander::success($ret);
    }

    // 我提交的汇报列表
    public function list(){
        $page = input('page/d',1);
        $size = input('size/d',10);
        $ret = model('WorkNews')->lists($page,$size,$this->userId,$this->orgId);
        HelpHander::success($ret);
    }

    // 我提交的汇报列表
    public function receiveList(){
        $page = input('page/d',1);
        $size = input('size/d',10);
        $ret = model('WorkNews')->receiveList($page,$size,$this->userId,$this->orgId);
        HelpHander::success($ret);
    }

    // 我的接收人
    public function receiver(){
        $ret = model('WorkNews')->myReceiver($this->userId,$this->orgId);
        HelpHander::success($ret);
    }

    // 我的审核人
    public function auditor(){
        $ret = model('WorkNews')->auditor($this->userId,$this->orgId);
        HelpHander::success($ret);
    }

    // 撤销
    public function cancel(){
        $id = input('id/d',0);
        model('WorkNews')->cancel($id,$this->userId);
        HelpHander::success([],'成功');
    }

    // 同意
    public function agree(){
        $id = input('id/d',0);
        model('WorkNews')->agree($id,$this->userId);
        HelpHander::success([],'成功');
    }
    // 拒绝
    public function disagree(){
        $id = input('id/d',0);
        model('WorkNews')->disagree($id,$this->userId);
        HelpHander::success([],'成功');
    }

    // 获取报告项目列表
    public function itemLists(){
        $page = input('page/d',1);
        $size = input('size/d',10);
        $content = input('content','','trim');
        $workTypeId = input('workTypeId/d',0);
        $name = input('name','','trim');
        $ret = model('WorkNews')->itemLists($page,$size,$this->userId,$this->orgId,$content,$workTypeId,$name);
        HelpHander::success($ret);
    }

    public function itemAll(){
        $content = input('content','','trim');
        $workTypeId = input('workTypeId/d',0);
        $name = input('name','','trim');
        $ret = model('WorkNews')->itemAll($this->userId,$this->orgId,$content,$workTypeId,$name);
        HelpHander::success($ret);
    }

    // 获取报告项目列表
    public function allItemLists(){
        $page = input('page/d',1);
        $size = input('size/d',10);
        $content = input('content','','trim');
        $workTypeId = input('workTypeId/d',0);
        $name = input('name','','trim');
        $label = input('label/d',0);
        $ret = model('WorkNews')->allItemLists($page,$size,$this->userId,$this->orgId,$content,$workTypeId,$name,$label);
        HelpHander::success($ret);
    }

    public function allItemAll(){
        $content = input('content','','trim');
        $workTypeId = input('workTypeId/d',0);
        $name = input('name','','trim');
        $label = input('label/d',0);
        $ret = model('WorkNews')->allItemAll($this->userId,$this->orgId,$content,$workTypeId,$name,$label);
        HelpHander::success($ret);
    }

    public function addLabel(){
        $itemid = input('itemId/d',0);
        $type = input('type/d',1);
        if($itemid <= 0 || !in_array($type,[1,2,3])){
            HelpHander::error('参数错误');
        }
        model('WorkNews')->addLabel($itemid,$type,$this->userId);
        HelpHander::success([],'操作成功');
    }

    public function delLabel(){
        $id = input('id/d',0);
        if($id <= 0){
            HelpHander::error('参数错误');
        }
        model('WorkNews')->delLabel($id,$this->userId);
        HelpHander::success([],'操作成功');
    }

    public function unapply(){
        $ret = model('WorkNews')->unapply($this->userId);
        HelpHander::success($ret);
    }

}