<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('sales', ['action' => 'detail', 'id' => $this->orderInfo->getOrderId()]);?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('点击修改单号'); ?></button>
            <?php echo $this->HelpUrl('editExpressNumber'); ?>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->translate('订单发货信息'); ?></h3>
                    </div>
                    <div class="box-body">
                        <?php echo $this->partial('layout/messages'); ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('订单编号'); ?></label>
                            <div class="col-sm-3">
                                <p class="form-control-static"><?php echo $this->escapeHtml($this->orderInfo->getOrderSn()); ?></p>
                            </div>
                        </div>
                        <?php if($this->orderDeliveryAddress && !empty($this->orderDeliveryAddress->getDeliveryTimeInfo())) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('送货时间'); ?></label>
                                <div class="col-sm-3">
                                    <p class="form-control-static"><?php echo $this->escapeHtml($this->orderDeliveryAddress->getDeliveryTimeInfo()); ?></p>
                                </div>
                            </div>
                        <?php } ?>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('配送模式'); ?></label>
                            <div class="col-sm-2">
                                <p class="form-control-static"><?php echo $this->translate('单独配送'); ?></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><?php echo $this->translate('操作备注'); ?></label>
                            <div class="col-sm-6">
                                <p class="form-control-static"><?php echo nl2br($this->escapeHtml($this->orderStatusInfo->getStatusInfo())); ?></p>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <?php echo $this->formElementErrors($form->get('goodsId'), ['class'=>'error-message']); ?>
                        <?php echo $this->formElementErrors($form->get('expressNumber'), ['class'=>'error-message']); ?>
                        <table class="table shop-table table-bordered">
                            <thead>
                            <tr class="shop-bg-thead">
                                <th width="30%"><?php echo $this->translate('商品名称'); ?></th>
                                <th width="15%"><?php echo $this->translate('商品货号'); ?></th>
                                <th width="15%"><?php echo $this->translate('商品规格'); ?></th>
                                <th width="8%"><?php echo $this->translate('购买数量'); ?></th>
                                <th width="16%"><?php echo $this->translate('快递信息'); ?></th>
                                <th width="16%"><?php echo $this->translate('快递单号'); ?><span class="must_add_value">*</span></th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach($this->orderInfo->getOrderGoods() as $goodsValue) { ?>
                                <tr>
                                    <td>
                                        <input type="hidden" name="goodsId[]" value="<?php echo $goodsValue->getGoodsId(); ?>">
                                        <img src="<?php echo $this->goodsHelper()->goodsImage($goodsValue->getGoodsImage()); ?>" class="img-thumbnail" style="width: 50px;height: 50px;">
                                        <?php echo $this->escapeHtml($goodsValue->getGoodsName()); ?>
                                    </td>
                                    <td><?php echo $this->escapeHtml($goodsValue->getGoodsItem()); ?></td>
                                    <td>
                                        <?php if(!empty($goodsValue->getInSpecGoodsStr())) { echo $this->escapeHtml($goodsValue->getInSpecGoodsStr()); } else echo $this->translate('无'); ?>
                                    </td>
                                    <td><?php echo $goodsValue->getBuyNum(); ?></td>
                                    <td><?php echo $this->escapeHtml($goodsValue->getDeliveryName()); ?></td>
                                    <td>
                                        <input type="text" name="expressNumber[]" value="<?php echo $this->escapeHtml($goodsValue->getExpressNumber()); ?>" class="form-control">
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <?php echo $this->form()->closeTag(); ?>

</div>
<script>
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            submitHandler: function(form) {
                let expressNumberStatus = true;
                $("input[name='expressNumber[]']").each(function() {
                    if(this.value.length <= 0) {
                        shopMessage('<?php echo $this->translate('请填写快递单号!'); ?>');
                        expressNumberStatus = false;
                        return false;
                    }
                });
                if(!expressNumberStatus) return false;

                form.submit();
            }
        });
    });
</script>
