app/views/educode_sales/customers/index.html.erb in educode_sales-0.9.44 vs app/views/educode_sales/customers/index.html.erb in educode_sales-0.9.45

- old
+ new

@@ -43,10 +43,16 @@ </div> <script type="text/html" id="toolbarDemo"> <div class="layui-btn-container"> <span class="table-label">客户列表</span> + <% if can? :export, EducodeSales::Customer %> + <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="export">导出</button> + <% end %> + <% if can? :modify_school_tag, EducodeSales::Customer %> + <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" id="modify_customer">批量修改客户类型</button> + <% end %> <% if can? :create, EducodeSales::Customer %> <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="add">添加客户</button> <% end %> <% if can? :give, EducodeSales::Customer %> <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="give">分配/移交</button> @@ -81,14 +87,15 @@ <a href="javascript:void(0);" lay-event="follow" class="layui-table-link">{{ d.follow }}</a> </script> <script> - layui.use(['form', 'table', 'miniPage', 'element', 'request', 'laydate'], function () { + layui.use(['form', 'table', 'miniPage', 'element', 'request', 'laydate', 'upload'], function () { var $ = layui.jquery, form = layui.form, request = layui.request, + upload = layui.upload, dropdown = layui.dropdown, miniPage = layui.miniPage, laydate = layui.laydate; var laydate = layui.laydate; @@ -112,16 +119,17 @@ laydate.render({ elem: '#time', }); table = layui.table; - table.render({ + var customer_table = table.render({ elem: '#customers_table', url: '/missions/customers', where: {q: form.val('search_teachers')}, toolbar: '#toolbarDemo', // totalRow:true, + title: '客户列表', defaultToolbar: ['filter'], cols: [ [ {type: 'checkbox'}, { @@ -184,10 +192,15 @@ ], limit: 20, limits: [10, 15, 20, 30, 40, 50, 60, 70, 80, 90], page: true, + done: function() { + if ($('#modify_customer').length > 0) { + uploadCustomer(); + } + } }); //监听表格复选框选择 table.on('checkbox(customers_table)', function (obj) { }); @@ -347,10 +360,26 @@ content: content, }); $(window).on("resize", function () { layer.full(index); }); + } else if (obj.event == 'export') { + layer.load(0, {}); + var data = form.val("search_teachers"); + var property = []; + property_list.getValue().forEach(function (d) { + property.push(d.value); + }) + data.property = property.toString(); + request.authGet("/missions/customers?=" + $.param({q:data}), { + }, function (res) { + data = res.data + table.exportFile(customer_table.config.id, data, 'xls'); + layer.closeAll('loading'); + }) + } else if (obj.event == 'modify_customer') { + } }); table.on('tool(customers_table)', function (obj) { @@ -501,13 +530,55 @@ layer.full(index); }); } }); + function uploadCustomer() { + upload.render({ + elem: '#modify_customer' + ,url: '/missions/customers/batch_update_school_tags' + ,accept: 'file' //普通文件 + ,acceptMime: 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.ms-excel' + ,headers: { + 'X-CSRF-Token': $('meta[name=csrf-token]').attr('content') + } + ,before: function(obj){ + layer.load(); + } + ,done: function(res){ + layer.msg('导入成功'); + table.reload('customers_table'); + layer.closeAll('loading'); //关闭loading + } + ,error: function(index, upload){ + table.reload('file'); + layer.closeAll('loading'); //关闭loading + layer.alert('导入失败,请检查文件格式') + layer.close(parent.import_index) + } + }); + } + if ($('#modify_customer').length > 0) { + var uploadTip; + $(document).on('mouseenter', '#modify_customer', function() { + uploadTip = layer.tips("<p style='color:#000;'>" + "导入Excel文件可批量修改客户性质。表格格式:客户名称 区域 性质。格式按导出的客户列表格式导入" + "</p>", + this, + { + tips:[1,'#f2f2f2'], + time:0, + area: 'auto', + maxWidth:500 + }); + }) + + $(document).on('mouseleave', '#modify_customer', function() { + layer.close(uploadTip); + }) + } + }); </script> <style> .layui-table-tool-temp { - padding-right: 30px; - !important; + padding-right: 30px; !important; } </style> \ No newline at end of file