// ==================================================================================== 页面数据
// 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 = "";
for (var i = 1, mo = res.data.class_list; i < mo.length; i++) {
versionsHtml += "";
}
$("#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()
{
goListPage();
}, 500);
}
});
}