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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * 管理初始化
 */
var TCoupon = {
    id: "TCouponTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
TCoupon.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '联系方式', field: 'phone', visible: true, align: 'center', valign: 'middle',
        },
        {title: '使用状态', field: 'status', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                return {2: "已使用", 1: "未使用"}[value]
            }},
    ];
};
 
/**
 * 检查是否选中
 */
TCoupon.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else{
        TCoupon.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加
 */
TCoupon.openAdd = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tCouponManage/coupon_add'
    });
    this.layerIndex = index;
};
 
 
/**
 * 点击编辑
 */
TCoupon.openChange = function () {
    if (this.check()){
        let id = TCoupon.seItem.id
        let name = TCoupon.seItem.name
        let quantityIssued = TCoupon.seItem.quantityIssued
        let pickUpQuantity = TCoupon.seItem.pickUpQuantity
        let illustrate = TCoupon.seItem.illustrate
        let hasPickQty = TCoupon.seItem.hasPickQty
        var index = layer.load(1,{
            type: 1
            , title: '编辑优惠券'
            , area: ['50%', '50%']
            , offset: 'auto' //具体配置参考:http://www.layui.com/doc/modules/layer.html#offset
            , id: 'layerDemo' //防止重复弹出cge
            , content: '<div class="form-horizontal">' +
                '                    <div class="col-sm-11" >' +
                '                    <div class="col-sm-11">' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">优惠券名称:</label>\n' +
                '                         <div class="col-sm-9">\n' +
                '                                  <label class="form-control"  id="name" >'+name+'</label> '+
                '                          </div>\n' +
                '                        </div>\n'+
            '                        <div class="form-group">\n' +
                    '                            <label class="col-sm-3 control-label">发放数量:</label>\n' +
                '                         <div class="col-sm-9">\n' +
                '                                  <input class="form-control"  id="num" value="'+quantityIssued+'" > '+
                '                          </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">限领数量:</label>\n' +
                '                         <div class="col-sm-9">\n' +
                '                                  <input class="form-control"  id="num1" value="'+pickUpQuantity+'" > '+
                '                          </div>\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <label class="col-sm-3 control-label">优惠券说明:</label>\n' +
                '                         <div class="col-sm-9">\n' +
                '                                  <textarea class="form-control"  id="text"  >'+illustrate+'</textarea> '+
                '                          </div>\n' +
                '                        </div>\n' +
                '                       </div>' +
                '                   </div>' +
                '</div>'
            , btn: ['关闭', '保存']
            , btnAlign: 'c' //按钮居中
            , shade:  0.5 //不显示遮罩
            ,load:1
            , yes: function () {
                layer.closeAll();
            },
            btn2:function () {
                let num = $("#num").val()
                if(num==''){
                    Feng.info("请输入发放数量")
                    return false;
                }
                let num1 = $("#num1").val()
                if(num1==''){
                    Feng.info("请输入限领数量")
                    return false;
                }
                let text = $("#text").val()
                if(text==''){
                    Feng.info("请输入优惠券说明")
                    return false;
                }
 
                if(num<hasPickQty){
                    Feng.info("发放数量不能小于已领取数量")
                    return false;
                }
                var ajax = new $ax(Feng.ctxPath + "/tCouponManage/update", function (data) {
                    if (data.code == 200) {
                        Feng.success("操作成功!");
                        window.location.reload();
                        window.parent.layer.closeAll();
                    } else if(data=="repeat"){
                        window.location.reload();
                        window.parent.layer.closeAll();
                        Feng.error("请勿重复操作");
                    }else {
                        return  Feng.error(data.msg);
                    }
                }, function (data) {
                    Feng.error("操作失败!")
                    window.location.reload();
                    window.parent.layer.closeAll();
                    return   Feng.error("操作失败!");
                });
                ajax.set("id", id);
                ajax.set("num", num);
                ajax.set("num1", num1);
                ajax.set("text", text);
                ajax.start();
                layer.closeAll();
            }
        });
 
        this.layerIndex = index;
    }
};
 
 
 
/**
 * 上架
 */
 
 
/**
 * 下架
 */
TCoupon.offShelf = function () {
 
 
};
 
 
/**
 * 打开查看详情
 */
TCoupon.openDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCouponManage/coupon_detail/' + TCoupon.seItem.id
        });
        this.layerIndex = index;
    }
};
 
 
 
 
/**
 * 打开领取记录
 */
TCoupon.openCollectionRecord = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tCouponManage/coupon_record/' + TCoupon.seItem.id
        });
        this.layerIndex = index;
    }
};
TCoupon.updateType = function () {
    if (this.check()) {
        if(TCoupon.seItem.status==2){
            Feng.info("该券已核销")
            return false;
        }
        var ajax = new $ax(Feng.ctxPath + "/tCouponManage/updateType", function(data){
            if(data.code==200){
                Feng.success("核销成功!")
                TCoupon.table.refresh();
            }
        },function(data){
            Feng.error("核销失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id",TCoupon.seItem.id)
        ajax.start();
    }
};
 
 
 
/**
 * 查询列表
 */
TCoupon.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['type'] = $("#type").val();
    queryData['phone'] = $("#state").val();
    TCoupon.table.refresh({query: queryData});
};
 
 
/**
 * 重置搜索
 */
TCoupon.resetSearch = function () {
    $("#name").val('');
    $("#type").val('');
    $("#phone").val('');
    TCoupon.search();
};
 
$(function () {
    var defaultColunms = TCoupon.initColumn();
    var table = new BSTable(TCoupon.id, "/tCouponManage/listRecord?id="+$("#id").val(), defaultColunms);
    table.setPaginationType("client");
    TCoupon.table = table.init();
});