goods.js
10.7 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'goods/index' + location.search,
add_url: 'goods/add',
edit_url: 'goods/edit',
del_url: 'goods/del',
multi_url: 'goods/multi',
import_url: 'goods/import',
table: 'goods',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'goods_images', title: __('Goods_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'goods_name', title: __('Goods_name')},
{field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
{field: 'sale_num', title: __('Sale_num')},
{field: 'issale', title: __('Issale'), searchList: {"0":__('Issale 0'),"1":__('Issale 1')}, formatter: Table.api.formatter.normal},
{field: 'ismember', title: __('Ismember'), searchList: {"0":__('Ismember 0'),"1":__('Ismember 1')}, formatter: Table.api.formatter.normal},
{field: 'ishot', title: __('Ishot'), searchList: {"0":__('Ishot 0'),"1":__('Ishot 1')}, formatter: Table.api.formatter.normal},
{field: 'ismake', title: __('Ismake'), searchList: {"0":__('Ismake 0'),"1":__('Ismake 1')}, formatter: Table.api.formatter.normal},
{field: 'buyer_images', title: __('Buyer_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'detail',
title: __('模特款'),
classname: 'btn btn-xs btn-warning btn-dialog',
icon: 'fa fa-file',
url: 'goods/style?goods_id={id}',
visible: function(row){
if(row.ismake == '1'){
return true;
}
}
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
style: function () {
Controller.api.bindevent();
setTimeout(function () {
$("#c-style_template_id").trigger("change");
}, 100);
},
api: {
bindevent: function () {
var goods_style = Config.goods_style;
var hidden_style_list = [];
$(document).on("change", "#c-style_template_id", function () {
Fast.api.ajax({
url:'goods/styleList',
data:{
style_template_id:$(this).val()
}
}, function(data, ret){
if(ret.code == 1){
var list = ret.data.list;
var html = '<div class="display_mode_1">';
// 一级风格
html += style_list(list);
html += '<div>';
$('.display_mode_1').remove();
$('.layer-footer').before(html);
// 绑定上传事件
Form.events.plupload();
Form.events.faselect();
// 显示隐藏风格
$("input:checked[type=radio]").trigger("change");
}
return false;
}, function(data, ret){
//失败的回调
alert(ret.msg);
return false;
});
});
// 选项下风格
$(document).on("change", "input[type=radio]", function () {
var style_value_id = $(this).val();
var list = hidden_style_list[style_value_id];
$(this).parent().parent().parent().parent('.form-group').next('.display_mode_2').remove();
if(list.length > 0){
var html = '<div class="display_mode_2">';
html += style_list(list);
html += '<div>';
$(this).parent().parent().parent().parent('.form-group').after(html);
// 绑定上传事件
Form.events.plupload();
Form.events.faselect();
}
});
// 风格
function style_list(list){
var html = '';
// 一级风格
$.each(list,function(index,style){
html += '<div class="form-group">'+
'<label class="control-label col-xs-12 col-sm-2">'+style.style_name+':</label>'+
'<div class="col-xs-12 col-sm-8">'+
style_value_list(index,style);
// 一级风格下二级风格
if(style.two_style_list.length > 0){
$.each(style.two_style_list,function(index,style_s){
html += '<div class="form-group">'+
'<label class="control-label col-xs-12 col-sm-2">'+style_s.style_name+':</label>'+
'<div class="col-xs-12 col-sm-8">'+
style_value_list(index,style_s)+
'</div>'+
'</div>';
})
}
html += '</div>'+
'</div>';
})
return html;
}
// 选项
function style_value_list(index,style){
var html = '';
// 风格下选项
if(style.style_value_list.length > 0){
html += '<div class="radio">';
$.each(style.style_value_list,function(index,style_o){
hidden_style_list[style_o.id] = style_o.style_list;
var img = style_o.style_value_image == '' ? '/assets/img/qrcode.png' : style_o.style_value_image;
var checked = goods_style[style_o.style_id] == style_o.id ? 'checked' : index == 0 ? 'checked' : '';
html += '<label for="'+style_o.id+'" style="border:1px solid #f1f4f6">'+
'<input id="'+style_o.id+'" '+checked+' name="row[goods_style]['+style_o.style_id+']" type="radio" value="'+style_o.id+'">'+
'<img width="100px" src="'+img+'">'+
'<p style="text-align:center">'+style_o.style_value_name+'</p>'+
'</label>';
})
html += '</div>';
}
// 风格下文本框
if(style.style_type == '2'){
var val = goods_style[style.id] == undefined ? '' : goods_style[style.id];
html += '<input id="c-'+style.id+'" data-rule="required" class="form-control" name="row[goods_style]['+style.id+']" type="text" value="'+val+'">';
}
// 风格下上传图片
if(style.style_type == '3'){
var val = goods_style[style.id] == undefined ? '' : goods_style[style.id];
html += '<div class="input-group">'+
'<input id="c-'+style.id+'" data-rule="required" class="form-control" size="50" name="row[goods_style]['+style.id+']" type="text" value="'+val+'">'+
'<div class="input-group-addon no-border no-padding">'+
'<span><button type="button" id="plupload-'+style.id+'" class="btn btn-danger plupload" data-input-id="c-'+style.id+'" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-'+style.id+'"><i class="fa fa-upload"></i> 上传</button></span>'+
'<span><button type="button" id="fachoose-'+style.id+'" class="btn btn-primary fachoose" data-input-id="c-'+style.id+'" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> 选择</button></span>'+
'</div>'+
'<span class="msg-box n-right" for="c-'+style.id+'"></span>'+
'</div>'+
'<ul class="row list-inline plupload-preview" id="p-'+style.id+'"></ul>';
}
return html;
}
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});