goods_spec_edit.html
6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{echo:JS::import('validator');}
{echo:JS::import('form');}
{echo:JS::import('dialog?skin=brief');}
{echo:JS::import('dialogtools');}
<h1 class="page_title">规格编辑</h1>
<div id="obj_form" class="form2">
<form action="{url:/goods/goods_spec_save}" method="post" >
{if:isset($id)}
<input type="hidden" name="id" value="{$id}">
{/if}
<dl class="lineD">
<dt>名称:</dt>
<dd>
<input name="name" type="text" pattern="required" value="{$name}" alt="名称不能为空">
<label>规格名称(如:颜色)</label>
</dd>
</dl>
<dl class="lineD">
<dt>类型:</dt>
<dd>
<input name="type" type="radio" checked="checked" value="1">
<label>文字</label>
<input name="type" type="radio" value="2">
<label>图片</label>
</dd>
</dl>
<dl class="lineD">
<dt>备注:</dt>
<dd>
<input name="note" type="text" pattern="required" value="{$note}" alt="不能为空,用于标注">
<label>备注(一般说明是关于什么的,如:服装)</label>
</dd>
</dl>
<dl class="lineD">
<dt></dt>
<dd>
<button class="button" id="addSpecButton" >添加规格值</button>
</dd>
</dl>
<div>
<table class="default" id="spec">
<tr>
<th>规格值名称</th>
<th>规格图片</th>
<th>操作</th>
</tr>
{if:isset($id)}
{query:name=spec_value where= spec_id eq $id order=sort}
<tr>
<td>
<input type="hidden" name="value_id[]" value="{$item['id']}">
<input type="text" name="value[]" value="{$item['name']}" pattern="required" />
</td>
<td>
<input type="text" name="img[]" readonly="readonly" value="{$item['img']}" >
<button class="button select_button" value="选择">选择</button>
</td>
<td class="btn_min">
<a href="javascript:;" class="icon-arrow-up-2">上升</a>
<a href="javascript:;" class="icon-arrow-down-2">下降</a>
<a href="javascript:;" class="icon-remove-2" >删除</a>
</td>
</tr>
{/query}
{else:}
<tr>
<td>
<input type="hidden" name="value_id[]" value="0">
<input type="text" name="value[]" pattern="required" />
</td>
<td>
<input type="text" name="img[]" readonly="readonly" >
<button class="button select_button" value="选择">选择</button>
</td>
<td class="btn_min">
<a href="javascript:;" class="icon-arrow-up-2">上升</a>
<a href="javascript:;" class="icon-arrow-down-2">下降</a>
<a href="javascript:;" class="icon-remove-2" >删除</a>
</td>
</tr>
{/if}
</table>
</div>
<div style="text-align:center">
<input type="submit" value="提交" class="button">
<input type="reset" value="重置" class="button"></div>
</form>
</div>
<script type="text/javascript">
var form = new Form();
form.setValue('parent_id','{$parent_id}');
form.setValue('type','{$type}');
$("#addSpecButton").on("click",function(){
if(2==$("input[name='type']:checked").val()){
$("#spec").append('<tr> <td><input type="hidden" name="value_id[]" value="0"><input type="text" name="value[]" pattern="required" /></td> <td><input type="text" name="img[]" readonly="readonly" > <button class="button select_button">选择</button></td> <td class="btn_min"><a href="javascript:;" class="icon-arrow-up-2">上升</a><a href="javascript:;" class="icon-arrow-down-2">下降</a><a href="javascript:;" class="icon-remove-2">删除</a></td></tr>');
}else{
$("#spec").append('<tr> <td><input type="hidden" name="value_id[]" value="0"><input type="text" name="value[]" pattern="required" /></td> <td><input type="text" name="img[]" readonly="readonly" disabled="disabled"> <button class="button select_button" disabled="disabled">选择</button></td> <td class="btn_min"><a href="javascript:;" class="icon-arrow-up-2">上升</a><a href="javascript:;" class="icon-arrow-down-2">下降</a><a href="javascript:;" class="icon-remove-2">删除</a></td></tr>');
}
bindEvent();
return false;
})
// 绑定规格类型点击事件
$("input[name='type']").on("click",changeType);
//改变规格的类型
function changeType(){
var select_type = $("input[name='type']:checked");
if(select_type.val()==1){
$("input[name='img[]']").prop("disabled", true);
$(".select_button").prop("disabled", true);
}
else{
$("input[name='img[]']").prop("disabled", false);
$(".select_button").prop("disabled", false);
}
}
changeType();
bindEvent();
//操作按钮事件绑定
function bindEvent(){
$(".icon-arrow-down-2").off();
$(".icon-arrow-up-2").off();
$(".icon-remove-2").off();
$(".select_button").off();
$(".icon-arrow-down-2").on("click",function(){
var current_tr = $(this).parent().parent();
current_tr.insertAfter(current_tr.next());
});
$(".icon-arrow-up-2").on("click",function(){
var current_tr = $(this).parent().parent();
if(current_tr.prev().prev().html()!=null)current_tr.insertBefore(current_tr.prev());
});
$(".icon-remove-2").on("click",function(){
if($("input[name='value[]']").length>1)$(this).parent().parent().remove();
else alert('必须至少保留一个规格值');
});
$(".select_button").each(function(i){
var num = i;
$(this).on("click",function(){
uploadFile(num);
return false;
});
});
}
function uploadFile(num){
art.dialog.data('num', num);
art.dialog.open('{url:/admin/photoshop?type=1}',{id:'upimg_dialog',title:'选择图片',width:613,height:380});
}
function setImg(value){
var num = art.dialog.data('num');
$("input[name='img[]']:eq("+num+")").val(value);
art.dialog({id:'upimg_dialog'}).close();
}
</script>