<?php
$channel_id = Dever::input('set')['channel_id'] ?? 0;
if (!$channel_id) {
    $channel_id = Dever::input('field')['channel_id'] ?? 0;
}
$id = Dever::input('id');
$type = 'text';
if ($id > 0) {
    $type = 'show';
}
return array
(
    'list' => array
    (
        'stat' => 'channel/manage.showCardStat',
        'where' => array('channel_id' => $channel_id),
        'field'      => array
        (
            'id',
            'seller_id' => array
            (
                'name' => '商户',
                'show' => '{seller_id} > 0 ? Dever::db("info", "seller")->find({seller_id})["name"] : "无"',
            ),
            'goods' => array
            (
                'name' => '商品',
                'show' => 'Dever::load("manage", "goods")->showGoodsInfo("{goods_id}", "{sku_id}")',
            ),
            'number' => array
            (
                'show' => '"{number} "',
            ),
            'use_status',
            'status' => array
            (
                'type' => 'switch',
                'show'  => '{status}',
                'active_value' => 1,
                'inactive_value' => 2,
            ),
        ),
        'data_button' => array
        (
            '查看' => array('fastedit', 'number,pwd,end'),
        ),
        'button' => array
        (
            '新增' => array('fastadd', array
            (
                'channel_id' => $channel_id,
            )),
            '上传卡密文件' => array('fastadd', array
            (
                'path' => 'supplier/card_upload',
                'param' => array
                (
                    'set' => array('channel_id' => $channel_id),
                ),
            ), 'ChatLineSquare'),
            '下载卡密模板' => array('link', Dever::host() . 'data/card.xlsx?v1'),
        ),
        'search' => array
        (
            'channel_id' => 'hidden',
            'seller_id' => array
            (
                'name' => '选择商户',
                'option'     => 'Dever::load("seller/manage")->getList('.$channel_id.')',
            ),
            'sku_id' => array
            (
                'name' => '商品',
                'placeholder' => '请选择商品',
                'type' => 'cascader',
                'option'    => 'Dever::load("goods/manage")->getGoodsSku("km")',
                'search' => function($key, $type, $value) {
                    $value = end($value);
                    return $value;
                }
            ),
            'number',
            'pwd',
            'use_status',
            'status',
        ),
    ),
    'update' => array
    (
        'check' => 'number',
        'field'    => array
        (
            'seller_id' => array
            (
                'desc' => '请选择要分配卡密的商户，上传后将自动分配给这个商户，如未选择，则为通用卡密，任何商户都可以购买',
                'option'     => 'Dever::load("seller/manage")->getList('.$channel_id.')',
            ),
            'channel_id' => array
            (
                'type' => 'hidden',
            ),
            'goods' => array
            (
                # 数据来源
                'name' => '商品',
                'type' => 'cascader',
                'option'    => 'Dever::load("goods/manage")->getGoods("km")',
                'remote' => 'goods/manage.getSku',
                # 无需默认值
                //'remote_default' => false,
                'rules' => true,
            ),
            'goods_id' => array
            (
                'name' => '商品',
                'type' => 'hidden',
                'rules' => true,
            ),
            'sku_id' => array
            (
                'name' => '规格',
                'type' => 'select',
                'rules' => true,
            ),
            'number' => array
            (
                'type' => $type,
                'rules' => true,
                'default' => '"{number} "',
            ),
            'pwd' => array
            (
                'type' => $type,
                'rules' => true,
            ),
            'end' => array
            (
                'type' => $type,
            ),
        ),
    ),
);