mitao
2024-06-06 3d2b51ea4520533de5e78f88dddf5b5c7dce4247
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
265
266
267
268
269
270
271
272
273
274
275
/**
 * 初始化商品信息详情对话框
 */
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('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,"price_sale": inputSpec[3].value,"price_member": inputSpec[4].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.add_specs = function () {
    let specsItems = [];
    var query_item = {
        oneClassifyId: this.get( "classifyIdOne"),
        selectedItems: specsItems,
    };
    $(".specGroup").each(function (i, item) {
        // 遍历循环拿到列中所有input元素值
        let inputSpec = $(item).find(".inputSpec");
        specsItems[i] = inputSpec[1].value
    });
    console.log(specsItems)
    if ( !query_item.oneClassifyId) {
        return Feng.error( "请先选择分类!")
    }
    this.layerIndex = layer.open({
        type: 2,
        title: '添加规格',
        area: ['45%', '45%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.url_params( Feng.ctxPath + '/mallGoods/getGoodsSpecs', query_item)
    });
}
 
MallGoodsInfoDlg.close_specs = function(specGroup) {
    // 生成规格表格
    MallGoodsInfoDlg.setSpecTable(specGroup);
    this.layerIndex && layer.close( this.layerIndex);
}
 
MallGoodsInfoDlg.initSpecData = function() {
    $.ajax({
        url : Feng.ctxPath + "/mallGoods/getGoodsSpecData",
        type : "get",
        data : {"goodsId": $("#id").val()},
        dataType : "json",
        success : function (list) {
            // 生成规格表格
            MallGoodsInfoDlg.setSpecTable(list);
        }
    });
}
function delTr(buttonElement) {
    // 获取按钮所在的<tr>元素
    var row = buttonElement.closest('tr');
 
    // 从DOM中移除该<tr>元素
    row.parentNode.removeChild(row);
}
/**
 * 生成规格表格
 * @param specGroup
 */
MallGoodsInfoDlg.setSpecTable = function(specGroup) {
    // specGroup = [{"id":1,"grepName":"规格1","stock":1, priceMember: 20, priceSale: 10},{"id":2,"grepName":"规格2","stock":2, priceMember: 20, priceSale: 10}]
    // 商品分类
    let className = $('#classifyIdOne option:selected').text();
    let thStr = "<thead><tr><th>规格名称</th><th>商品分类</th><th>商品库存</th><th>美天销售价</th><th>会员价</th><th>操作</th></tr></thead><tbody></tbody>";
    if (!$("#specsTable").html()){
        $("#specsTable").html(thStr);
    }
    let tdStr = '';
    for (let i = 0; i < specGroup.length; i++) {
        let item = specGroup[i];
        $(item).find(".inputSpec").each(function (ii, iitem) {
            specGroup += (iitem.value == "" ? "0" : iitem.value) + "__";
        });
 
        tdStr = "<tr class='specGroup'>" +
            "<td>" +
            "<input type='hidden' class='inputSpec' value='" + item.id + "'>" +
            "<input type='hidden' class='inputSpec' value='" + item.grepName + "'>" +
            item.grepName +
            "</td>" +
            "<td>" + (item.classifyName != "" ? item.classifyName : className) + "</td>" +
            "<td><input type='text' class='inputSpec' value='" + item.stock + "' style='width: 92px'></td>" +
            "<td><input type='text' class='inputSpec' value='" + item.priceSale + "' style='width: 92px'></td>" +
            "<td><input type='text' class='inputSpec' value='" + item.priceMember + "' style='width: 92px'></td>" +
            '<td><button type="button" class="btn btn-outline btn-danger btn-xs" onclick="delTr(this)" value="1">删除</button></td>' +
            "</tr>";
        // 生成规格表格
        $("#specsTable tbody").append(tdStr)
    }
}
/**
 * 提交添加
 */
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 + "/mallGoods/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 + "/mallGoods/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 + "/mallGoods/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);
});