{{include file="public/header" /}}

<!-- right content start  -->
<div class="content-right">
	<div class="content">
		<!-- form start -->
		<form class="am-form form-validation view-save" action="{{:MyUrl('admin/goods/save')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/goods/index', $params)}}" enctype="multipart/form-data">
			<legend>
				<span class="am-text-default">商品{{if empty($data['id'])}}添加{{else /}}编辑{{/if}}</span>
				<a href="{{:MyUrl('admin/goods/index', $params)}}" class="am-fr am-text-sm am-margin-top-sm am-icon-mail-reply"> 返回</a>
			</legend>

			<nav class="goods-nav">
				<ul>
					<li>
						<a href="javascript:;" data-value="#goods-nav-base">基础信息</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-operations">商品规格</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-parameters">商品参数</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-photo">商品相册</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-video">商品视频</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-app">手机详情</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-web">电脑详情</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-fictitious">虚拟信息</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-extends">扩展数据</a>
					</li>
					<li>
						<a href="javascript:;" data-value="#goods-nav-seo">SEO</a>
					</li>
					<li class="am-text-center am-padding-xs nav-shrink-submit">
						<i class="am-icon-angle-double-right am-icon-sm"></i>
					</li>
				</ul>
			</nav>

			<!-- 基础信息 -->
			<div class="am-panel am-panel-default" id="goods-nav-base">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">基础信息</h3>
                </div>
                <div class="am-panel-bd am-padding-vertical-xs">
					<div class="am-form-group">
						<label>标题名称<span class="am-form-group-label-tips-must">必填</span></label>
						<div class="am-input-group am-input-group-sm">
							<input type="hidden" name="title_color" value="{{if !empty($data['title_color'])}}{{$data.title_color}}{{/if}}" />
							<input type="text" name="title" placeholder="标题名称" minlength="2" maxlength="160" data-validation-message="标题名称格式 2~160 个字符" class="am-form-field am-radius" {{if !empty($data)}} value="{{$data.title}}" {{/if}} {{if !empty($data['title_color'])}} style="color:{{$data.title_color}};" {{/if}} required />
							<span class="am-input-group-btn">
								<button type="button" class="am-btn am-btn-default am-btn-xs colorpicker-submit" data-input-tag="input[name='title']" data-color-tag="input[name='title_color']">
									<img src="{{$attachment_host}}/static/common/images/colorpicker.png" />
								</button>
							</span>
						</div>
					</div>
					<div class="am-form-group">
						<label>商品简述<span class="am-form-group-label-tips">选填</span></label>
						<input type="text" name="simple_desc" placeholder="商品简述" maxlength="230" data-validation-message="商品简述格式 最多230个字符" class="am-radius" {{if !empty($data)}} value="{{$data.simple_desc}}"{{/if}} />
					</div>
					<div class="am-form-group">
						<label>商品型号<span class="am-form-group-label-tips">选填</span></label>
						<input type="text" name="model" placeholder="商品型号" maxlength="30" data-validation-message="商品型号格式 最多30个字符" class="am-radius" {{if !empty($data)}} value="{{$data.model}}"{{/if}} />
					</div>
					<div class="am-form-group">
						<label>商品分类<span class="am-form-group-label-tips-must">至少选择一个</span></label>
						<br />
						<select name="category_id" class="am-radius chosen-select" multiple="multiple" minchecked="1" data-placeholder="请选择..." data-validation-message="请至少选择一个商品分类" required>
							{{if !empty($goods_category_list)}}
								{{foreach $goods_category_list as $v}}
									<option value="{{$v.id}}" {{if !empty($data['category_ids']) and in_array($v['id'], $data['category_ids'])}}selected{{/if}}>一级 - {{$v.name}}</option>
									{{if !empty($v['items'])}}
										{{foreach $v.items as $vs}}
											<option style="padding-left: 30px;" value="{{$vs.id}}" {{if !empty($data['category_ids']) and in_array($vs['id'], $data['category_ids'])}}selected{{/if}}>二级-{{$vs.name}}</option>
											{{if !empty($vs['items'])}}
												{{foreach $vs.items as $vss}}
													<option style="padding-left: 60px;" value="{{$vss.id}}" {{if !empty($data['category_ids']) and in_array($vss['id'], $data['category_ids'])}}selected{{/if}}>三级-{{$vss.name}}</option>
												{{/foreach}}
											{{/if}}
										{{/foreach}}
									{{/if}}
								{{/foreach}}
							{{/if}}
						</select>
					</div>
					<div class="am-form-group">
						<label>品牌<span class="am-form-group-label-tips">可选</span></label>
						<br />
						<select name="brand_id" class="am-radius chosen-select" data-placeholder="请选择..." data-validation-message="请选择品牌">
							{{if !empty($brand_list)}}
								<option value="0">请选择...</option>
								{{foreach $brand_list as $v}}
									<option value="{{$v.id}}" {{if isset($data['brand_id']) and $data['brand_id'] eq $v['id']}}selected{{/if}}>{{$v.name}}</option>
								{{/foreach}}
							{{/if}}
						</select>
					</div>
					<div class="am-form-group">
						<label>生产地<span class="am-form-group-label-tips">可选</span></label>
						<br />
						<select name="place_origin" class="am-radius chosen-select" data-placeholder="请选择..." data-validation-message="请选择生产地">
							<option value="0">请选择...</option>
							{{if !empty($region_province_list)}}
								{{foreach $region_province_list as $v}}
									<option value="{{$v.id}}" {{if !empty($data['place_origin']) and $v['id'] eq $data['place_origin']}}selected{{/if}}>{{$v.name}}</option>
								{{/foreach}}
							{{/if}}
						</select>
					</div>
					<div class="am-form-group">
						<label>库存单位<span class="am-form-group-label-tips-must">必填</span></label>
						<input type="text" name="inventory_unit" placeholder="库存单位" minlength="1" maxlength="6" data-validation-message="库存单位格式 1~6 个字符" class="am-radius" {{if !empty($data)}} value="{{$data.inventory_unit}}"{{/if}} required />
					</div>
					<div class="am-form-group">
	                    <label>购买赠送积分比例<span class="am-form-group-label-tips">选填</span><span class="am-form-group-label-tips">按照商品金额比例乘以数量的比例进行发放</span></label>
	                    <div class="am-input-group am-input-group-sm">
	                        <input type="number" name="give_integral" placeholder="购买赠送积分" min="0" max="100" data-validation-message="购买赠送积分比例 0~100 的数字" class="am-form-field am-radius" {{if !empty($data['give_integral'])}} value="{{$data.give_integral}}"{{/if}} />
	                        <span class="am-input-group-btn">
	                            <button type="button" class="am-btn am-btn-default am-radius">%</button>
	                        </span>
	                    </div>
	                </div>
					<div class="am-form-group">
						<label>最低起购数量<span class="am-form-group-label-tips-must">必填</span><span class="am-form-group-label-tips">默认数值 1</span></label>
						<input type="number" name="buy_min_number" placeholder="最低起购数量" min="1" max="100000000" data-validation-message="最低起购数量 1~100000000" class="am-radius" value="{{if empty($data) or empty($data['buy_min_number'])}}1{{else /}}{{$data.buy_min_number}}{{/if}}" required />
					</div>
					<div class="am-form-group">
						<label>单次最大购买数量<span class="am-form-group-label-tips">选填</span><span class="am-form-group-label-tips">单次最大数值 100000000, 小于等于0或空则不限</span></label>
						<input type="number" name="buy_max_number" placeholder="单次最大购买数量" min="0" max="100000000" data-validation-message="单次最大购买数量 1~100000000" class="am-radius" {{if !empty($data['buy_max_number'])}} value="{{$data.buy_max_number}}"{{/if}} />
					</div>
					<div class="am-form-group">
						<label>商品类型<span class="am-form-group-label-tips">可选</span></label>
						<div class="am-alert am-alert-warning am-radius am-margin-top-0" data-am-alert>
						    <p>1. 当前系统配置的站点类型为[ <strong class="am-text-danger">{{$common_site_type_list[$common_site_type]['name']}}</strong> ]</p>
						    <p>2. 如果商品类型未配置则跟随系统配置的站点类型</p>
						    <p>3. 当设置的商品类型不在系统设置的站点类型包含的时候，商品加入购物车功能将失效</p>
						</div>
						<select name="site_type" class="am-radius chosen-select am-margin-top-xs" data-placeholder="可选择..." data-validation-message="请选择商品类型">
							<option value="-1">可选择...</option>
							{{if !empty($common_site_type_list)}}
								{{foreach $common_site_type_list as $v}}
									<option value="{{$v.value}}" {{if isset($data['site_type']) and $v['value'] eq $data['site_type']}}selected{{/if}}>{{$v.name}}</option>
								{{/foreach}}
							{{/if}}
						</select>
					</div>
					<div class="am-form-group am-form-file">
						<label class="block">封面图片<span class="am-form-group-label-tips">选传</span><span class="am-form-group-label-tips">留空则取相册第一张图、建议800*800px</span></label>
						<ul class="plug-file-upload-view goods-recommended-images-view" data-form-name="images" data-max-number="1" data-dialog-type="images">
							{{if !empty($data['images'])}}
								<li>
									<input type="text" name="images" value="{{$data.images}}" />
									<img src="{{$data.images}}" />
									<i>×</i>
								</li>
							{{/if}}
						</ul>
						<div class="plug-file-upload-submit" data-view-tag="ul.goods-recommended-images-view">+上传图片</div>
					</div>
					<div class="am-form-group">
						<label class="block">扣减库存<span class="am-form-group-label-tips">可选</span><span class="am-form-group-label-tips">扣除规则根据后台配置->扣除库存规则而定</span></label>
						<input name="is_deduction_inventory" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_deduction_inventory']) and $data['is_deduction_inventory'] eq 1) or empty($data)}}checked="true"{{/if}} />
					</div>
					<div class="am-form-group">
						<label class="block">上下架<span class="am-form-group-label-tips">可选</span><span class="am-form-group-label-tips">下架后用户不可见</span></label>
						<input name="is_shelves" value="1" type="checkbox" data-off-text="下架" data-on-text="上架" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_shelves']) and $data['is_shelves'] eq 1) or empty($data)}}checked="true"{{/if}} />
					</div>
				</div>
			</div>

			<!-- 商品规格 -->
			<div class="am-panel am-panel-default" id="goods-nav-operations" data-spec-add-max-number="{{:MyC('common_spec_add_max_number', 3, true)}}">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">商品规格<span class="am-form-group-label-tips-must">必填</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                    <div class="am-margin-horizontal-sm">
                    	{{include file="goods/spec" /}}
                    </div>
                </div>
            </div>

			<!-- 商品参数 -->
            <div class="am-panel am-panel-default" id="goods-nav-parameters">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">商品参数<span class="am-form-group-label-tips">选填</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                    <div class="am-margin-horizontal-sm">
						{{include file="public/goodsparamstemplate/tips" /}}
						<!-- 通过配置生成商品参数 -->
						<div class="am-dropdown" id="parameters-quick-container" data-am-dropdown>
							<span class="business-operations-submit am-dropdown-toggle parameters-quick-add">
								<span>快捷操作</span>
								<i class="am-icon-caret-down"></i>
							</span>
							<div class="am-dropdown-content parameters-quick-config">
								<div class="am-margin-bottom-sm">
									<select class="am-radius chosen-select goods-template-params-select" data-placeholder="请选择模板..." data-validation-message="选择商品参数模板">
										{{if !empty($goods_template_list) and is_array($goods_template_list)}}
											<option value="">请选择模板...</option>
											{{foreach $goods_template_list as $v}}
												<option value="{{:urlencode(json_encode($v['config_data'], JSON_UNESCAPED_UNICODE))}}">{{$v.name}}</option>
											{{/foreach}}
										{{/if}}
									</select>
								</div>
								<textarea rows="5" placeholder="粘贴商品参数配置信息"></textarea>
								<button type="button" class="am-btn am-btn-secondary am-btn-xs am-radius am-btn-block am-margin-top-sm">确认</button>
							</div>
						</div>
						<!-- 复制操作 -->
						<span class="business-operations-submit am-margin-left-sm parameters-quick-copy">
							<i class="am-icon-copy"></i>
							<span>复制配置</span>
						</span>
					    <!-- 清空操作 -->
					    <span class="business-operations-submit am-margin-left-sm parameters-quick-remove">
							<i class="am-icon-times"></i>
							<span>清空参数</span>
						</span>

						<!-- 参数表格 -->
						{{include file="public/goodsparamstemplate/table" /}}
					</div>
                </div>
            </div>

			<!-- 相册 -->
			<div class="am-panel am-panel-default" id="goods-nav-photo">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">商品相册<span class="am-form-group-label-tips-must">必传</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                    <div class="am-margin-horizontal-sm">
                    	<div class="am-alert am-alert-warning am-radius" data-am-alert>
	                        <button type="button" class="am-close">&times;</button>
	                        <p>可拖拽图片进行排序，建议图片尺寸一致800*800px、最多30张</p>
	                    </div>
	                    <ul class="plug-file-upload-view goods-photo-view" data-form-name="photo[]" data-max-number="30" data-dialog-type="images">
	                        {{if !empty($data['photo'])}}
	                            {{foreach $data.photo as $v}}
	                                <li>
	                                    <input type="text" name="photo[]" value="{{$v.images_old}}" />
	                                    <img src="{{$v.images}}" />
	                                    <i>×</i>
	                                </li>
	                            {{/foreach}}
	                        {{/if}}
	                    </ul>
	                    <div class="plug-file-upload-submit" data-view-tag="ul.goods-photo-view">+上传相册</div>
                    </div>
                </div>
            </div>

			<!-- 视频 -->
            <div class="am-panel am-panel-default" id="goods-nav-video">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">商品视频<span class="am-form-group-label-tips">选传</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                    <div class="am-margin-horizontal-sm">
	                    <div class="am-alert am-alert-warning am-radius" data-am-alert>
	                        <button type="button" class="am-close">&times;</button>
	                        <p>视频比图文更有具带入感，仅支持 mp4 格式</p>
	                    </div>
	                    <ul class="plug-file-upload-view plug-file-upload-view-video goods-video-view" data-form-name="video" data-max-number="1" data-dialog-type="video">
	                        {{if !empty($data['video'])}}
	                            <li>
	                                <input type="text" name="video" value="{{$data.video}}" />
	                                <video src="{{$data.video}}" controls>your browser does not support the video tag</video>
	                                <i>×</i>
	                            </li>
	                        {{/if}}
	                    </ul>
	                    <div class="plug-file-upload-submit" data-view-tag="ul.goods-video-view">+上传视频</div>
	                </div>
                </div>
            </div>

			<!-- 手机详情 -->
			<div class="am-panel am-panel-default" id="goods-nav-app">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">手机详情<span class="am-form-group-label-tips">选填</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                    <div class="am-margin-horizontal-sm">
                    	<div class="am-alert am-alert-warning am-radius" data-am-alert>
	                        <button type="button" class="am-close">&times;</button>
	                        <p>设置手机详情后、在手机模式下将展示手机详情、比如[小程序、APP]</p>
	                    </div>
						<ul class="content-app-items" data-max-count="10" data-required="1" data-images-name="content_app_images" data-content-name="content_app_text" data-images-text="图片" data-content-text="文本内容" data-delete-text="删除" data-drag-sort-text="拖拽排序">
							{{if !empty($data['content_app'])}}
								{{foreach $data.content_app as $v}}
									<li>
										<div>
											<div class="content-app-left">
												<label class="block">图片</label>
												<ul class="plug-file-upload-view goods-content-app-images-view-{{$v.id}}" data-form-name="content_app_images_{{$v.id}}" data-max-number="1" data-dialog-type="images">
													{{if !empty($v['images'])}}
														<li>
															<input type="text" name="content_app_images_{{$v.id}}" value="{{$v.images_old}}" />
															<img src="{{$v.images}}" />
															<i>×</i>
														</li>
													{{/if}}
												</ul>
												<div class="plug-file-upload-submit" data-view-tag="ul.goods-content-app-images-view-{{$v.id}}">+上传图片</div>
											</div>
											<div class="am-form-group content-app-right fr">
												<label>文本内容</label>
												<textarea rows="5" name="content_app_text_{{$v.id}}" maxlength="105000" class="am-radius" placeholder="文本内容" data-validation-message="文本内容最多 105000 个字符">{{if !empty($v)}}{{$v.content_old|raw}}{{/if}}</textarea>
											</div>
										</div>
										<i class="c-p am-text-xs cr-red content-app-items-rem-sub">删除</i>
										<i class="c-m am-text-xs drag-sort-submit">拖拽排序</i>
									</li>
								{{/foreach}}
							{{/if}}
						</ul>
						<span class="business-operations-submit content-app-items-add-sub">+添加手机详情</span>
					</div>
				</div>
			</div>

			<!-- 电脑详情 -->
			<div class="am-panel am-panel-default" id="goods-nav-web">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">电脑详情<span class="am-form-group-label-tips-must">必填</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                	<div class="am-margin-horizontal-sm">
                        <textarea class="am-radius am-validate" name="content_web" maxlength="105000" id="editor-tag" data-validation-message="电脑端详情内容最多 105000 个字符" style="width: 100%;">{{if !empty($data['content_web'])}}{{$data.content_web}}{{/if}}</textarea>
                    </div>
                </div>
            </div>

			<!-- 虚拟信息 -->
            <div class="am-panel am-panel-default" id="goods-nav-fictitious">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">虚拟信息<span class="am-form-group-label-tips">选填</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                	<div class="am-margin-horizontal-sm">
                        <script type="text/plain" id="goods-fictitious-container" name="fictitious_goods_value">{{if !empty($data['fictitious_goods_value'])}}{{$data.fictitious_goods_value|raw}}{{/if}}</script>
                    </div>
                </div>
            </div>

			<!-- 扩展数据 -->
            <div class="am-panel am-panel-default" id="goods-nav-extends">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">扩展数据<span class="am-form-group-label-tips">该区域为插件扩展数据，请按照插件文档填写相应的值</span></h3>
                </div>
                <div class="am-panel-bd business-form-group">
                	<div class="am-margin-horizontal-sm">
	                	<!-- 插件扩展数据 start -->
						{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true}}
			                <div class="plugins-tag">
			                    <span>plugins_view_admin_goods_save</span>
			                </div>
			            {{/if}}
						{{if !empty($plugins_view_admin_goods_save_data) and is_array($plugins_view_admin_goods_save_data) and !empty(array_filter($plugins_view_admin_goods_save_data))}}
							{{foreach $plugins_view_admin_goods_save_data as $hook}}
			                    {{if is_string($hook) or is_int($hook)}}
			                        {{$hook|raw}}
			                    {{/if}}
			                {{/foreach}}
						{{else /}}
							{{include file="public/not_data" /}}
						{{/if}}
						<!-- 插件扩展数据 end -->
					</div>
                </div>
            </div>

            <!-- SEO信息 -->
            <div class="am-panel am-panel-default" id="goods-nav-seo">
                <div class="am-panel-hd">
                    <h3 class="am-panel-title">SEO信息<span class="am-form-group-label-tips">选填</span></h3>
                </div>
                <div class="am-panel-bd am-padding-vertical-xs">
                    {{include file="lib/seo" /}}
                </div>
            </div>

			<div class="am-form-group am-form-group-refreshing am-margin-top-lg am-padding-left-0">
				<input type="hidden" name="id" {{if isset($data) and !empty($data['id']) and (!isset($is_copy) or $is_copy neq 1)}} value="{{$data.id}}"{{/if}} />
				<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block" data-am-loading="{loadingText:'处理中...'}">保存</button>
			</div>
		</form>
        <!-- form end -->
	</div>
</div>
<!-- right content end  -->

<!-- 规格扩展数据弹层 -->
{{include file="goods/spec_extends" /}}

<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->

<script type="text/javascript">
// 规格扩展返回处理
function SpecificationsExtendsBack(data)
{
	var $extends_popup = $('#specifications-extends-popup');
    $('.specifications-table').find($extends_popup.attr('data-line-extend')).find('.line-extend-input').val(JSON.stringify(data));
    $extends_popup.modal('close');
}
</script>