123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- {extend name="public/layout" /} {block name="title"}小区导入{/block} {block name="body"}
- <style type="text/css">
- html,
- body {
- display: block;
- width: 100%;
- background-color: #fff;
- }
- .layui-icon {
- font-size: 18px !important;
- line-height: 38px;
- }
- .layui-table-view .layui-table th,
- .layui-table-view .layui-table td {
- text-align: center;
- border-color: #B6CADE;
- }
- .upload-img .area i {
- font-size: 50px;
- color: #009688;
- }
- .evi-block {
- float: left;
- margin-right: 10px;
- }
- /*///*/
- .addImages {
- display: inline-block;
- width: 140px;
- height: 125px;
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- box-sizing: border-box;
- border: 1px dashed darkgray;
- background: #f8f8f8;
- position: relative;
- overflow: hidden;
- }
- .text-detail {
- margin-top: 40px;
- text-align: center;
- }
- .text-detail>span {
- font-size: 40px;
- }
- .imageDiv div {
- width: 100%;
- height: 100%;
- position: absolute;
- top: 0px;
- background-color: #e6e6e600;
- }
- .imageDiv div i {
- display: none;
- font-size: 31px;
- position: absolute;
- top: 37%;
- left: 40%;
- }
- .imageDiv div:hover {
- background-color: #e6e6e680;
- }
- .imageDiv div:hover i {
- display: block;
- cursor: pointer;
- }
- .layui-card-header p a:hover {
- text-decoration-line: underline;
- }
- .clearfix::after {
- clear: both;
- content: ' ';
- display: table;
- }
- .clearfix::before {
- content: ' ';
- display: table;
- }
- .left {
- float: left;
- }
- .templetbox {
- display: block;
- width: 80px;
- height: 80px;
- border:unset;
- text-align: center;
- background-color: #fff;
- box-shadow: 0 0 10px 6px rgba(209,205,205,0.2);
- cursor: pointer;
- }
- .templetbox img {
- display: block;
- width: 40px;
- margin: 14px auto 4px;
- }
- .templetbox span,
- .templetbox button {
- display: block;
- width: 100%;
- text-align: center;
- font-size: 12px;
- color: #384855;
- height: 20px;
- background-color: transparent;
- line-height: 20px;
- }
- .leftextbox {
- color: #249efb;
- font-size: 14px;
- line-height: 88px;
- margin-right: 32px;
- }
- .uploadbox {
- margin-left: 40px;
- }
- .noticebox {
- margin-top: 40px;
- }
- .sourcebox {
- margin-top: 40px;
- }
- .sourcebtn {
- padding-left: 0;
- width: auto;
- }
- .sourceinput {
- margin-left: 84px;
- }
- .width33_3{
- width: 33.333%;
- }
- .resultbox{
- display: block;
- border: 1px solid #e6e6e6;
- margin-top: 24px;
- padding: 16px 0;
- }
- .everyresultbox{
- height: 48px;
- border-right: 1px solid #e6e6e6;
- box-sizing: border-box;
- text-align: center;
- line-height: 48px;
- }
- .resultbox .everyresultbox:last-child{
- border: unset;
- }
- .numbox{
- height: 18px;
- font-size: 12px;
- padding: 0 2px;
- background-color: #249efb;
- color: #fff;
- line-height: 18px;
- margin-right: 4px;
- border-radius: 4px;
- }
- .sourcebox .layui-form-select{width:50%;display: inline-block;}
- .layui-form-select dl{max-height: 200px;}
- </style>
- <body>
- <div class="layui-fluid">
- <div class="layui-card">
- <div class="layui-card-body">
- <form class="layui-form">
- <div class="layui-upload">
- <div class="clearfix">
- <div class="left clearfix">
- <div class="left leftextbox">小区模板</div>
- <a class="left templetbox" href="../../static/communityTemplate.xlsx" download>
- <img src="__STATIC__/img/file.png" />
- <span>下载模板</span>
- </a>
- </div>
- <div class="left uploadbox">
- <div class="left leftextbox">选择小区数据</div>
- <!--<button type="button" class="left templetbox" id="excelfile">
- <img src="__STATIC__/img/upload.png" />
- <span>上传文档</span>
- </button>-->
- <div class="left templetbox" id="excelfile" style="cursor: pointer;" href>
- <img src="__STATIC__/img/upload.png" />
- <span>上传文档</span>
- <input type="file" hidden id="xlsx-file" accept=".xls,.xlsx" />
- </div>
- <span class="layui-inline layui-upload-choose filename" style="line-height: 80px;"></span>
- </div>
- </div>
- <p class="noticebox" style="color:red"><span>注意:仅支持xlsx、xls格式,若未按照规范,则可能造成导入失败</span></p>
- </div>
- <div class="layui-form-item ">
- <button class="layui-btn submitbox" lay-submit style="float:right"
- lay-filter="submit">开始上传</button>
- </div>
- </form>
- </div>
- </div>
- <div class="resultbox clearfix" style="display:none;">
- <div class="left width33_3 everyresultbox">
- <span class="numbox badphone">0</span>
- <span>无效线索数</span>
- </div>
- <div class="left width33_3 everyresultbox">
- <span class="numbox avaliable">0</span>
- <span>有效线索数</span>
- </div>
- <div class="left width33_3 everyresultbox">
- <span class="numbox repeat">0</span>
- <span>重复数</span>
- </div>
- </div>
- <div id="loadings" hidden><span style="color:black;margin: 43%;">上传中请稍后...</span></div>
- </div>
- </body>
- {/block} {block name="js"}
- <script src="__STATIC__/js/xlsx.core.min.js"></script>
- <!-- <script type="text/javascript" src="__STATIC__/js/plupload/js/plupload.full.min.js"></script> -->
- <script>
- layui.config({
- base: '__LAYUI__/' //静态资源所在路径
- ,
- urlbase: '/sys'
- }).extend({
- index: 'lib/index' //主入口模块
- }).use(['index', 'form', 'upload'], function () {
- var $ = layui.$,
- form = layui.form,
- upload = layui.upload;
- var requestAjax = function (url, data) {
- $.post(url, data, function (res) {
- if (res.code === 0) {
- layer.msg(res.msg, {
- icon: 1,
- time: 2000
- }, function () {
- location.reload();
- });
- } else {
- layer.msg(res.msg, {
- icon: 0,
- time: 2000
- });
- }
- })
- }
-
- function isPhoneNum(phone) {
- 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})$/;
- if (!myreg.test(phone)) {
- return false;
- }
- return true;
- }
- function uniqueArray(arr) {
- const newArr = [];
- const tmp = new Map();
- for (let i = 0; i < arr.length; i++) {
- if (!tmp.get(arr[i].phone)) {
- tmp.set(arr[i].phone, 1);
- newArr.push(arr[i])
- }
- }
- return newArr;
- }
- $('#excelfile').click(function(){
- $('#xlsx-file')[0].click()
- })
- var fileobj='';
- $('#xlsx-file').change(function(e) {
- fileobj = e.target.files;
- var fileReader = new FileReader();
- $('.filename').html(fileobj[0].name);
- fileReader.readAsDataURL(document.querySelector('#xlsx-file').files[0])
- fileReader.onload = function(ev) {
- try {
- // console.log( ev.target.result)
- } catch (e) {
- console.log('文件类型不正确');
- return;
- }
- };
- });
-
- var log_id='',allnum=0,invalidnum=0,repeatnum=0;
- form.on('submit(submit)', function (obj) {
- if(!fileobj){
- layer.msg("数据不能为空!", {time: 1000});
- return false;
- }
-
- $(obj.elem).addClass('layui-btn layui-btn-disabled');
- var myMsg = layer.msg("数据上传中...", {
- icon: 16,
- time: -1,
- shade: 0.01
- })
-
- var fileReader = new FileReader();
- // fileReader.readAsDataURL(document.querySelector('#xlsx-file').files[0])
- fileReader.onload = function(ev) {
- var data = ev.target.result;
- try {
- var data = ev.target.result,
- workbook = XLSX.read(data, {
- type: 'binary'
- }), // 以二进制流方式读取得到整份excel表格对象
- persons = []; // 存储获取到的数据
- } catch (e) {
- console.log('文件类型不正确');
- return;
- }
-
-
- // 表格的表格范围,可用于判断表头是否数量是否正确
- var fromTo = '';
- // 遍历每张表读取
- for (var sheet in workbook.Sheets) {
- if (workbook.Sheets.hasOwnProperty(sheet)) {
- fromTo = workbook.Sheets[sheet]['!ref'];
- // console.log(fromTo);
- var arr=XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);
- var arrn=[];
- for (var i = 0; i < arr.length; i++) {
- var obj = {
- name: !arr[i]['小区名称'] ? '' : arr[i]['小区名称'],
- households: !arr[i]['户数'] ? '' : arr[i]['户数'],
- province: !arr[i]['省'] ? '' : arr[i]['省'],
- city: !arr[i]['市'] ? '' : arr[i]['市'],
- area: !arr[i]['区'] ? '' : arr[i]['区'],
- duetime: !arr[i]['交房时间'] ? '' : arr[i]['交房时间'],
- users: !arr[i]['活跃用户'] ? '' : arr[i]['活跃用户'],
- };
- arrn.push(obj);
- }
- // 插入到数组中
- persons = persons.concat(arrn);
- // 在这里便利数组格式不对就把无效数量+1,
- //break; // 如果只取第一张表,就取消注释这行
- }
- }
- console.log(persons)
- //在控制台打印出来表格中的数
- allnum=persons.length*1;
- $.ajax({
- type: 'post',
- url: '{:url("material/importCommunityLog")}',
- data: {
- 'file_name':fileobj[0].name,//文件名,
- 'count':persons.length*1,
- },
- dataType: 'json',
- success: function (data) {
- if (data.code === 0) {
- log_id=data.data;
- crmsourceadd(0,persons,myMsg)
- } else {
- layer.msg(data.msg, {
- anim: 6
- , time: 2000
- });
- }
-
- }
- })
- };
- fileReader.readAsBinaryString(fileobj[0]);
- return false;
- })
- function crmsourceadd(num,persons,myMsg){
- if (!persons.length) {
- layer.msg('Excel数据为空,请检查导入数据内容', {
- anim: 6
- , time: 2000
- });
- return;
- }
- var index = parent.layer.getFrameIndex(window.name);
- let n= num*20,nextnum= (num*1+1) * 20-1;
- var arr=[];
- for(var i= n;i<= nextnum;i++){
- arr.push(persons[i]);
- }
- if(arr.length==0){
- return false;
- }
- $.ajax({
- type: 'post',
- url: '{:url("material/importCommunityAdd")}',
- data: {
- log_id: log_id,
- content: arr
- },
- dataType: 'json',
- success: function (data) {
-
- if(persons.length- (num*1+1) * 20 <= 0){
- layer.close(myMsg);//手动关闭
- repeatnum = repeatnum * 1 + data.data.repeat * 1;
- invalidnum = invalidnum * 1 + data.data.error * 1;
- if(data.code === 0){
- layer.msg(data.msg, {
- anim: 0
- , time: 2000
- }, function () {
- parent.layui.table.reload('pool_customer_table'); //重载表格
- parent.layer.close(index); //再执行关闭
- });
- } else {
- layer.msg(data.msg, {
- anim: 6
- , time: 2000
- });
-
- }
- if(data){
- $('.resultbox').show();
- $('.avaliable').html(allnum-invalidnum-repeatnum);
- $('.badphone').html(invalidnum);
- $('.repeat').html(repeatnum);
- }
- }else{
- repeatnum = repeatnum * 1 + data.data.repeat * 1;
- invalidnum = invalidnum * 1 + data.data.error * 1;
- crmsourceadd(num * 1 + 1, persons, myMsg)
-
-
- }
-
-
- }
- })
- }
-
- });
- </script>
- {/block}
|