importing_community.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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/communityTemplate.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. <!--<button type="button" class="left templetbox" id="excelfile">
  179. <img src="__STATIC__/img/upload.png" />
  180. <span>上传文档</span>
  181. </button>-->
  182. <div class="left templetbox" id="excelfile" style="cursor: pointer;" href>
  183. <img src="__STATIC__/img/upload.png" />
  184. <span>上传文档</span>
  185. <input type="file" hidden id="xlsx-file" accept=".xls,.xlsx" />
  186. </div>
  187. <span class="layui-inline layui-upload-choose filename" style="line-height: 80px;"></span>
  188. </div>
  189. </div>
  190. <p class="noticebox" style="color:red"><span>注意:仅支持xlsx、xls格式,若未按照规范,则可能造成导入失败</span></p>
  191. </div>
  192. <div class="layui-form-item ">
  193. <button class="layui-btn submitbox" lay-submit style="float:right"
  194. lay-filter="submit">开始上传</button>
  195. </div>
  196. </form>
  197. </div>
  198. </div>
  199. <div class="resultbox clearfix" style="display:none;">
  200. <div class="left width33_3 everyresultbox">
  201. <span class="numbox badphone">0</span>
  202. <span>无效线索数</span>
  203. </div>
  204. <div class="left width33_3 everyresultbox">
  205. <span class="numbox avaliable">0</span>
  206. <span>有效线索数</span>
  207. </div>
  208. <div class="left width33_3 everyresultbox">
  209. <span class="numbox repeat">0</span>
  210. <span>重复数</span>
  211. </div>
  212. </div>
  213. <div id="loadings" hidden><span style="color:black;margin: 43%;">上传中请稍后...</span></div>
  214. </div>
  215. </body>
  216. {/block} {block name="js"}
  217. <script src="__STATIC__/js/xlsx.core.min.js"></script>
  218. <!-- <script type="text/javascript" src="__STATIC__/js/plupload/js/plupload.full.min.js"></script> -->
  219. <script>
  220. layui.config({
  221. base: '__LAYUI__/' //静态资源所在路径
  222. ,
  223. urlbase: '/sys'
  224. }).extend({
  225. index: 'lib/index' //主入口模块
  226. }).use(['index', 'form', 'upload'], function () {
  227. var $ = layui.$,
  228. form = layui.form,
  229. upload = layui.upload;
  230. var requestAjax = function (url, data) {
  231. $.post(url, data, function (res) {
  232. if (res.code === 0) {
  233. layer.msg(res.msg, {
  234. icon: 1,
  235. time: 2000
  236. }, function () {
  237. location.reload();
  238. });
  239. } else {
  240. layer.msg(res.msg, {
  241. icon: 0,
  242. time: 2000
  243. });
  244. }
  245. })
  246. }
  247. function isPhoneNum(phone) {
  248. var myreg =/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
  249. if (!myreg.test(phone)) {
  250. return false;
  251. }
  252. return true;
  253. }
  254. function uniqueArray(arr) {
  255. const newArr = [];
  256. const tmp = new Map();
  257. for (let i = 0; i < arr.length; i++) {
  258. if (!tmp.get(arr[i].phone)) {
  259. tmp.set(arr[i].phone, 1);
  260. newArr.push(arr[i])
  261. }
  262. }
  263. return newArr;
  264. }
  265. $('#excelfile').click(function(){
  266. $('#xlsx-file')[0].click()
  267. })
  268. var fileobj='';
  269. $('#xlsx-file').change(function(e) {
  270. fileobj = e.target.files;
  271. var fileReader = new FileReader();
  272. $('.filename').html(fileobj[0].name);
  273. fileReader.readAsDataURL(document.querySelector('#xlsx-file').files[0])
  274. fileReader.onload = function(ev) {
  275. try {
  276. // console.log( ev.target.result)
  277. } catch (e) {
  278. console.log('文件类型不正确');
  279. return;
  280. }
  281. };
  282. });
  283. var log_id='',allnum=0,invalidnum=0,repeatnum=0;
  284. form.on('submit(submit)', function (obj) {
  285. if(!fileobj){
  286. layer.msg("数据不能为空!", {time: 1000});
  287. return false;
  288. }
  289. $(obj.elem).addClass('layui-btn layui-btn-disabled');
  290. var myMsg = layer.msg("数据上传中...", {
  291. icon: 16,
  292. time: -1,
  293. shade: 0.01
  294. })
  295. var fileReader = new FileReader();
  296. // fileReader.readAsDataURL(document.querySelector('#xlsx-file').files[0])
  297. fileReader.onload = function(ev) {
  298. var data = ev.target.result;
  299. try {
  300. var data = ev.target.result,
  301. workbook = XLSX.read(data, {
  302. type: 'binary'
  303. }), // 以二进制流方式读取得到整份excel表格对象
  304. persons = []; // 存储获取到的数据
  305. } catch (e) {
  306. console.log('文件类型不正确');
  307. return;
  308. }
  309. // 表格的表格范围,可用于判断表头是否数量是否正确
  310. var fromTo = '';
  311. // 遍历每张表读取
  312. for (var sheet in workbook.Sheets) {
  313. if (workbook.Sheets.hasOwnProperty(sheet)) {
  314. fromTo = workbook.Sheets[sheet]['!ref'];
  315. // console.log(fromTo);
  316. var arr=XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
  317. var arrn=[];
  318. for (var i = 0; i < arr.length; i++) {
  319. var obj = {
  320. name: !arr[i]['小区名称'] ? '' : arr[i]['小区名称'],
  321. households: !arr[i]['户数'] ? '' : arr[i]['户数'],
  322. province: !arr[i]['省'] ? '' : arr[i]['省'],
  323. city: !arr[i]['市'] ? '' : arr[i]['市'],
  324. area: !arr[i]['区'] ? '' : arr[i]['区'],
  325. duetime: !arr[i]['交房时间'] ? '' : arr[i]['交房时间'],
  326. users: !arr[i]['活跃用户'] ? '' : arr[i]['活跃用户'],
  327. };
  328. arrn.push(obj);
  329. }
  330. // 插入到数组中
  331. persons = persons.concat(arrn);
  332. // 在这里便利数组格式不对就把无效数量+1,
  333. //break; // 如果只取第一张表,就取消注释这行
  334. }
  335. }
  336. console.log(persons)
  337. //在控制台打印出来表格中的数
  338. allnum=persons.length*1;
  339. $.ajax({
  340. type: 'post',
  341. url: '{:url("material/importCommunityLog")}',
  342. data: {
  343. 'file_name':fileobj[0].name,//文件名,
  344. 'count':persons.length*1,
  345. },
  346. dataType: 'json',
  347. success: function (data) {
  348. if (data.code === 0) {
  349. log_id=data.data;
  350. crmsourceadd(0,persons,myMsg)
  351. } else {
  352. layer.msg(data.msg, {
  353. anim: 6
  354. , time: 2000
  355. });
  356. }
  357. }
  358. })
  359. };
  360. fileReader.readAsBinaryString(fileobj[0]);
  361. return false;
  362. })
  363. function crmsourceadd(num,persons,myMsg){
  364. if (!persons.length) {
  365. layer.msg('Excel数据为空,请检查导入数据内容', {
  366. anim: 6
  367. , time: 2000
  368. });
  369. return;
  370. }
  371. var index = parent.layer.getFrameIndex(window.name);
  372. let n= num*20,nextnum= (num*1+1) * 20-1;
  373. var arr=[];
  374. for(var i= n;i<= nextnum;i++){
  375. arr.push(persons[i]);
  376. }
  377. if(arr.length==0){
  378. return false;
  379. }
  380. $.ajax({
  381. type: 'post',
  382. url: '{:url("material/importCommunityAdd")}',
  383. data: {
  384. log_id: log_id,
  385. content: arr
  386. },
  387. dataType: 'json',
  388. success: function (data) {
  389. if(persons.length- (num*1+1) * 20 <= 0){
  390. layer.close(myMsg);//手动关闭
  391. repeatnum = repeatnum * 1 + data.data.repeat * 1;
  392. invalidnum = invalidnum * 1 + data.data.error * 1;
  393. if(data.code === 0){
  394. layer.msg(data.msg, {
  395. anim: 0
  396. , time: 2000
  397. }, function () {
  398. parent.layui.table.reload('pool_customer_table'); //重载表格
  399. parent.layer.close(index); //再执行关闭
  400. });
  401. } else {
  402. layer.msg(data.msg, {
  403. anim: 6
  404. , time: 2000
  405. });
  406. }
  407. if(data){
  408. $('.resultbox').show();
  409. $('.avaliable').html(allnum-invalidnum-repeatnum);
  410. $('.badphone').html(invalidnum);
  411. $('.repeat').html(repeatnum);
  412. }
  413. }else{
  414. repeatnum = repeatnum * 1 + data.data.repeat * 1;
  415. invalidnum = invalidnum * 1 + data.data.error * 1;
  416. crmsourceadd(num * 1 + 1, persons, myMsg)
  417. }
  418. }
  419. })
  420. }
  421. });
  422. </script>
  423. {/block}