yujian
2020-04-29 d840d22b0fb31394f7e0b4fc3daa8f761f1c7866
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
// ==================================================================================== 页面数据
// vue 实例化
var vm = null;
var editor = null;
var backParams = null;
doui.onReady(function()
{
    vm = new Vue({
        el: "#allwai",
        
        // 数据
        data: {
            
            // ---------------------------------------------------------------- 新建问题数据
            // 问题编辑
            question: {
                type: 'new', // 新建还是修改?
                id: '', // 问题的id
                title: "", // 问题的标题
                html: "", // 问题的答案html
                json: "", // 问题的答案json
                startTime: "", 
                endTime: "", 
            },
        },
        
        // 初始化事件
        methods: {
            // 初始化 问题编辑
            creatQuestion: function ()
            {
                vm.question.type = 'new';
                vm.question.id = null;
                vm.question.title = "";
                vm.question.html = "";
                vm.question.json = "";
                vm.question.startTime = "";
                vm.question.endTime = "";
                vm.question.cid = 0;
                vm.question.state = 0;
                vm.question.weight = 0;
            },
        },
    });
    
    
    // 获取传递值
    var urldata = doui.urlParamGet();
    if (urldata.type) { vm.question.type = urldata.type; }
    if (urldata.id) { vm.question.id = urldata.id;}
    backParams = urldata.backParams;
    
    
    // 编辑器初始化
    editor = wang.createGet({
        ids: ['editor1'],
        menus: ['fontName', 'fontSize', 'justify', 'foreColor', 'bold', 'quote', 'link', 'image', 'undo', 'redo'], // 菜单项设置
        imgBase64: true, // 图片上传转base64开启?
    });
    // 编辑器样式
    wang.style_scrollbar();
    wang.style_menu(editor, "font-size:0.08rem");
    wang.style_editor(editor, "height:600px;");
    wang.style_img("width:94%; height:auto; margin-left:3%;");
    
    // 分类获取
    helpClassGet();
    
    $("body").css("display","block");
});
 
function goListPage() {
    pageReplaceUrl("helpCenter.html?backParams=" + backParams);
}
        
 
// 编辑器 初始化
function creatEditor () { editor.txt.clear(); }
 
// 编辑器 内容设置,参数:   html代码字符串
function htmlEditor (htmlC) { editor.txt.html(htmlC); }
 
// 编辑器 确定提交
function okClick ()
{
    // 获取 JSON 格式的内容
    var json = editor.txt.getJSON();
    vm.question.json = json;
    
    // 获取 html 格式的内容
    var strHtml = editor.txt.html();
    vm.question.html = strHtml;
    
    vm.question.startTime = $("#test4").val();
    vm.question.endTime = $("#test5").val();
    vm.question.cid = $("#cid").val();
    vm.question.state = $("#state").val();
    vm.question.weight = $("#weight").val();
    
    // 发送数据
    submitQuestionSet();
}
    
 
 
// ==================================================================================== 数据请求
// 获取某个问题详情
function questionGet ()
{
    if (vm.question.id)
    {
        // 数据准备
        var myurl = gethttp() + "/admin/new/api/v1/helpCenter/getInfo";
        var mydata = doui.AjaxData({ id: vm.question.id, });
        
        // 数据请求
        doui.showLoading("加载问题");
        doui.AjaxJsonp(myurl, mydata, function(res)
        {
            if (res.code != 0) { doui.hideLoading(); doui.showToast(res.msg); }
            else 
            {
                // 标题赋值
                vm.question.title = res.data.title;
                // 保存json
                vm.question.json = res.data.content;
                
                $("#test4").val(res.data.startTime);
                $("#test5").val(res.data.endTime);
                $("#cid").val(res.data.cid);
                $("#state").val(res.data.state);
                $("#weight").val(res.data.weight);
                
                // 编辑器 设置html代码
                htmlEditor(res.data.html);
                doui.hideLoading();
            }
        });
    }
}
 
 
// 获取某个问题详情
function helpClassGet ()
{
    // 数据准备
    var myurl =gethttp() + "/admin/new/api/v1/helpCenter/getProvidedClass";
    var mydata = doui.AjaxData({ });
    doui.AjaxJsonp(myurl, mydata, function(res)
    {
        if (res.code != 0) { doui.hideLoading(); doui.showToast(res.msg); }
        else 
        {
            var versionsHtml = "<option value=0></option>";
            for (var i = 1, mo = res.data.class_list; i < mo.length; i++) {
                versionsHtml += "<option value=" + res.data.class_list[i].id + ">" ;
                versionsHtml += res.data.class_list[i].name;
                versionsHtml += "</option>";
            }
            $("#cid").empty();
            $("#cid").append(versionsHtml);
            
            // 内容获取
            questionGet();
        }
    });
}
 
// 提交问题编辑
function submitQuestionSet ()
{
    // 检测标题是否填写
    if (vm.question.title.length <= 0) { doui.showToast("未填写标题"); return false; }
    
    // 数据准备
    var myurl = gethttp() + "/admin/new/api/v1/helpCenter/save";
    var mydata = {
        id: vm.question.id,
        title: vm.question.title,
        content: "",
        html: vm.question.html,
        acction: adminCookieGet().userName,
        pwd: adminCookieGet().passWord,
        startTime: vm.question.startTime,
        endTime: vm.question.endTime,
        "helpClass.id": vm.question.cid,
        state: vm.question.state,
        weight: vm.question.weight,
    };
    
    
    // 数据请求
    doui.showLoading("正在处理");
    doui.AjaxUpload(myurl, mydata, function(res)
    {
        if (res.code != 0) { doui.hideLoading(); doui.showToast(res.msg); }
        else 
        {
            doui.hideLoading();
            doui.showToast("处理成功");
            // 初始化 编辑页
            vm.creatQuestion();
            creatEditor();
            // 返回上一页,且重新请求列表
            setTimeout(function()
            {
                pageReplaceUrl("helpCenter.html");
                
            }, 500);
        }
    });
}