form-step icon indicating copy to clipboard operation
form-step copied to clipboard

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

Open sunkangchina opened this issue 4 years ago • 2 comments

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();
            });
        });
    }

sunkangchina avatar May 21 '21 01:05 sunkangchina

不支持更新,只能新增

jqhph avatar May 21 '21 02:05 jqhph

这就尴尬了。

sunkangchina avatar May 21 '21 04:05 sunkangchina