Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新时,没有把数据带过来 #1

Open
sunkangchina opened this issue May 21, 2021 · 2 comments
Open

更新时,没有把数据带过来 #1

sunkangchina opened this issue May 21, 2021 · 2 comments

Comments

@sunkangchina
Copy link

protected function form()
    {
        return Form::make(new ShopGood(), function (Form $form) {
            $form->title('商品');
            $formStep = $form->multipleSteps();
            $formStep->add('商品分类', function ($step) {
                $step->tree('type_id')
                    ->nodes(ShopType::get()->toArray())
                    ->setIdColumn('id')
                    ->setTitleColumn('title')
                    ->setParentColumn('pid')
                    ->customFormat(function ($v) { // 格式化外部注入的值
                        if (!$v) return [];
                        return array_column($v, 'id');
                    })->required();
            });
            $formStep->add('商品基本信息', function ($step) {
                $step->text('title')->required();
                $step->weditor('body')->required();
                $step->select('sku_type')->options(Model::nodeSkuTypeSelect())->default(1)
                    ->when([1], function ($step) {
                        $step->currency('price');
                    })->when([2], function ($step) {
                        $sku_params = [
                            [
                                'name'    => '进货价',
                                'field'   => 'price_buy',
                                'default' => '',
                            ],
                            [
                                'name'    => '市场价',
                                'field'   => 'price_mark',
                                'default' => '',
                            ],
                        ];
                        $step->sku('sku', json_encode($sku_params))
                            ->display(true)
                            ->customFormat(function ($value) use ($step) {
                                if ($value === null) {
                                    $data = new \stdClass();
                                    $data->attrs = [
                                        '颜色' => [
                                            '红色',
                                            '蓝色',
                                        ],
                                        '大小' => [
                                            '20',
                                        ],
                                    ];
                                    $data->sku = [
                                        [
                                            "颜色" => "红色",
                                            "大小" => '20',
                                            "pic" => '',
                                            "stock" => '1',
                                            "price" => '100',
                                        ],
                                    ];
                                    return json_encode($data);
                                }
                                return null;
                            });
                    });
            });
            $form->tools(function (Form\Tools $tools) {
                $tools->disableDelete();
            });
        });
    }
@jqhph
Copy link
Contributor

jqhph commented May 21, 2021

不支持更新,只能新增

@sunkangchina
Copy link
Author

这就尴尬了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants