memberImport.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. .single-filter-box {justify-content: left;line-height: 34px}
  5. .single-filter-box a{cursor:pointer;margin-left: 10px}
  6. </style>
  7. {/block}
  8. {block name="main"}
  9. <div class="single-filter-box">
  10. <button class="layui-btn" id="member_file">导入会员</button>
  11. <a class="layui-btn layui-btn-primary" onclick="downloadMemberFile()">点击下载模板</a>
  12. </div>
  13. <!-- 列表 -->
  14. <table id="member_import_log_list" lay-filter="member_import_log_list"></table>
  15. <!-- 工具栏操作 -->
  16. <script type="text/html" id="operation">
  17. <div class="table-btn">
  18. <a class="layui-btn" lay-event="info">查看</a>
  19. </div>
  20. </script>
  21. {/block}
  22. {block name="script"}
  23. <script>
  24. var table,upload,repeat_flag = false;
  25. layui.use(['form', 'laydate','laytpl', 'upload'], function() {
  26. var form = layui.form,
  27. laydate = layui.laydate,
  28. currentDate = new Date(),
  29. laytpl = layui.laytpl,
  30. minDate = "";
  31. upload = layui.upload;
  32. form.render();
  33. /**
  34. * 表格加载
  35. */
  36. table = new Table({
  37. elem: '#member_import_log_list',
  38. url: ns.url("shop/member/memberImport"),
  39. cols: [
  40. [{
  41. field: 'create_time',
  42. title: '导入时间',
  43. width: '20%',
  44. unresize: 'false',
  45. }, {
  46. field: 'member_num',
  47. title: '导入会员数',
  48. width: '20%',
  49. unresize: 'false',
  50. }, {
  51. field: 'success_num',
  52. title: '导入成功会员数',
  53. width: '20%',
  54. unresize: 'false',
  55. }, {
  56. field: 'error_num',
  57. title: '导入失败会员数',
  58. width: '15%',
  59. unresize: 'false',
  60. },
  61. // {
  62. // field: 'status_name',
  63. // title: '导入状态',
  64. // width: '15%',
  65. // unresize: 'false',
  66. // },
  67. {
  68. title: '操作',
  69. unresize: 'false',
  70. toolbar: '#operation',
  71. align : 'right'
  72. }]
  73. ]
  74. });
  75. //允许上传的文件后缀
  76. upload.render({
  77. elem: '#member_file'
  78. ,url: ns.url("shop/member/file"),
  79. accept:'file',
  80. acceptMime: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  81. exts: 'xlsx',
  82. done: function(res){
  83. if (res.code >= 0) {
  84. member_import(1, res.data.name, res.data.path);
  85. repeat_flag = false;
  86. }else{
  87. layer.msg(res.message);
  88. }
  89. }
  90. });
  91. /**
  92. * 监听工具栏操作
  93. */
  94. table.tool(function(obj) {
  95. var data = obj.data;
  96. switch (obj.event) {
  97. case 'info': //查看
  98. location.href = ns.url("shop/member/memberimportlist?id=" + data.id);
  99. break
  100. }
  101. });
  102. });
  103. function member_import(index, name, path, success_num = 0, error_num = 0, record = 0){
  104. $.ajax({
  105. url: ns.url("shop/member/import"),
  106. data: {
  107. filename: name,
  108. path: path,
  109. index: index,
  110. success_num : success_num,
  111. error_num : error_num,
  112. record : record
  113. },
  114. dataType: 'JSON',
  115. type: 'POST',
  116. success: function (res) {
  117. index ++;
  118. if(res.code == 0){
  119. if(res.data.num < res.data.allRow){
  120. member_import(index, res.data.name, res.data.path, res.data.success_num, res.data.error_num, res.data.record);
  121. }else{
  122. table.reload();
  123. }
  124. }
  125. if(res.data.error_num > 0) {
  126. layer.msg('导入失败');
  127. } else {
  128. layer.msg('导入成功');
  129. }
  130. }
  131. });
  132. }
  133. function downloadMemberFile(){
  134. location.href = ns.url("shop/member/downloadMemberFile");
  135. return false;
  136. }
  137. </script>
  138. {/block}