/**
|
* 管理初始化
|
*/
|
var TQuestion = {
|
id: "TQuestionTable", //表格id
|
seItem: null, //选中的条目
|
table: null,
|
layerIndex: -1
|
};
|
|
/**
|
* 初始化表格的列
|
*/
|
TQuestion.initColumn = function () {
|
return [
|
{field: 'selectItem', checkbox: true},
|
{title: '序号', field: 'id', visible: true, align: 'center', valign: 'middle'},
|
{title: '问题标题', field: 'content', visible: true, align: 'center', valign: 'middle'},
|
{title: '添加时间', field: 'insertTime', visible: true, align: 'center', valign: 'middle',
|
formatter: function (value, row, index) {
|
var date = new Date(value);
|
date.setHours(date.getHours() + 8);
|
return date.toLocaleString('zh-CN', {
|
year: 'numeric',
|
month: '2-digit',
|
day: '2-digit',
|
hour: '2-digit',
|
minute: '2-digit',
|
second: '2-digit',
|
timeZone: 'Asia/Shanghai' // 替换为您想要的时区
|
});
|
}},
|
{title: '排序', field: 'sort', visible: true, align: 'center', valign: 'middle'},
|
{title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle',
|
formatter: function (value, row, index) {
|
return {1: "已上架", 2: "已下架", 3: "已删除"}[value]
|
}
|
}
|
];
|
};
|
|
/**
|
* 检查是否选中
|
*/
|
TQuestion.check = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
|
if(selected.length == 0){
|
Feng.info("请先选中表格中的某一记录!");
|
return false;
|
}else{
|
TQuestion.seItem = selected[0];
|
return true;
|
}
|
};
|
TQuestion.dataCount = 0;
|
TQuestion.phone = "";
|
TQuestion.phoneId = "";
|
|
/**
|
* 点击添加
|
*/
|
TQuestion.openAdd = function () {
|
var index = layer.open({
|
type: 2,
|
title: '添加常见问题',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tQuestion/add'
|
});
|
this.layerIndex = index;
|
};
|
|
|
/**
|
* 点击编辑
|
*/
|
TQuestion.openChange = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if(selected.length >1 ){
|
Feng.info("只能选择一个问题进行编辑!");
|
}else {
|
if (this.check()){
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
var index = layer.open({
|
type: 2,
|
title: '详情',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tQuestion/editQuestion/' + TQuestion.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
}
|
};
|
|
|
|
/**
|
* 上架
|
*/
|
|
TQuestion.onShelf = function () {
|
if (this.check()){
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
const data1 = {
|
questionId:[],
|
type:null
|
};
|
selected.forEach(function(obj) {
|
var id = obj.id;
|
data1.questionId.push(id);
|
});
|
data1.type = 1;
|
$.ajax({
|
url: Feng.ctxPath + "/tQuestion/changeState",
|
type: "POST",
|
contentType: "application/json", // 设置请求头的 Content-Type
|
data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
|
success: function(response) {
|
Feng.success("上架成功!");
|
TQuestion.table.refresh();
|
},
|
error: function(xhr, status, error) {
|
var errorMessage = xhr.responseText ? xhr.responseText : "上架失败!";
|
Feng.error("您的网络异常!");
|
}
|
});
|
}
|
};
|
|
|
/**
|
* 下架
|
*/
|
TQuestion.offShelf = function () {
|
|
if (this.check()){
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
const data1 = {
|
questionId:[],
|
type:null
|
};
|
selected.forEach(function(obj) {
|
var id = obj.id;
|
data1.questionId.push(id);
|
});
|
data1.type = 2;
|
$.ajax({
|
url: Feng.ctxPath + "/tQuestion/changeState",
|
type: "POST",
|
contentType: "application/json", // 设置请求头的 Content-Type
|
data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
|
success: function(response) {
|
Feng.success("下架成功!");
|
TQuestion.table.refresh();
|
|
},
|
error: function(xhr, status, error) {
|
var errorMessage = xhr.responseText ? xhr.responseText : "下架失败!";
|
Feng.error("您的网络异常!");
|
}
|
});
|
}
|
};
|
/**
|
* 查看详情
|
*/
|
TQuestion.getInfo = function () {
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
if(selected.length >1 ){
|
Feng.info("只能选择一条进行查看!");
|
}else {
|
if (this.check()){
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
|
var index = layer.open({
|
type: 2,
|
title: '详情',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tQuestion/infoQuestion/' + TQuestion.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
}
|
};
|
|
/**
|
* 删除
|
*/
|
TQuestion.delete = function () {
|
if (this.check()){
|
var selected = $('#' + this.id).bootstrapTable('getSelections');
|
|
const data1 = {
|
questionId:[],
|
type:null
|
};
|
selected.forEach(function(obj) {
|
var id = obj.id;
|
data1.questionId.push(id);
|
});
|
data1.type = 3;
|
|
$.ajax({
|
url: Feng.ctxPath + "/tQuestion/changeState",
|
type: "POST",
|
contentType: "application/json", // 设置请求头的 Content-Type
|
data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
|
success: function(response) {
|
Feng.success("删除成功!");
|
TQuestion.table.refresh();
|
},
|
error: function(xhr, status, error) {
|
var errorMessage = xhr.responseText ? xhr.responseText : "删除失败!";
|
Feng.error(errorMessage);
|
}
|
});
|
}
|
};
|
/**
|
* 打开查看详情
|
*/
|
TQuestion.openDetail = function () {
|
if (this.check()) {
|
var index = layer.open({
|
type: 2,
|
title: '详情',
|
area: ['100%', '100%'], //宽高
|
fix: false, //不固定
|
maxmin: true,
|
content: Feng.ctxPath + '/tQuestion/editQuestion/' + TQuestion.seItem.id
|
});
|
this.layerIndex = index;
|
}
|
};
|
|
|
/**
|
* 查询列表
|
*/
|
TQuestion.search = function () {
|
var queryData = {};
|
queryData['content'] = $("#content").val();
|
queryData['state'] = $("#state").val();
|
TQuestion.table.refresh({query: queryData});
|
};
|
|
|
/**
|
* 重置搜索
|
*/
|
TQuestion.resetSearch = function () {
|
$("#content").val('');
|
$("#state").val('');
|
TQuestion.search();
|
};
|
|
$(function () {
|
|
const data1 = {
|
id:null,
|
phone:null,
|
insertTime:null
|
};
|
// 获取客服电话
|
$.ajax({
|
url: Feng.ctxPath + "/tPhone/list",
|
type: "POST",
|
contentType: "application/json", // 设置请求头的 Content-Type
|
success: function(response) {
|
var phoneValue = null;
|
var split = [];
|
// 遍历列表数据使用 forEach() 方法
|
response.forEach(function (item) {
|
TQuestion.phoneId = item.id;
|
phoneValue = item.phone;
|
split = phoneValue.split(",");
|
});
|
if (response[0].phone !== "" && response[0].phone!== null) {
|
var dataContainer = document.getElementById('phone');
|
split.forEach(function (item) {
|
if (item !== ''){
|
// 创建新的数据项
|
var dataItem = document.createElement('div');
|
dataItem.className = 'data-item';
|
dataItem.innerText = item;
|
// 创建删除按钮
|
var deleteButton = document.createElement('div');
|
deleteButton.className = 'delete-button';
|
deleteButton.innerHTML = '×';
|
// 为删除按钮添加点击事件监听器
|
deleteButton.addEventListener('click', function () {
|
TQuestion.dataCount--;
|
// 在点击事件处理程序中删除数据项
|
dataContainer.removeChild(dataItem);
|
});
|
// 将删除按钮添加到数据项
|
dataItem.appendChild(deleteButton);
|
// 将数据项添加到容器中
|
dataContainer.appendChild(dataItem);
|
TQuestion.dataCount++;
|
// 获取item元素的文本内容(不包含"x")
|
var itemValues = Array.from(dataContainer.getElementsByClassName('data-item')).map(function (item) {
|
return item.innerText.replace(/[\u00D7]/g, '').trim();
|
});
|
}
|
|
});
|
}
|
var addButton = document.getElementById('addButton');
|
addButton.addEventListener('click', function () {
|
var phoneRegex = /^1[0-9]{10}$/;
|
var landlineRegex = /^\d{4}-\d{7}$/;
|
|
var inputField = document.getElementById('addPhone');
|
var dataContainer = document.getElementById('phone');
|
var inputData = inputField.value.trim();
|
if (TQuestion.dataCount>=2){
|
Feng.info("最多添加两个客服电话!");
|
// todo 添加正则表达式验证电话号码合法性
|
}else if(!phoneRegex.test(inputData)&&!landlineRegex.test(inputData)){
|
Feng.info("客服电话不合法,请重新输入!");
|
}else {
|
if (inputData !== '' || document.querySelectorAll('.data-item').length !==0) {
|
TQuestion.phone = "";
|
// 创建新的数据项
|
var dataItem = document.createElement('div');
|
if (inputData !== ''){
|
dataItem.className = 'data-item';
|
dataItem.innerText = inputData;
|
// 创建删除按钮
|
var deleteButton = document.createElement('div');
|
deleteButton.className = 'delete-button';
|
deleteButton.innerHTML = '×';
|
// 为删除按钮添加点击事件监听器
|
deleteButton.addEventListener('click', function () {
|
TQuestion.dataCount--;
|
// 在点击事件处理程序中删除数据项
|
dataContainer.removeChild(dataItem);
|
});
|
// 将删除按钮添加到数据项
|
dataItem.appendChild(deleteButton);
|
// 将数据项添加到容器中
|
dataContainer.appendChild(dataItem);
|
// 清空输入框的内容
|
inputField.value = '';
|
TQuestion.dataCount++;
|
}
|
var dataItems = document.querySelectorAll('.data-item');
|
for(var i = 0; i < dataItems.length; i++) {
|
var dataItem1 = dataItems[i];
|
TQuestion.phone = TQuestion.phone+dataItem1.textContent.slice(0, -1)+",";
|
}
|
data1.phone = TQuestion.phone;
|
data1.id = TQuestion.phoneId;
|
$.ajax({
|
url: Feng.ctxPath + "/tPhone/update",
|
type: "POST",
|
contentType: "application/json", // 设置请求头的 Content-Type
|
data: JSON.stringify(data1), // 将数据转换为 JSON 字符串
|
success: function(response) {
|
Feng.success("添加成功!");
|
TQuestion.table.refresh();
|
// window.parent.TQuestion.table.refresh();
|
TQuestion.phone = "";
|
},
|
error: function(xhr, status, error) {
|
TQuestion.phone = "";
|
var errorMessage = xhr.responseText ? xhr.responseText : "添加失败!";
|
Feng.error(errorMessage);
|
}
|
});
|
} else {
|
Feng.info("请输入客服电话!");
|
}
|
}
|
|
});
|
// window.parent.TQuestion.table.refresh();
|
},
|
error: function(xhr, status, error) {
|
var errorMessage = xhr.responseText ? xhr.responseText : "删除失败!";
|
Feng.error(errorMessage);
|
}
|
});
|
var defaultColunms = TQuestion.initColumn();
|
var table = new BSTable(TQuestion.id, "/tQuestion/list", defaultColunms);
|
table.setPaginationType("client");
|
TQuestion.table = table.init();
|
});
|