importing.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. {extend name="public/layout" /} {block name="title"}客户导入{/block} {block name="body"}
  2. <style type="text/css">
  3. html,
  4. body {
  5. display: block;
  6. width: 100%;
  7. background-color: #fff;
  8. }
  9. .layui-icon {
  10. font-size: 18px !important;
  11. line-height: 38px;
  12. }
  13. .layui-table-view .layui-table th,
  14. .layui-table-view .layui-table td {
  15. text-align: center;
  16. border-color: #B6CADE;
  17. }
  18. .upload-img .area i {
  19. font-size: 50px;
  20. color: #009688;
  21. }
  22. .evi-block {
  23. float: left;
  24. margin-right: 10px;
  25. }
  26. /*///*/
  27. .addImages {
  28. display: inline-block;
  29. width: 140px;
  30. height: 125px;
  31. -webkit-box-sizing: border-box;
  32. -moz-box-sizing: border-box;
  33. box-sizing: border-box;
  34. border: 1px dashed darkgray;
  35. background: #f8f8f8;
  36. position: relative;
  37. overflow: hidden;
  38. }
  39. .text-detail {
  40. margin-top: 40px;
  41. text-align: center;
  42. }
  43. .text-detail>span {
  44. font-size: 40px;
  45. }
  46. .imageDiv div {
  47. width: 100%;
  48. height: 100%;
  49. position: absolute;
  50. top: 0px;
  51. background-color: #e6e6e600;
  52. }
  53. .imageDiv div i {
  54. display: none;
  55. font-size: 31px;
  56. position: absolute;
  57. top: 37%;
  58. left: 40%;
  59. }
  60. .imageDiv div:hover {
  61. background-color: #e6e6e680;
  62. }
  63. .imageDiv div:hover i {
  64. display: block;
  65. cursor: pointer;
  66. }
  67. .layui-card-header p a:hover {
  68. text-decoration-line: underline;
  69. }
  70. .clearfix::after {
  71. clear: both;
  72. content: ' ';
  73. display: table;
  74. }
  75. .clearfix::before {
  76. content: ' ';
  77. display: table;
  78. }
  79. .left {
  80. float: left;
  81. }
  82. .templetbox {
  83. display: block;
  84. width: 80px;
  85. height: 80px;
  86. border:unset;
  87. text-align: center;
  88. background-color: #fff;
  89. box-shadow: 0 0 10px 6px rgba(209,205,205,0.2);
  90. cursor: pointer;
  91. }
  92. .templetbox img {
  93. display: block;
  94. width: 40px;
  95. margin: 14px auto 4px;
  96. }
  97. .templetbox span,
  98. .templetbox button {
  99. display: block;
  100. width: 100%;
  101. text-align: center;
  102. font-size: 12px;
  103. color: #384855;
  104. height: 20px;
  105. background-color: transparent;
  106. line-height: 20px;
  107. }
  108. .leftextbox {
  109. color: #249efb;
  110. font-size: 14px;
  111. line-height: 88px;
  112. margin-right: 32px;
  113. }
  114. .uploadbox {
  115. margin-left: 40px;
  116. }
  117. .noticebox {
  118. margin-top: 40px;
  119. }
  120. .sourcebox {
  121. margin-top: 40px;
  122. }
  123. .sourcebtn {
  124. padding-left: 0;
  125. width: auto;
  126. }
  127. .sourceinput {
  128. margin-left: 84px;
  129. }
  130. .width33_3{
  131. width: 33.333%;
  132. }
  133. .resultbox{
  134. display: block;
  135. border: 1px solid #e6e6e6;
  136. margin-top: 24px;
  137. padding: 16px 0;
  138. }
  139. .everyresultbox{
  140. height: 48px;
  141. border-right: 1px solid #e6e6e6;
  142. box-sizing: border-box;
  143. text-align: center;
  144. line-height: 48px;
  145. }
  146. .resultbox .everyresultbox:last-child{
  147. border: unset;
  148. }
  149. .numbox{
  150. height: 18px;
  151. font-size: 12px;
  152. padding: 0 2px;
  153. background-color: #249efb;
  154. color: #fff;
  155. line-height: 18px;
  156. margin-right: 4px;
  157. border-radius: 4px;
  158. }
  159. .sourcebox .layui-form-select{width:50%;display: inline-block;}
  160. .layui-form-select dl{max-height: 200px;}
  161. </style>
  162. <body>
  163. <div class="layui-fluid">
  164. <div class="layui-card">
  165. <div class="layui-card-body">
  166. <form class="layui-form">
  167. <div class="layui-upload">
  168. <div class="clearfix">
  169. <div class="left clearfix">
  170. <div class="left leftextbox">客户信息模板</div>
  171. <a class="left templetbox" href="../../static/customerRemove.xlsx" download>
  172. <img src="__STATIC__/img/file.png" />
  173. <span>下载模板</span>
  174. </a>
  175. </div>
  176. <div class="left uploadbox">
  177. <div class="left leftextbox">导入客户</div>
  178. <div class="left templetbox" id="excelfile" style="cursor: pointer;" href>
  179. <img src="__STATIC__/img/upload.png" />
  180. <span>上传文档</span>
  181. <input type="file" hidden id="xlsx-file" accept=".xls,.xlsx" />
  182. </div>
  183. <span class="layui-inline layui-upload-choose filename" style="line-height: 80px;"></span>
  184. </div>
  185. </div>
  186. <p class="noticebox" style="color:red"><span>注意:仅支持xlsx、xls格式,若未按照规范,则可能造成导入失败</span></p>
  187. </div>
  188. <div class="layui-form-item ">
  189. <button class="layui-btn submitbox" lay-submit style="float:right"
  190. lay-filter="submit">上传</button>
  191. <div class="layui-btn reloadTable" style="float: right;margin-right: 6px;">刷新</div>
  192. </div>
  193. </form>
  194. </div>
  195. </div>
  196. <div id="loadings" class="layui-hide"><span style="color:black;margin: 43%;white-space: nowrap;">正在上传数据,需要一些时间,请稍后...</span></div>
  197. <table id="cluelist" lay-filter="cluelist"></table>
  198. </div>
  199. </body>
  200. {/block} {block name="js"}
  201. <script src="__STATIC__/js/xlsx.core.min.js"></script>
  202. <script type="text/html" id="status">
  203. {{# if(d.status == 0){ }}
  204. <span>未开始</span>
  205. {{# } }}
  206. {{# if(d.status == 1){ }}
  207. <span style="color: orange;">导入中</span>
  208. {{# } }}
  209. {{# if(d.status == 2){ }}
  210. <span style="color: #009688;">已完成</span>
  211. {{# } }}
  212. {{# if(d.status == 3){ }}
  213. <span style="color: red;">导入失败</span>
  214. {{# } }}
  215. </script>
  216. <script type="text/html" id="act">
  217. {{# if(d.status == 0){ }}
  218. <a class="layui-btn layui-btn-xs" lay-event="add">导入</a>
  219. {{# } }}
  220. </script>
  221. <script>
  222. layui.config({
  223. base: '__LAYUI__/' //静态资源所在路径
  224. ,
  225. urlbase: '/sys'
  226. }).extend({
  227. index: 'lib/index' //主入口模块
  228. }).use(['index', 'form', 'upload', 'table'], function () {
  229. var $ = layui.$,
  230. form = layui.form,
  231. upload = layui.upload,
  232. table = layui.table;
  233. $('#excelfile').click(function(){
  234. $('#xlsx-file')[0].click()
  235. })
  236. var fileobj='';
  237. $('#xlsx-file').change(function(e) {
  238. fileobj = e.target.files;
  239. var fileReader = new FileReader();
  240. $('.filename').html(fileobj[0].name);
  241. fileReader.readAsDataURL(document.querySelector('#xlsx-file').files[0])
  242. fileReader.onload = function(ev) {
  243. try {
  244. // console.log( ev.target.result)
  245. } catch (e) {
  246. console.log('文件类型不正确');
  247. return;
  248. }
  249. };
  250. });
  251. table.render({
  252. elem: '#cluelist'
  253. , url: '{:url("crm_remove/importing")}' //数据接口
  254. , page: true //开启分页
  255. ,height: 'full-160'
  256. ,limit:30
  257. , autoSort: false
  258. , cols: [[ //表头
  259. { field: 'name', title: '导入文件名'}
  260. , { field: 'count', title: '读取资源数'}
  261. , { field: 'avaliable_count', title: '有效线索资源数'}
  262. , { field: 'bad_phone_num', title: '无效线索资源数'}
  263. , { field: 'addtime', title: '导入时间',}
  264. , { field: 'status', title: '导入状态' ,templet:'#status'}
  265. , { field: '', title: '操作' ,templet:'#act'}
  266. ]]
  267. });
  268. $(".reloadTable").click(function() {
  269. table.reload('cluelist');
  270. })
  271. table.on('tool(cluelist)', function (obj) {
  272. var id = obj.data.id;
  273. var layEvent = obj.event;
  274. if (layEvent === 'add') {
  275. //layer.msg("数据上传中,请手动刷新上传结果", {time: 1000});
  276. add_on(id);
  277. setTimeout(function(){
  278. table.reload('cluelist');
  279. }, 1000)
  280. //myMsg(1)
  281. }
  282. })
  283. function add_on(log_id) {
  284. $.ajax({
  285. url: '{:url("crm_remove/add")}',
  286. type: 'post',
  287. data: {log_id: log_id},
  288. success: function (res) {
  289. if (res.code == 0) {
  290. layer.msg(res.msg);
  291. } else if (res.code == 1) {
  292. $("#loadings").addClass('layui-hide');
  293. layer.msg(res.msg)
  294. }
  295. }
  296. });
  297. }
  298. var allnum=0,invalidnum=0,repeatnum=0,avaliablenum=0;
  299. form.on('submit(submit)', function (obj) {
  300. if(!fileobj){
  301. layer.msg("数据不能为空!", {time: 1000});
  302. return false;
  303. }
  304. $(obj.elem).addClass('layui-btn layui-btn-disabled');
  305. let formData = new FormData();
  306. formData.append("file", fileobj[0]);
  307. $.ajax({
  308. url: '{:url("crm_remove/importLog")}',
  309. type: 'post',
  310. data: formData,
  311. dataType: 'json',
  312. processData: false,
  313. contentType: false,
  314. success: function (res) {
  315. $(obj.elem).removeClass('layui-btn-disabled');
  316. $("#loadings").addClass('layui-hide');
  317. if (res.code === 0) {
  318. setTimeout(() => {
  319. table.reload('cluelist');
  320. },2000)
  321. fileobj = null;
  322. $("#xlsx-file").val("");
  323. $(".filename").html("")
  324. layer.msg(res.msg);
  325. } else {
  326. layer.msg(res.msg, {
  327. anim: 6
  328. , time: 2000
  329. });
  330. }
  331. }
  332. });
  333. return false;
  334. })
  335. });
  336. </script>
  337. {/block}