mitao
2024-07-08 022a7ff7abf82cd2546e18071ade5228b4e2339f
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
/**
 * 初始化商品信息详情对话框
 */
var MallGoodsInfoDlg = {
    mallGoodsInfoData : {},
    validFields: {
        goodsName: Feng.def_valid_info( true, null, null, null, {
            stringLength: {
                max: 50,
                message: "最多支持50个字符"
            }
        }), // 不能为空
        // classifyIdOne: Feng.def_valid_info( true), // 不能为空
        // goodsImage: Feng.def_valid_info( true), // 不能为空
        // introImage: Feng.def_valid_info( true), // 不能为空
        // introH5: Feng.def_valid_info( true) // 不能为空
    }
};
 
/**
 * 清除数据
 */
MallGoodsInfoDlg.clearData = function() {
    this.mallGoodsInfoData = {};
};
 
/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MallGoodsInfoDlg.set = function(key, val) {
    this.mallGoodsInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
};
 
/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MallGoodsInfoDlg.get = function(key) {
    return $("#" + key).val();
};
 
/**
 * 关闭此对话框
 */
MallGoodsInfoDlg.close = function() {
    parent.layer.close(window.parent.MallGoods.layerIndex);
};
 
/**
 * 收集数据
 */
MallGoodsInfoDlg.collectData = function() {
    this
    .set('id')
    .set('groupType')
    .set('goodsName')
    .set('goodsTitle')
    .set('goodsNo')
    .set('price')
    .set('priceSale')
    .set('priceMember')
    .set('stock')
    .set('state')
    .set('tagIds', Feng.get_chosen_selected( "#tagIds"))
    .set('classifyIdOne')
    .set('classifyIdTwo')
    .set('goodsImage')
    .set('introImage')
    .set('purchaseH5', Feng.getEditorContent(MallGoodsInfoDlg.purchaseH5))
    .set('introH5', Feng.getEditorContent(MallGoodsInfoDlg.introH5))
    ;
};
function isNull ( val) { return val == undefined || val == null || val == ""; }
 
/**
 * 遍历循环规格表格的所有列input元素值,拼接字符串
 */
MallGoodsInfoDlg.getSpecGroup = function() {
    // 定义规格组合值
    let specGroup = [];
    // 遍历循环规格表格的所有列
    $(".specGroup").each(function (i, item) {
        // 遍历循环拿到列中所有input元素值
        let inputSpec = $(item).find(".inputSpec");
        specGroup[i] = {"spec_ids": inputSpec[0].value, "grep_name": inputSpec[1].value, "stock": inputSpec[2].value, "priceMerchant": inputSpec[3].value}
    });
    return specGroup;
}
 
MallGoodsInfoDlg.getGoodsSet = function() {
    // 定义规格组合值
    let set = {
        "buyCoef": $("#buyCoef").val(),
        "v3BuyCoef": $("#v3BuyCoef").val(),
        "v3BrokerageCoef": $("#v3BrokerageCoef").val(),
        "v4BuyCoef": $("#v4BuyCoef").val(),
        "v4BrokerageCoef": $("#v4BrokerageCoef").val(),
        "v5BuyCoef": $("#v5BuyCoef").val(),
        "v5BrokerageCoef": $("#v5BrokerageCoef").val(),
    }
    return set;
}
 
MallGoodsInfoDlg.clear_move_table = function() {
    this.moveTable && this.moveTable.clear();
    this.specs_item = {};
}
 
 
MallGoodsInfoDlg.chooseGoodsGroupSpec = function() {
    $.ajax({
        url : Feng.ctxPath + "/mallGoodsGroup/groupSpecByIdsList",
        type : "get",
        data : {"ids": Feng.getMultipleSelectVal("goodsIds")},
        dataType : "json",
        success : function (list) {
            let goodsSelectTbodyStr = '';
            $.each(list, function(i, item) {
                goodsSelectTbodyStr += "<tr class='specGroup'>"
                    + "<td>"
                    + "<input class='inputSpec' type='hidden' value='" + item.id + "'>"
                    + "<input class='inputSpec' type='hidden' value='" + item.specName + "'>"
                    + item.specName + "</td>"
                    + "<td>" + item.goodsNames + "</td>"
                    + "<td style='text-align: center;'><input class='inputSpec' type='hidden' value='" + item.stock + "'>" + item.stock + "</td>"
                    + "<td style='text-align: center;'>" + item.provinceName + "</td>"
                    + "<td style='text-align: center;'><input class='inputSpec' type='number' value='" + item.priceMerchant + "'></td>"
                    + "</tr>"
            });
 
            $("#goodsSelectTbody").html(goodsSelectTbodyStr);
        }
    });
}
MallGoodsInfoDlg.chooseGoodsGroupSpecDetail = function() {
    $.ajax({
        url : Feng.ctxPath + "/mallGoodsGroup/groupSpecByIdsList",
        type : "get",
        data : {"ids": Feng.getMultipleSelectVal("goodsIds")},
        dataType : "json",
        success : function (list) {
            let goodsSelectTbodyStr = '';
            $.each(list, function(i, item) {
                goodsSelectTbodyStr += "<tr class='specGroup'>"
                    + "<td>"
                    + "<input class='inputSpec' type='hidden' value='" + item.id + "'>"
                    + "<input class='inputSpec' type='hidden' value='" + item.specName + "'>"
                    + item.specName + "</td>"
                    + "<td>" + item.goodsNames + "</td>"
                    + "<td>" + item.totalPrice + "</td>"
                    + "<td style='text-align: center;'><input class='inputSpec' type='hidden' value='" + item.stock + "'>" + item.stock + "</td>"
                    + "<td style='text-align: center;'>" + item.provinceName + "</td>"
                    + "<td style='text-align: center;'><input class='inputSpec' type='number' value='" + item.priceMerchant + "'></td>"
                    + "</tr>"
            });
 
            $("#goodsSelectTbody").html(goodsSelectTbodyStr);
        }
    });
}
 
/**
 * 提交添加
 */
MallGoodsInfoDlg.addSubmit = function() {
    this.clearData();
    this.collectData();
 
    if ( !Feng.check_form( "formId")) { return; }
 
    this.mallGoodsInfoData.goodsSkusJson = JSON.stringify(MallGoodsInfoDlg.getSpecGroup());
    this.mallGoodsInfoData.goodsSetJson = JSON.stringify(MallGoodsInfoDlg.getGoodsSet());
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/mallGoodsGroup/add", function(data){
        if(data.code == 200){
            Feng.success("添加成功!");
            window.parent.MallGoods.table.refresh();
            MallGoodsInfoDlg.close();
        } else {
            Feng.error("添加失败!" + data.message);
        }
    },function(){
        Feng.error("添加失败!");
    });
    ajax.set(this.mallGoodsInfoData);
    ajax.start();
};
 
/**
 * 提交修改
 */
MallGoodsInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();
 
    if ( !Feng.check_form( "formId")) { return; }
 
    this.mallGoodsInfoData.goodsSkusJson = JSON.stringify(MallGoodsInfoDlg.getSpecGroup());
    this.mallGoodsInfoData.goodsSetJson = JSON.stringify(MallGoodsInfoDlg.getGoodsSet());
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/mallGoodsGroup/update", function(data){
        if(data.code == 200){
            Feng.success("修改成功!");
            window.parent.MallGoods.table.refresh();
            MallGoodsInfoDlg.close();
        } else {
            Feng.error("修改失败!" + data.message);
        }
    },function(){
        Feng.error("修改失败!");
    });
    ajax.set(this.mallGoodsInfoData);
    ajax.start();
};
 
MallGoodsInfoDlg.editBuyCountSubmit = function() {
    // 提交信息
    var ajax = new $ax(Feng.ctxPath + "/mallGoodsGroup/updateBuyCount", function(data){
        if(data.code == 200){
            Feng.success("修改成功!");
            window.parent.MallGoods.table.refresh();
            MallGoodsInfoDlg.close();
        } else {
            Feng.error("修改失败!" + data.message);
        }
    },function(){
        Feng.error("修改失败!");
    });
    ajax.set("mallGoodsId", $("#id").val());
    ajax.set("buyCount", $("#buyCount").val());
    ajax.start();
};
 
$(function() {
    $("#tagIds").val((($("#tagIds").data("value")||"")+"").split(","));
 
    Feng.initValidator( "formId", MallGoodsInfoDlg.validFields);
});