puzhibing
2024-03-06 b79d17d163a1f162190cb46d881ab1fd5957c602
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
/**
 * 初始化详情对话框
 */
var THomeModuleDlg = {
    tHomeModuleData : {}
};
var language=$("#language").val();
/**
 * 清除数据
 */
THomeModuleDlg.clearData = function() {
    this.tHomeModuleData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
THomeModuleDlg.set = function(key, val) {
    this.tHomeModuleData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
THomeModuleDlg.get = function(key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
THomeModuleDlg.close = function() {
    parent.layer.close(window.parent.THomeModule.layerIndex);
}
 
THomeModuleDlg.provinceChange = function () {
    var provinceId = $("#cityId").val();
    var ajax = new $ax(Feng.ctxPath + "/THomeModule/change", function(data){
        if(data!=null){
            if(language==1){
                var content='<option value="">选择市</option>';
            }else if(language==2){
                var content='<option value="">Please select a city</option>';
            }else {
                var content='<option value="">Pilih Kota</option>';
            }
            $.each(data, function(k,v) {
                content += "<option value='"+v.id+"'>"+v.chineseName+"</option>";
            });
            $("#cityId1").empty().append(content);
        }
    });
    ajax.set("id",provinceId);
    ajax.start();
}
/**
 * 收集数据
 */
THomeModuleDlg.collectData = function() {
    this
    .set('id')
    .set('isOpen')
    .set('title')
    .set('isTop')
    .set('sort')
    .set('backgroundImage')
    .set('buttonImage')
    .set('model')
    .set('page')
    .set('jumpPage')
    .set('type')
    .set('typeId')
    .set('turnId')
    .set('content');
}
 
THomeModuleDlg.updateSubmit = function(){
 
    console.log("kankan")
    console.log($("#backgroundImage").val())
    var data1 = {
        id:null,
        isOpen:null,
        title:"",
        isTop:null,
        sort:null,
        backgroundImage:"",
        buttonImage:"",
        model:null,
        page:"",
        jumpPage:null,
        type:"",
        typeId:null,
        turnId:null,
        content:"",
    };
    let name  =  $("#model").val();
    data1.id = $("#id").val();
    if(document.querySelector('input[name="isOpen"]').checked){
        data1.isOpen = 1;
    }else {
        data1.isOpen = 0;
    }
    if(document.querySelector('input[name="isTop"]').checked){
        data1.isTop = 1;
    }else {
        data1.isTop = 0;
    }
    data1.title = $("#title").val();
    data1.sort = $("#sort").val();
    data1.backgroundImage = $("#backgroundImage").val();
    data1.buttonImage = $("#buttonImage").val();
    data1.model = $('#model option:selected').text();
    data1.page =  $('#page option:selected').text();
    data1.jumpPage = $("#page").val();
    data1.type = $('#type option:selected').text();
    data1.typeId = $("#type").val();
    data1.turnId = $("#pageId").val();
    data1.content = jQuery.trim(THomeModuleDlg.editor.getContent());
 
    if ( $("#roleType").val()==1){
        if($("#title").val()==''){
            data1.title = $("#title").val();
            Feng.info("请填写标题")
            return;
        }
    }
 
    if ( $("#roleType").val()==1) {
        if ($("#model").val() == '') {
            Feng.info("请选择跳转模块")
            return;
        }
    }
    if(name !='0'){
        if($("#page").val()=='' ){
            Feng.info("请选择跳转页面")
            return;
        }
    }
    if(name !='0') {
        if ($("#roleType").val() == 1) {
            if ($("#type").val() == ''&&$("#page").val()!=2&&$("#page").val()!=25&&$("#page").val()!=27&&$("#page").val()!=37&&$("#page").val()!=28) {
                Feng.info("请选择跳转类型")
                return;
            }
        }
    }
    if(name !='0') {
        if ($("#roleType").val() == 1) {
            if ($('#type option:selected').text() == "详情"&&$('#type option:selected').text() == "指定商品"&&$('#type option:selected').text() == "指定折扣") {
                if ($("#pageId").val() == '') {
                    Feng.info("请输入跳转ID")
                    return;
                }
            }
        }
    }
    if ( $("#roleType").val()==1){
        if($("#content").val()==''){
            data1.content = $("#content").val();
            Feng.info("请填写内容设置")
            return;
        }
    }
    $.ajax({
        url: Feng.ctxPath + "/tHomeModule/updateHomeModule",
        type: "POST",
        contentType: "application/json", // 设置请求头的 Content-Type
        data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
        success: function(response) {
            // window.parent.THomeModule.table.refresh();
            THomeModuleDlg.close();
            Feng.success("编辑成功!");
        },
        error: function(xhr, status, error) {
            var errorMessage = xhr.responseText ? xhr.responseText : "下架失败!";
            Feng.error("您的网络异常!");
        }
    });
};
 
$(function() {
    THomeModuleDlg.editor = UE.getEditor('editor');
    var backgroundImage = new $WebUpload("backgroundImage");
    backgroundImage.setUploadBarId("progressBar");
    backgroundImage.init();
    var buttonImage = new $WebUpload("buttonImage");
    buttonImage.setUploadBarId("progressBar");
    buttonImage.init();
});