<?php
namespace backendApi\modules\v1\models\lists\shop;

use common\helpers\Tool;
use common\libs\dataList\column\DateTime;
use common\libs\dataList\column\YesNo;
use common\libs\dataList\DataListInterface;
use common\models\DeclarationLevel;
use common\models\DeclarationPackage;

class PackageList extends \common\libs\dataList\DataList implements DataListInterface
{
    /**
     * 列表名称
     * @return string
     */
    public function getListName(){
        return 'Kitting products list';//套餐列表
    }

    /**
     * 列表筛选到的数据
     */
    public function dataHandle()
    {
        $this->listData = DeclarationPackage::lists($this->condition, $this->params, [
            'select' => 'DP.*,DL.LEVEL_NAME',
            'orderBy' => 'DP.CREATED_AT DESC, DP.ID DESC',
            'from' => DeclarationPackage::tableName(). ' AS DP',
            'join' => [
                ['LEFT JOIN', DeclarationLevel::tableName() . ' AS DL', 'DP.LEVEL_ID=DL.ID'],
            ],
            'page' => $this->page,
            'pageSize' => $this->pageSize,
        ]);
    }

    /**
     * 要展示和导出的所有字段
     * @return array
     */
    public function getColumn(){
        if(!$this->columns){
            $this->columns = [
                'ID' => null,
                'PACKAGE_NAME' => [
                    'header' => 'Kitting Products Name', // 套餐名称
                    'headerOther' => ['width' => '200'],
                ],
                'PACKAGE_NO' => [
                    'header' => 'Kitting Products Code', // 套餐编号
                    'headerOther' => ['width' => '200'],
                ],
                'LEVEL_NAME' => [
                    'header' => 'Entry Level', // 所属报单级别
                    'headerOther' => ['width' => '200'],
                ],
                'AMOUNT_STANDARD' => [
                    'header' => 'Standard Price', // 标准价格
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['AMOUNT_STANDARD']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
			'STORE_NUMS' => [
			    'header' => 'Kitting Stock', // 库存
			    'headerOther' => ['width' => '200'],
			],
                'AMOUNT' => [
                    'header' => 'Kit Price', // 套餐金额
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['AMOUNT']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'PV' => [
                    'header' => 'Kitting Products BV', // 套餐BV
                    'headerOther' => [
                        'width' => '150',
                    ],
                    'value' => function ($row) {
                        return Tool::formatPrice($row['PV']);
                    },
                    'valueOther' => function ($row) {
                        return [
                            'tag' => ['type' => 'danger', 'size' => 'small', 'class' => 'no-border']
                        ];
                    },
                ],
                'STATUS' => [
                    'header' => 'Status', // 状态
                    'value' => function($row) {
                        return $row['STATUS'] == 1 ? 'On sale' : 'Sold out';//'已上架' : '已下架'
                    },
                    'headerOther' => [
                        'width' => '110',
                    ],
                ],
                'PACKAGE_CONTENT' => [
                    'header' => 'Kit Products', // 套餐内容
                    'headerOther' => ['width' => '290'],
                ],
                'CREATED_AT' => [
                    'header' => 'Creation Time', // 创建时间
                    'value' => function ($row) {
                        return (new DateTime([
                            'value' => $row['CREATED_AT'],
                        ]))->result();
                    },
                    'headerOther' => ['width' => '190'],
                ],
            ];
        }
        return $this->columns;
    }

    /**
     * 前台用于筛选的类型集合
     * @return mixed
     */
    public function getFilterTypes()
    {
        if(!$this->filterTypes){
            $this->filterTypes = [
                'LEVEL_NAME'=> ['name'=> 'Entry Level', 'other'=> 'decLevel'], // 所属报单级别
                'PACKAGE_NAME'=> ['name'=> 'Kitting Products Name'], // 套餐名称
                'AMOUNT'=> ['name'=> 'Kitting Products Amount'], // 套餐金额
                'PV'=> ['name'=> 'Kitting Products BV'], // 套餐BV
                'STATUS'=> ['name'=> 'Status', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> 'On Sale'],['id'=> 0, 'name'=> 'Sold Out']]], // 状态，已上架，已下架
            ];
        }
        return $this->filterTypes;
    }
}