define(['jquery', 'table', 'form', 'layui'], function($, Table, Form, layui) { var Element = layui.element; Yzn.config.openArea = ['780px', '640px']; function formatStatus(val) { var map = {0: '未处理', 1: '已跟进', 2: '已转化', 9: '无效'}; return map[val] || val; } function formatOptionType(val) { var map = {country_region: '大洲/区域', country: '国家/地区', industry: '行业'}; return map[val] || val || '-'; } function getLeadFilters() { return { keyword: $('#keyword').val(), country: $('#country').val(), industry: $('#industry').val(), lang: $('#lang').val(), status: $('#status').val(), createtime_start: $('#createtime_start').val(), createtime_end: $('#createtime_end').val() }; } function getOptionFilters() { return { type: $('#option_type').val() || 'country', lang: $('#option_lang').val(), status: $('#option_status').val() }; } function getCurrentOptionType() { return $('#option_type').val() || 'country'; } function currentOptionTitle() { return formatOptionType(getCurrentOptionType()); } var Controller = { index: function() { Table.init = { table_elem: '#currentTable', table_render_id: 'currentTable' }; Table.render({ init: Table.init, toolbar: ['refresh'], url: 'cooperation/index', cols: [[ {type:'checkbox', width:50}, {field:'id', width:80, title:'ID', sort:true}, {field:'name', width:120, title:'姓名'}, {field:'phone', width:150, title:'电话'}, {field:'email', minWidth:200, title:'邮箱'}, {field:'company', minWidth:180, title:'公司名称'}, {field:'country', width:140, title:'国家/地区'}, {field:'industry', width:140, title:'行业'}, {field:'content', minWidth:260, title:'咨询内容'}, {field:'lang', width:90, title:'语言'}, {field:'status', width:100, title:'状态', templet:function(d){ return formatStatus(parseInt(d.status, 10)); }}, {field:'admin_remark', minWidth:180, title:'备注'}, {field:'source_page', minWidth:220, title:'来源页面'}, {field:'privacy_agree', width:100, title:'隐私同意', templet:function(d){ return parseInt(d.privacy_agree,10) ? '已同意' : '未同意'; }}, {field:'privacy_agree_time', width:170, title:'同意时间', templet:function(d){ return d.privacy_agree_time ? Table.formatter.datetime.call(this, d.privacy_agree_time) : '-'; }}, {field:'ip', width:140, title:'提交IP'}, {field:'createtime', width:170, title:'提交时间', templet: Table.formatter.datetime}, {field:'operate', title:'操作', width:260, fixed:'right', templet:function(d){ return '' + '已跟进' + '已转化' + '备注' + '无效'; }} ]], page: {} }); $('#searchBtn').on('click', function() { layui.table.reload('currentTable', { where: getLeadFilters(), page: {curr: 1} }); }); $('#resetBtn').on('click', function() { $('#keyword,#country,#industry,#lang,#status,#createtime_start,#createtime_end').val(''); layui.form.render('select'); layui.table.reload('currentTable', { where: {}, page: {curr: 1} }); }); $('#deleteBtn').on('click', function() { var rows = layui.table.checkStatus('currentTable').data || []; if (!rows.length) { layer.msg('请先勾选留资记录'); return; } var ids = rows.map(function(i){ return i.id; }); layer.confirm('确认删除选中的 ' + ids.length + ' 条留资记录吗?此操作不可恢复。', {icon:3,title:'警告'}, function(index) { $.post('cooperation/del', {ids: ids}, function(res) { layer.msg(res.msg || (res.code===1 ? '删除成功' : '删除失败')); if (res.code === 1) layui.table.reload('currentTable'); }, 'json').fail(function(){ layer.msg('删除请求失败'); }); layer.close(index); }); }); $(document).on('click', '[data-event="status"]', function() { var id = $(this).data('id'); var status = $(this).data('status'); $.post('cooperation/changeStatus', {id: id, status: status}, function(res) { layer.msg(res.msg || (res.code===1 ? '更新成功' : '更新失败')); if (res.code === 1) layui.table.reload('currentTable'); }, 'json').fail(function(){ layer.msg('状态更新失败'); }); }); $(document).on('click', '[data-event="remark"]', function() { var id = $(this).data('id'); var oldRemark = $(this).data('remark') || ''; layer.prompt({title:'填写跟进备注', formType:2, value: oldRemark}, function(value, index) { $.post('cooperation/remark', {id: id, admin_remark: value}, function(res) { layer.msg(res.msg || (res.code===1 ? '保存成功' : '保存失败')); if (res.code === 1) layui.table.reload('currentTable'); }, 'json').fail(function(){ layer.msg('备注保存失败'); }); layer.close(index); }); }); Table.api.bindevent(); Form.api.bindevent($('form.layui-form')); layui.form.render('select'); }, options: function() { Table.init = { table_elem: '#optionTable', table_render_id: 'optionTable' }; Table.render({ init: Table.init, toolbar: ['refresh'], url: 'cooperation/options', cols: [[ {type:'checkbox', width:50}, {field:'id', width:80, title:'ID', sort:true}, {field:'lang', width:100, title:'语言'}, {field:'title', minWidth:180, title:'显示名称'}, {field:'value', minWidth:140, title:'提交值'}, {field:'parent_value', minWidth:140, title:'所属大洲/区域'}, {field:'listorder', width:100, title:'排序', sort:true}, {field:'status', width:100, title:'状态', templet:function(d){ return parseInt(d.status,10) ? '启用' : '禁用'; }}, {field:'updatetime', width:170, title:'更新时间', templet:function(d){ return d.updatetime ? Table.formatter.datetime.call(this, d.updatetime) : '-'; }}, {field:'operate', title:'操作', width:110, fixed:'right', templet:function(d){ return '编辑'; }} ]], page: {}, where: getOptionFilters() }); $('#optionSearchBtn').on('click', function() { layui.table.reload('optionTable', { where: getOptionFilters(), page: {curr: 1} }); }); Element.on('tab(cooperationOptionTabs)', function(data) { var type = $(this).data('type'); if (!type) { return; } $('#option_type').val(type); layui.table.reload('optionTable', { where: getOptionFilters(), page: {curr: 1} }); }); $('#optionResetBtn').on('click', function() { $('#option_lang,#option_status').val(''); layui.form.render('select'); layui.table.reload('optionTable', { where: getOptionFilters(), page: {curr: 1} }); }); $('#addOptionBtn').on('click', function() { Yzn.api.open('cooperation/addOption?type=' + getCurrentOptionType(), '新增' + currentOptionTitle(), {area: Yzn.config.openArea}); }); $('#deleteOptionBtn').on('click', function() { var rows = layui.table.checkStatus('optionTable').data || []; if (!rows.length) { layer.msg('请先勾选选项'); return; } var ids = rows.map(function(i){ return i.id; }); layer.confirm('确认删除选中的 ' + ids.length + ' 个选项吗?', {icon:3,title:'警告'}, function(index) { $.post('cooperation/delOption', {ids: ids}, function(res) { layer.msg(res.msg || (res.code===1 ? '删除成功' : '删除失败')); if (res.code === 1) layui.table.reload('optionTable'); }, 'json').fail(function(){ layer.msg('删除请求失败'); }); layer.close(index); }); }); $(document).on('click', '[data-event="editOption"]', function() { Yzn.api.open('cooperation/editOption?id=' + $(this).data('id'), '编辑' + currentOptionTitle(), {area: Yzn.config.openArea}); }); Table.api.bindevent(); Form.api.bindevent($('form.layui-form')); }, addoption: function() { Form.api.bindevent($('form.layui-form')); }, editoption: function() { Form.api.bindevent($('form.layui-form')); } }; return Controller; });