<?php
namespace admin\action\pro;

use model\pack\packs;
use model\pro\pro;

class packAction  extends \action
{   
    /**
     * @method 包装页面
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function list()
    {
        $req = \mvc::$req;
        //产品信息
        if($req['p_id']){
            $item = (new pro())->getRowByKey($req['p_id']);
        }
        \view::set('item', $item);
        \view::set('req', $req);
        \view::put();
    }

    /**
     * @method 获取包装方案数据列表
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function getList()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $list = $packs->getList($req);
        $this->successJson($list);
    }

    /**
     * @method 保存包装相关信息
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function savePack()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $id = $packs->saveDetail($req);
        $this->successJson(['key'=>$id]);
    }

    /**
     * @method 获取事业部
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function getComKVList()
    {   
        $req = \mvc::$req;
        $pro = new pro();
        $rows = $pro->getPlcComList();
        // $rows = $result['rows'];
        $data = [];
        $regi=0;
		$firstkey = isset($req['firstkey'])? $req['firstkey']: 0;
        if(isset($req['hasFirst']) && $req['hasFirst']){
            $data[0] = ['key'=>$firstkey, 'value'=>'' ];
            $regi = 1;
        }
        foreach($rows as $k=>$row){

            $data[$k+$regi] = ['key'=>$row['com_id'], 'value'=> $row['com_name'] ];
        }
        $this->successJson($data);
        
    }
    /**
     * @method 编辑子料页面
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function editMaterial()
    {
        $req = \mvc::$req;
        \view::set('req', $req);
        \view::put();
    }

    /**
     * @method 获取子料数据
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function getMaterialList()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $result = $packs->getMaterialList($req);
        $this->successJson($result);
    }

    /**
     * @method 编辑子零件页面
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function editSonPro()
    {
        $req = \mvc::$req;
        \view::set('req', $req);
        \view::put();
    }

    /** 
     * @method 获取子零件数据
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function getSonProList()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $result = $packs->getSonProList($req);
        $this->successJson($result);
    }

    /**
     * @method 设置默认
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function setDefault()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $result = $packs->setDefault($req);
        $this->successJson($result);
    }

    /**
     * @method 删除
     * @author zhengweihua 
     * @copyright 2025-12-15
     */
    public function delData()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $result = $packs->delData($req['ids']);
        $this->successJson($result);
    }


    /**
     * @method 内盒比较
     * @author zhengweihua 
     * @copyright 2026-01-05
     */
    public function compareBox()
    {
        $req = \mvc::$req;
        $packs = new packs();
        $list = $packs->compareBox($req['ppids']);
        \view::set('list', $list['arr']);
        \view::set('attcatArr', $list['attcatArr']);
        \view::set('req', $req);
        \view::put();
    }

    public function fixPackStyle()
    {
        $packs = new packs();
        $list = $packs->fixPackStyle();
        $this->successJson($list);
    }
}
