binquan.qiu | 366cc5b | 2020-03-19 15:32:13 +0800 | [diff] [blame^] | 1 | <div class="layui-card"> |
| 2 | <div class="layui-card-header"> |
| 3 | <h2 class="header-title">客户管理</h2> |
| 4 | <span class="layui-breadcrumb pull-right"> |
| 5 | <a href="#">客户管理</a> |
| 6 | <a><cite>客户管理</cite></a> |
| 7 | </span> |
| 8 | </div> |
| 9 | <div class="layui-card-body"> |
| 10 | <div class="layui-form toolbar"> |
| 11 | 搜索: |
| 12 | <input id="customer-search-value" class="layui-input search-input" type="text" placeholder="输入姓名"/>  |
| 13 | <button id="customer-btn-search" class="layui-btn icon-btn" data-type="search"><i class="layui-icon"></i>搜索 |
| 14 | </button> |
| 15 | <button id="customer-btn-add" class="layui-btn icon-btn" data-type="add"><i class="layui-icon"></i>添加人员</button> |
| 16 | <!-- <button id="customer-btn-import" class="layui-btn icon-btn" ><i class="layui-icon"></i>批量导入</button>--> |
| 17 | <!-- <a id="customer-btn-export" href="javascript:void(0);" class="layui-btn layui-btn-primary" >导出</a>--> |
| 18 | </div> |
| 19 | <table class="layui-table" id="customer-table" lay-filter="customer-table"></table> |
| 20 | </div> |
| 21 | </div> |
| 22 | <input hidden th:value="${custtypelist}" id="custtypelist"> |
| 23 | <input hidden th:value="${deptlist}" id="deptlist"> |
| 24 | <script> |
| 25 | |
| 26 | var ctlist=$("#custtypelist").val(); |
| 27 | var custtypelist=JSON.parse(ctlist); |
| 28 | var dplist=$("#deptlist").val(); |
| 29 | var deptlist=JSON.parse(dplist); |
| 30 | layui.use(['form', 'table', 'layer', 'admin', 'element'], function () { |
| 31 | let form = layui.form; |
| 32 | let table = layui.table; |
| 33 | let admin = layui.admin; |
| 34 | |
| 35 | form.render('select'); |
| 36 | |
| 37 | // 渲染表格 |
| 38 | table.render({ |
| 39 | elem: '#customer-table', |
| 40 | url: '[[@{/customer/list}]]', |
| 41 | page: true, |
| 42 | minWidth: 80, |
| 43 | cols: [ |
| 44 | [ |
| 45 | {field: 'custname', sort: true, width: 120, title: '客户姓名'}, |
| 46 | {field: 'cardno', sort: true,width: 120, title: '市名卡号'}, |
| 47 | {field: 'phone', title: '联系电话'}, |
| 48 | {field: 'bankcardno', sort: true, width: 200, title: '银行卡号'}, |
| 49 | /*{ |
| 50 | field: 'checkstatus', title: '审核状态', align: 'center', width: 120, sort: true, templet: function (d) { |
| 51 | if ('uncheck' == d.checkstatus) { |
| 52 | return '<span class="layui-badge layui-bg-orange">待审核</span>' |
| 53 | } else if ('normal' == d.checkstatus) { |
| 54 | return '<span class="layui-badge layui-bg-green">成功</span>'; |
| 55 | } else if ('fail' == d.checkstatus) { |
| 56 | return '<span class="layui-badge layui-bg-gray">失败</span>'; |
| 57 | } else { |
| 58 | return d.checkstatus; |
| 59 | } |
| 60 | } |
| 61 | },*/ |
| 62 | { |
| 63 | field: 'deptcode', |
| 64 | title: '部门', |
| 65 | sort: true, |
| 66 | align: 'center', |
| 67 | templet: function (item) { |
| 68 | console.log(deptlist); |
| 69 | for(var i=0 ;i<deptlist.length;i++){ |
| 70 | if(item.deptcode==deptlist[i].deptcode){ |
| 71 | return deptlist[i].deptname; |
| 72 | } |
| 73 | } |
| 74 | return item.deptno; |
| 75 | } |
| 76 | }, |
| 77 | { |
| 78 | field: 'custtype', width:100, title: '人员类别', templet: function (item) { |
| 79 | for(var i=0 ;i<custtypelist.length;i++){ |
| 80 | if(item.custtypeid==custtypelist[i].custtypeid){ |
| 81 | return custtypelist[i].custtypename; |
| 82 | } |
| 83 | } |
| 84 | return item.custtypeid; |
| 85 | } |
| 86 | }, |
| 87 | { |
| 88 | field: 'custid', align: 'center',width:150, title: '操作', fixed: 'right', templet: function (item) { |
| 89 | return ' <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a> '+ |
| 90 | ' <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>'; |
| 91 | } |
| 92 | } |
| 93 | ] |
| 94 | ] |
| 95 | }); |
| 96 | $('#customer-btn-export').click(function () { |
| 97 | var url = '[[@{/customer/export}]]'; |
| 98 | /* $("#form").attr("action",url); |
| 99 | |
| 100 | $("#form").submit();*/ |
| 101 | |
| 102 | $("#customer-btn-export").attr("href", url ); |
| 103 | $("#customer-btn-export")[0].click(); |
| 104 | }); |
| 105 | // 搜索按钮点击事件 |
| 106 | $('#customer-btn-search').click(function () { |
| 107 | let key = $('#customer-search-value').val().trim(); |
| 108 | table.reload('customer-table', {where: {searchkey: key}, page: {curr: 1}}); |
| 109 | }); |
| 110 | $('#customer-btn-add').click(function () { |
| 111 | showModel(); |
| 112 | }); |
| 113 | /* $('#customer-btn-import').click(function () { |
| 114 | showDownload(); |
| 115 | }); |
| 116 | let showDownload = function () { |
| 117 | let title ='导入'; |
| 118 | admin.popupCenter({ |
| 119 | title: title, |
| 120 | path: '[[@{/customer/loadimport}]]', |
| 121 | finish: function () { |
| 122 | table.reload('customer-table', {}); |
| 123 | } |
| 124 | }); |
| 125 | };*/ |
| 126 | let showModel = function (data) { |
| 127 | let title = data ? '修改人员信息' : '添加人员信息'; |
| 128 | admin.putTempData('t_cus', data); |
| 129 | admin.popupCenter({ |
| 130 | title: title, |
| 131 | path: '[[@{/customer/loadadd}]]', |
| 132 | finish: function () { |
| 133 | table.reload('customer-table', {}); |
| 134 | } |
| 135 | }); |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | // 工具条点击事件 |
| 140 | table.on('tool(customer-table)', function (obj) { |
| 141 | let data = obj.data; |
| 142 | let layEvent = obj.event; |
| 143 | console.log(data); |
| 144 | if (layEvent === 'edit') { |
| 145 | showModel(data); |
| 146 | } else if (layEvent === 'del') { |
| 147 | showDelete(data); |
| 148 | } |
| 149 | }); |
| 150 | let showDelete = function (data) { |
| 151 | console.log(data); |
| 152 | layer.confirm('确定要删除吗?', function (i) { |
| 153 | layer.close(i); |
| 154 | layer.load(2); |
| 155 | let token = $("meta[name='_csrf_token']").attr("value"); |
| 156 | admin.go('[[@{/customer/delete}]]', { |
| 157 | custid: data.custid, |
| 158 | _csrf: token |
| 159 | }, function (data) { |
| 160 | console.log(data.code); |
| 161 | layer.closeAll('loading'); |
| 162 | if (data.code == 200) { |
| 163 | layer.msg(data.msg, {icon: 1}); |
| 164 | } else if (data.code == 401) { |
| 165 | layer.msg(data.msg, {icon: 2, time: 1500}, function () { |
| 166 | location.replace('/login'); |
| 167 | }, 1000); |
| 168 | return; |
| 169 | } else { |
| 170 | layer.msg(data.msg, {icon: 2}); |
| 171 | } |
| 172 | table.reload('customer-table', {}); |
| 173 | }, function (ret) { |
| 174 | console.log(ret); |
| 175 | layer.closeAll('loading'); |
| 176 | layer.msg('请求失败了,请稍后再试', {icon: 2}); |
| 177 | }); |
| 178 | }); |
| 179 | }; |
| 180 | |
| 181 | }); |
| 182 | </script> |