/** * 消息管理相关js * * @author CaiAoLin * @date 2017/9/21 * @version */ $(document).ready(function() { // 选择框 $(".selector > li > a").click(function() { let value = $(this).data("value"); let string = $(this).text(); let selector = $(this).parent().parent(); selector.next("input:hidden").val(value); selector.prev("button").children("lable").text(string); $('#searchUser').submit(); //selector.prev("button").html(string + ' '); }); $("#deleteConfirm").click(async function () { let userID = $("#userID").val(); let delCount = parseInt($("#delCount").val()); delCount = delCount+1; $("#delCount").val(delCount); if(delCount == 3){//连续点3次才做真删除 if(userID!=""){ try { $.bootstrapLoading.start(); let result = await ajaxPost("/user/deleteUser",{userID:userID}); $.bootstrapLoading.end(); if(result == "success"){ window.location.reload(); }else { alert("删除失败!"); $("#delCount").val(0); } }catch (err){ $.bootstrapLoading.end(); $("#delCount").val(0); } } } }); $('#remove-cldUser').click(async function () { const id = $(this).attr('data-uid'); if(id !== '') { try { await ajaxPost("/user/updateUser",{ID:id,updateData:{is_cld:0}}); window.location.reload(); }catch (err){ console.log(err); } } }); $('#add-allCldUser').click(async function () { try { await ajaxPost("/user/updateCldUser", {}); window.location.reload(); }catch (err){ console.log(err); } }) }); let cacheUser = null; async function getOnlineInfo(filter) { try { let htmlString = `日期/时间在线时长`; let info = await ajaxPost("/user/getOnlineInfo",JSON.parse(filter)); for(let i of info){ htmlString += `${i.dateString}${i.online_times}` } htmlString +=""; $("#time-detail-table").html(htmlString); }catch (e){ console.log(e) } } async function getUserInfo(ID) { let user = await ajaxPost("/user/findByID",{ID:ID}); let infoString = `注册时间${user.create_time}最近登录${moment(user.latest_login).format('YYYY-MM-DD HH:mm:ss')} 手机${user.mobile}邮箱${user.email} 姓名${user.real_name} 企业名称${user.company}`; $('#userInfoTable').html(infoString); $('#remove-cldUser').attr('data-uid', ID); } function deleteUser(userID) { $("#delCount").val(0); $("#userID").val(userID); } function searchUser() { const keyword = $.trim($('#search_keyword').val()); if (keyword === '') { alert("请输出查询用户信息!"); } CommonAjax.get(`/user/search?keyword=` + keyword, function (result) { if (result.error === 0) { let html = ''; for (const user of result.data) { html += `${user.real_name}${user.email}${user.mobile}` + (user.is_cld === 0 ? `添加` : '已添加') + ``; } $('#search_user_list').html(html); } else { alert(result.msg); } }); return false; } async function addCldUser($this, id) { try { await ajaxPost("/user/updateUser",{ID:id,updateData:{is_cld:Date.parse(new Date())/1000}}); const _self = $($this).parents('td'); $this.remove(); _self.text('已添加'); }catch (err){ console.log(err); } } async function getUserUpgradeInfo(ID){ try { cacheUser = await ajaxPost("/user/findByID",{ID:ID}); refreshUpgradeTable(cacheUser); }catch (err){ console.log(err); } } function refreshUpgradeTable(user) { let compilationTable = ' 专业版升级'; let test = true; for(let c of compilationList){ compilationTable += `${c.name} ${getButtonHtml(c._id)} `; } $('#upgrade_table').html(compilationTable); function getButtonHtml(ID) { let updateString = `
`; let closeString = `
`; let upgradeInfo = _.find(user.upgrade_list,{'compilationID':ID}); if(upgradeInfo){ if(upgradeInfo.isUpgrade == true){ return updateString + upgradeInfo.remark; }else { return closeString + upgradeInfo.remark; } }else { return closeString; } } } async function updateUser(compilationID,type) { if(cacheUser){ let upgrade_list = cacheUser.upgrade_list?cacheUser.upgrade_list:[]; let upgradeInfo = _.find(upgrade_list,{'compilationID':compilationID}); if(!upgradeInfo){ upgradeInfo = { compilationID:compilationID,//编办ID upgrade_time:new Date().getTime(), isUpgrade:true, }; upgrade_list.push(upgradeInfo); } if(type == 'upgrade'){ upgradeInfo.isUpgrade = true; upgradeInfo.remark = adminName + " "+ moment().format("YYYY-MM-DD") +" 启用"; }else { upgradeInfo.isUpgrade = false; upgradeInfo.remark = adminName + " "+ moment().format("YYYY-MM-DD") +" 关闭"; } try { await ajaxPost("/user/updateUser",{ID:cacheUser._id,updateData:{upgrade_list:upgrade_list}}); cacheUser.upgrade_list = upgrade_list; refreshUpgradeTable(cacheUser); }catch (err){ console.log(err); } } }