puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
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
200
201
202
/**
 * 商品管理管理初始化
 */
var TIntegralGoods = {
    id: "TIntegralGoodsTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
var language =$("#language").val()
/**
 * 初始化表格的列
 */
TIntegralGoods.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: language==1?'添加时间':(language==2?'Add Time':'Tambahkan waktu'), field: 'insertTime', visible: true, align: 'center', valign: 'middle',width:'10%',
            formatter: function (value, row) {
                var btn = "";
                if(row.insertTime != '' && row.insertTime != null) {
                    var time = row.insertTime.replace(" ",'<br>');
                    btn = ['<p class="toolTip" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;" title="' + row.insertTime + '" onfocus="TUser.tooltip()">' + time + '</p>']
                }
                return btn;
            }
        },
        {title: '商品名称', field: 'name', visible: true, align: 'center', valign: 'middle',width:'30%',
            formatter: function (value, row) {
                var btn = "";
                if(row.name != '' && row.name != null) {
                    btn = ['<p class="toolTip" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;" title="' + row.name + '" onfocus="TUser.tooltip()">' + row.name + '</p>']
                }
                return btn;
            }
        },
        {title: '商品图片', field: 'imgUrl', visible: true, align: 'center', valign: 'middle',width:'20%',
            formatter: function (value, row) {
                if (row.imgUrl == null || row.imgUrl == '') {
                    return '<a class = "view"  href="javascript:void(0)"><img style="width: 60px;height:60px;" src="' + Feng.ctxPath + '/static/img/NoPIC.png" /></a>';
                } else {
                    return '<a class = "view"  href="javascript:void(0)"><img style="width: 100px;height:60px;" src="' + row.imgUrl + '" /></a>';
                }
            },
            events: 'operateEvents'
        },
        {title: '兑换积分', field: 'integral', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row) {
                var btn = "";
                if(row.integral != '' && row.integral != null) {
                    btn = ['<p class="toolTip" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;" title="' + row.integral + '" onfocus="TUser.tooltip()">' + row.integral + '</p>']
                }
                return btn;
            }
        },
        {title:language==1?'状态':(language==2?'State':'Status'), field: 'state', visible: true, align: 'center', valign: 'middle',width:'12%',
            formatter: function (value, row) {
                var btn = "";
                if(row.state != '' && row.state != null) {
                    if (row.state == 1){
                        btn = ['<p class="toolTip" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;" title="正常" onfocus="TUser.tooltip()">正常</p>']
                    } else if (row.state == 2){
                        btn = ['<p class="toolTip" style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;color: red;" title="已下架" onfocus="TUser.tooltip()">已下架</p>']
                    }
                }
                return btn;
            }
        }
    ];
};
 
/**
 * 检查是否选中
 */
TIntegralGoods.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else{
        TIntegralGoods.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加商品管理
 */
TIntegralGoods.openAddTIntegralGoods = function () {
    var index = layer.open({
        type: 2,
        title: language==1?'添加':(language==2?'Add':'Tambahkan'),
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tIntegralGoods/tIntegralGoods_add'
    });
    this.layerIndex = index;
};
 
/**
 * 打开查看商品管理详情
 */
TIntegralGoods.openTIntegralGoodsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: language==1?'编辑':(language==2?'Edit':'Edit'),
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tIntegralGoods/tIntegralGoods_update/' + TIntegralGoods.seItem.id
        });
        this.layerIndex = index;
    }
};
 
/**
 * 操作商品管理
 * type 1=上架 2=下架 3=删除
 */
TIntegralGoods.opt = function (type) {
    if (this.check()) {
        var name = TIntegralGoods.seItem.name;
        if (name == "" || name == null || name == undefined) {
            name = "该积分商品";
        } else {
            name = "【" + name + "】";
        }
        var str = "";
        var text = "请谨慎操作!";
        var title = "请谨慎操作!";
        if (1 == type){
            str = "上架";
            title = "您是否确认上架"+name+"?";
        }else if (2 == type){
            str = "下架";
            title = "您是否确认下架"+name+"?";
        }else if (3 == type){
            str = "删除";
            title = "您是否确认删除"+name+"?";
            text = "请谨慎操作,删除后数据无法恢复!";
        }
        if(1 == type){
            if (TIntegralGoods.seItem.state != 2) {
                swal("上架失败", "【已下架】状态下才能执行此操作", "warning");
                return;
            }
        }
        if (2 == type){
            if (TIntegralGoods.seItem.state != 1){
                swal("下架失败", "【正常】状态下才能执行此操作", "warning");
                return;
            }
        }
 
        swal({
            title: title,
            text: text,
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: str,
            closeOnConfirm: true
        }, function () {
            var ajax = new $ax(Feng.ctxPath + "/tIntegralGoods/opt", function (data) {
                swal(str+"成功", "您已经"+str+"了" + name + "。", "success");
                TIntegralGoods.table.refresh();
            }, function (data) {
                swal(str+"失败", data.responseJSON.message + "!", "warning");
            });
            ajax.set("tIntegralGoodsId",TIntegralGoods.seItem.id);
            ajax.set("optType", type);
            ajax.start();
        });
    }
};
 
/**
 * 查询商品管理列表
 */
TIntegralGoods.search = function () {
    var queryData = {};
    queryData['insertTime'] = $("#insertTime").val();
    queryData['name'] = $("#name").val();
    queryData['state'] = $("#state").val();
    TIntegralGoods.table.refresh({query: queryData});
};
 
TIntegralGoods.resetSearch = function () {
    $("#insertTime").val("");
    $("#name").val("");
    $("#state").val("");
    TIntegralGoods.search();
};
 
$(function () {
    var defaultColunms = TIntegralGoods.initColumn();
    var table = new BSTable(TIntegralGoods.id, "/tIntegralGoods/list", defaultColunms);
    table.setPaginationType("server");
    TIntegralGoods.table = table.init();
});