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
/**
 * 初始化规格属性详情对话框
 */
var MallGoodsSpecInfoDlg = {
    mallGoodsSpecInfoData : {},
    deleteSpecValueIds: '',
    validFields: {
        specName: Feng.def_valid_info( true, null, null, null, {
            stringLength: {
                max: 20,
                message: "最多支持10个字"
            }
        }), // 不能为空
        classifyIdOne: Feng.def_valid_info( true), // 不能为空
        // classifyIdTwo: Feng.def_valid_info( true), // 不能为空
    }
};
 
/**
 * 清除数据
 */
MallGoodsSpecInfoDlg.clearData = function() {
    this.mallGoodsSpecInfoData = {};
};
 
/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MallGoodsSpecInfoDlg.set = function(key, val) {
    this.mallGoodsSpecInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
};
 
/**
 * 设置对话框中的数据
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MallGoodsSpecInfoDlg.get = function(key) {
    return $("#" + key).val();
};
 
/**
 * 关闭此对话框
 */
MallGoodsSpecInfoDlg.close = function() {
    parent.layer.close(window.parent.MallGoodsSpec.layerIndex);
};
 
/**
 * 收集数据
 */
MallGoodsSpecInfoDlg.collectData = function() {
    this
    .set('id')
    .set('classifyIdOne', Feng.get_chosen_selected( "#classifyIdOne"))
    // .set('classifyIdTwo', Feng.get_chosen_selected( "#classifyIdTwo"))
    .set('specName')
    .set('specValuesJson', JSON.stringify( this.get_spec_values()))
    .set('remark');
};
 
MallGoodsSpecInfoDlg.check_value = function () {
    if ( !Feng.check_form( "formId")) { return false; }
    if ( Feng.get_chosen_selected( "#classifyIdOne").length <= 0) {
        Feng.error( "请选择商品分类")
        return false;
    }
    // if (this.get_spec_values().length <= 0) {
    //     Feng.error( "请设置规格值");
    //     return false;
    // }
    return true;
}
 
/**
 * 提交添加
 */
MallGoodsSpecInfoDlg.addSubmit = function() {
    this.clearData();
    this.collectData();
 
    if ( !this.check_value()) { return; }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/mallGoodsSpec/add", function(data){
        if(data.code == 200){
            Feng.success("添加成功!");
            window.parent.MallGoodsSpec.search();
            MallGoodsSpecInfoDlg.close();
        } else {
            Feng.error("添加失败!" + data.message);
        }
    },function(){
        Feng.error("添加失败!");
    });
    ajax.set(this.mallGoodsSpecInfoData);
    ajax.start();
};
 
 
MallGoodsSpecInfoDlg.change_classify_two = function() {
    return;
    // var twoIds = Feng.get_chosen_selected( "#classifyIdTwo");
    // twoIds = twoIds || $( "#classifyIdTwo").data( "value");
    // $("#classifyIdTwo").data( "value", "").val("").empty().trigger("chosen:updated");
    // var oneIds = Feng.get_chosen_selected( "#classifyIdOne");
    // if ( oneIds.length <= 0) { return; }
    // Feng.base_ajax_data( "/mallClassifyTwo/getMallClassTwoAll", { classOneIds: oneIds}, function (array) {
    //     $("#classifyIdTwo").empty()
    //         .append('<option value="0">全部</option>')
    //         .append( (array||[]).map(function (val) {
    //             var $op = $( "<option value='"+val.id+"'>"+ val.classifyName +"</option>");
    //             $op.data( val);
    //             return $op;
    //         })).val( ((twoIds||"")+"").split( ",")).trigger("chosen:updated");
    // })
}
 
MallGoodsSpecInfoDlg.add_spec = function() {
    var $content = $( "#spec_content"), $tr = $( "<tr>");
 
    $tr.append( $( "<td>").css({"padding-left": "10px"}).append( "<input maxlength='30' placeholder='请输入规格名称' class='form-control'>"))
    $tr.append( $( "<td>").append( "<a style='color: blue' href='javascript:void(0);'>删除</a>"));
 
    $tr.find( "a").on( "click", function () {
        Feng.confirm( "是否确定删除所选中的规格?", function () { $tr.remove(); });
    });
    $content.append( $tr);
}
 
MallGoodsSpecInfoDlg.del_spec_ = function( $id) {
    if (this.get("id")) {
        Feng.confirm( "已使用的商品规格值会发生变化,是否确定删除", function () {
            MallGoodsSpecInfoDlg.deleteSpecValueIds += $id + ",";
            $( "#" + $id).remove();
        });
    } else {
        Feng.confirm( "是否确定删除所选中的规格?", function () { $( "#" + $id).remove() });
    }
}
 
MallGoodsSpecInfoDlg.get_spec_values = function() {
    var result = [];
    $( "#spec_content").find( "tr").each(function () {
        result.push( { specValue: $(this).find( "input").val() , id: $( this).attr("id")})
    });
    return result;
}
 
/**
 * 提交修改
 */
MallGoodsSpecInfoDlg.editSubmit = function() {
    this.clearData();
    this.collectData();
 
    if ( !this.check_value()) { return; }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/mallGoodsSpec/update", function(data){
        if(data.code == 200){
            Feng.success("修改成功!");
            window.parent.MallGoodsSpec.table.refresh();
            MallGoodsSpecInfoDlg.close();
        } else {
            Feng.error("修改失败!" + data.message);
        }
    },function(data){
        Feng.error("修改失败!");
    });
    ajax.set(this.mallGoodsSpecInfoData);
    ajax.set("deleteSpecValueIds", MallGoodsSpecInfoDlg.deleteSpecValueIds);
    ajax.start();
};
 
$(function() {
    Feng.initValidator( "formId", MallGoodsSpecInfoDlg.validFields);
    $("#classifyIdOne").val((($("#classifyIdOne").data("value")||"")+"").split(","));
 
    $( "#classifyIdOne, #classifyIdTwo").on( "change", function () {
        if (0 != $(this).val()) { return; }
        Feng.chose_change( this, Feng.get_select_option_values( this)
            .filter(function(val) { return val != 0 && val})).trigger( "change");
    });
});