layui.use(['table', 'jquery', 'madmin', 'mhttp', 'layer', 'form', 'common'], function () { let table = layui.table; let $ = layui.jquery; let admin = layui.madmin; let layer = layui.layer; let form = layui.form; let common = layui.common; let mhttp = layui.mhttp; admin.getConfig(); getStorageServersConfig(); //搜索条件 let uid = GetQueryString('uid') ?? null; let agent_uid = GetQueryString('agent_uid') ?? null; let mom_app_uid = GetQueryString('mom_app_uid') ?? null; let agent_username = GetQueryString('agent_username') ?? null; $('.uid').val(uid); $('.agent_uid').val(agent_uid); $('.mom_app_uid').val(mom_app_uid); $('.agent_username').val(agent_username); let appArray = {}; let appArrayInfo = {}; // 获取app let ret = mhttp.ajax({ url: '/app/all' }); ret.then((data) => { if (data.code === 200) { let html = ''; for (var i in data.data) { appArray[data.data[i].uid] = data.data[i].name; appArrayInfo[data.data[i].uid] = data.data[i]; html += ''; } $('.mom_app_uid').append(html); $('.mom_app_uid .se_' + mom_app_uid).attr('selected', 'selected'); form.render(); let cols = [ [ { title: 'UID', field: 'uid', align: 'center', }, { title: '渠道名字', field: 'name', align: 'center' }, { title: '代理UID', field: 'agent_uid', align: 'center', }, { title: '代理名称', field: 'nick', align: 'center', templet: function (d) { if (!d.agent_name) { return '未知'; } return d.agent_name.nick; } }, { title: '渠道链接', field: 'share_url', align: 'center', templet: function (d) { if (d.share_url) { return ''; } else { return ''; } } }, { title: '应用名称', field: 'mom_app_uid', align: 'center', templet: function (d) { return appArray[d.mom_app_uid]; } }, { title: '更新时间', field: 'updated_at', align: 'center' }, { title: '操作', field: 'updated_at', align: 'center', width: '200', templet(d) { if (d.channel_row) { // 判断版本号是否相同 if (appArrayInfo[d.mom_app_uid].android_version === d.channel_row.mom_app_version) { if (d.channel_row.status === 1) { return '
'; } else if ((d.channel_row.status === 2)) { return '
'; } else if ((d.channel_row.status === 3)) { return '
'; } } else { return '
'; } } else { return '
'; } } }, ] ]; let search = httpRequestPostData({ uid: uid, agent_uid: agent_uid, mom_app_uid: mom_app_uid, agent_username: agent_username }); table.render({ elem: '#channel-table', method: 'POST', request: { pageName: 'page', limitName: 'page_size' }, async: false, headers: { "AUTH-TOKEN": localStorage.getItem('XSRF-TOKEN') ?? '' }, contentType: 'application/json', where: search, url: getMyApiUrl('/agent/channel/list'), limit: 20, limits: [20, 30, 40, 50, 80, 100], parseData: function (res) { return httpRequestPagesParseData(res); }, response: { "statusCode": 200, }, done: function (data, page, total) { var intCode = parseInt(data.code); if (intCode === 403) { cbRespnseRedirectLogin(data); } else if (intCode === 401) { // 仅仅是过期了,这里可以有其他逻辑补偿. // 暂时跳到登陆页面 cbRespnse401(data); } onloadRender(); }, error: function (obj, message) { cbRespnseReloadPage(obj, message); }, page: true, cols: cols, skin: 'line', defaultToolbar: [{ title: '刷新', layEvent: 'refresh', icon: 'layui-icon-refresh', }, 'filter', 'print', 'exports'] }); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); form.render(); // 表单内 table.on('tool(channel-table)', function (obj) { if (obj.event === 'pack') { let createLoading = layer.load(); // 打包 let ret = mhttp.ajax({ url: '/agent/channel/pack', data: {uid: obj.data.uid} }); ret.then((data) => { layer.close(createLoading); if (data.code === 200) { layer.msg(data.message, {icon: 1, time: 1000}, function () { // 成功刷父页面 // window.parent.location.reload(); // 成功关闭父窗口 // let index = parent.layer.getFrameIndex(window.name); // parent.layer.close(index); // parent.layui.table.reload("channel-table"); // table.reload('channel-table'); let p_uid = obj.data.uid; let pack_bth = $('.pack_btn-box_uid_' + p_uid); pack_bth.html('
'); }); } else { layer.msg(data.message, {icon: 2, time: 1000}); } }); return false; } else if (obj.event === 'cp') { // 复制 layer.open({ id: 'qrcode', type: 2, title: '获取链接', shade: 0.1, offset: '200px', area: ['400px', '200px'], maxWidth: 500, maxHeight: 500, scrollbar: true, content: 'copy_link.html?|||' + obj.data.channel_row.app_download, }); } else if (obj.event === 'cp_link') { console.debug(obj.data) // 复制 layer.open({ id: 'qrcode', type: 2, title: '获取链接', shade: 0.1, offset: '200px', area: ['400px', '200px'], maxWidth: 500, maxHeight: 500, scrollbar: true, content: 'copy_link.html?|||' + obj.data.share_url, }); } }); $('#reset').click(function () { window.location.href = './channel_list.html'; }); window.refresh = function (param) { table.reload('channel-table'); } })