import-users.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <style>
  2. .table-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. }
  6. .tag-item {
  7. margin-right: 5px;
  8. }
  9. .btn {
  10. margin: 0;
  11. padding: 0;
  12. border: 1px solid transparent;
  13. outline: none;
  14. color: #409EFF;
  15. font-size: 14px;
  16. cursor: pointer;
  17. }
  18. .el-step__title.is-finish {
  19. position: absolute;
  20. left: -18px;
  21. }
  22. .el-step__title.is-process {
  23. position: absolute;
  24. left: -18px;
  25. }
  26. .el-step__title.is-wait {
  27. position: absolute;
  28. left: -18px;
  29. }
  30. </style>
  31. <div id="app" v-cloak>
  32. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  33. <div slot="header">
  34. <div>
  35. <span>用户导入</span>
  36. <el-button @click="$navigate({r:'mall/user/user-batch-send-model'})" style="margin-left: 20px;" size="small">批量导入模板下载</el-button>
  37. </div>
  38. </div>
  39. <div class="table-body">
  40. <el-steps style="margin-left: 10px" :space="300" :active="active">
  41. <el-step title="选择文件">
  42. <template slot="icon">
  43. <img src="resources/img/mall/goods/finish-2.png">
  44. </template>
  45. </el-step>
  46. <el-step title="导入数据">
  47. <template slot="icon">
  48. <img v-if="active > 1" src="resources/img/mall/goods/finish-2.png">
  49. </template>
  50. </el-step>
  51. <el-step title="导入完成">
  52. <template class="is-success" slot="icon">
  53. <img v-if="active > 2" src="resources/img/mall/goods/finish-2.png">
  54. </template>
  55. </el-step>
  56. </el-steps>
  57. <template v-if="active <= 2">
  58. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px"
  59. style="margin-top: 30px;width: 600px">
  60. <el-form-item></el-form-item>
  61. <el-form-item></el-form-item>
  62. <el-form-item label="上传数据" prop="file">
  63. <template slot="label">
  64. <span>上传数据</span>
  65. <el-tooltip effect="dark" content="仅支持上传csv格式"
  66. placement="top">
  67. <i class="el-icon-info"></i>
  68. </el-tooltip>
  69. </template>
  70. <label>{{ruleForm.file ? ruleForm.file.name : ''}}</label>
  71. <el-upload
  72. action=""
  73. :multiple="false"
  74. :http-request="handleFile"
  75. :on-change="excelChange"
  76. :show-file-list="false">
  77. <span style="color: #409EFF;">选择本地文件</span>
  78. </el-upload>
  79. <div style="color: #ff0000;">注:一次最多导入5000条数据</div>
  80. </el-form-item>
  81. <el-form-item>
  82. <!-- <el-button :loading="btnLoading" type="primary" @click="submit('ruleForm',0)" size="small">一键导入
  83. </el-button> -->
  84. <el-button :loading="btnLoading" type="primary" @click="submit('ruleForm',1)" size="small">异步导入
  85. </el-button>
  86. </el-form-item>
  87. </el-form>
  88. </template>
  89. <template v-else>
  90. <div style="width: 600px;height: 200px" flex="dir:top cross:center main:center">
  91. <div flex="dir:left cross:center">
  92. <img src="resources/img/mall/goods/finish-1.png">
  93. <span style="margin-left: 10px">成功导入{{successCount}}条数据</span>
  94. <a class="btn" style="margin-left: 10px;" href="index.php?r=mall/user/index" >返回会员列表</a>
  95. <a class="btn" style="margin-left: 10px;" href="index.php?r=mall/user/import-users" >继续导入</a>
  96. </div>
  97. <div v-if="errorCount > 0" style="margin-top: 20px;">
  98. <span>导入失败<span style="color: red;">{{errorCount}}</span>条数据</span>
  99. <span style="color: #409EFF;margin-left: 10px;"></span>
  100. </div>
  101. </div>
  102. </template>
  103. <el-dialog
  104. :before-close="beforeClose"
  105. :close-on-click-modal="false"
  106. title="上传"
  107. :visible.sync="importDialogVisible"
  108. width="20%">
  109. <template>
  110. <el-progress :text-inside="true" :stroke-width="18"
  111. :percentage="importParams.percentage"></el-progress>
  112. </template>
  113. </el-dialog>
  114. </div>
  115. </el-card>
  116. <div class="table-body" v-loading="loading">
  117. <p style="margin-right: 30px;">导入记录</p>
  118. <el-table class="table-info" :data="temp_list" style="width: 100%">
  119. <el-table-column
  120. label="序号"
  121. min-width="100"
  122. align="center"
  123. prop="id"
  124. >
  125. </el-table-column>
  126. <el-table-column
  127. label="导入时间"
  128. min-width="300" align="center">
  129. <template slot-scope="scope">
  130. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  131. </template>
  132. </el-table-column>
  133. <el-table-column
  134. label="导入会员"
  135. prop="counts"
  136. min-width="200" align="center">
  137. </el-table-column>
  138. <el-table-column
  139. label="导入成功会员"
  140. prop="success_counts"
  141. min-width="200" align="center">
  142. </el-table-column>
  143. <el-table-column
  144. label="导入失败会员"
  145. prop="fail_counts"
  146. min-width="200" align="center">
  147. </el-table-column>
  148. <!-- <el-table-column-->
  149. <!-- label="导入状态"-->
  150. <!-- prop="status_text"-->
  151. <!-- min-width="300" align="center">-->
  152. <!-- </el-table-column>-->
  153. <el-table-column label="操作" min-width="200">
  154. <template slot-scope="scope">
  155. <el-button size="mini" type="text" v-if="scope.row.url != ''" @click="download_files(scope.row.url)">下载</el-button>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <div class="pagination flex flex-x-between">
  160. <el-pagination @current-change="pagination" background layout="prev, pager, next"
  161. :page-count="pageCount" :current-page="currentPage"></el-pagination>
  162. </div>
  163. </div>
  164. </div>
  165. <script type="module">
  166. const app = new Vue({
  167. el: '#app',
  168. data() {
  169. return {
  170. ruleForm: {
  171. file: '',
  172. file_path: '',
  173. },
  174. active: 1,
  175. rules: {
  176. file: [
  177. {required: true, message: '请上传文件', trigger: 'change'},
  178. ],
  179. },
  180. btnLoading: false,
  181. errorCount: 0,
  182. successCount: 0,
  183. importDialogVisible: false,
  184. importParams: {
  185. percentage: 0,
  186. current_num: 1,
  187. },
  188. listLoading: false,
  189. errorList : [],
  190. importVisible: false,
  191. success_progress: 0,
  192. fail_progress: 0,
  193. is_clear: 0,
  194. t1:'',
  195. user_import_log_id:'',
  196. url:'',
  197. temp_list:[],
  198. page: 1,
  199. pageCount: 0,
  200. currentPage: 0,
  201. total_count: 0,
  202. loading: '',
  203. }
  204. },
  205. created() {
  206. this.getTempList();
  207. },
  208. methods: {
  209. handleFile() {
  210. },
  211. excelChange(file, fileList) {
  212. this.ruleForm.file = file.raw;
  213. },
  214. submit(formName,sync) {
  215. this.$refs[formName].validate((valid) => {
  216. if (valid) {
  217. this.$confirm('是否确认导入?', '提示', {
  218. confirmButtonText: '确定',
  219. cancelButtonText: '取消',
  220. type: 'warning'
  221. }).then(() => {
  222. this.btnLoading = true;
  223. this.active += 1;
  224. this.importDialogVisible = true;
  225. this.submitAction(sync);
  226. }).catch(() => {
  227. });
  228. } else {
  229. console.log('error submit!!');
  230. return false;
  231. }
  232. });
  233. },
  234. submitAction(sync) {
  235. let self = this;
  236. let formData = new FormData();
  237. formData.append('file', this.ruleForm.file);
  238. formData.append('sync', sync);
  239. formData.append('current_num', this.importParams.current_num);
  240. formData.append('file_path', this.importParams.file_path ? this.importParams.file_path : '');
  241. request({
  242. header: {
  243. 'Content-Type': 'multipart/form-data'
  244. },
  245. params: {
  246. r: 'mall/user/import-users'
  247. },
  248. data: formData,
  249. method: 'post'
  250. }).then(e => {
  251. this.btnLoading = false;
  252. if (e.data.code === 0) {
  253. let data = e.data.data;
  254. self.successCount = data.success_counts;
  255. self.errorCount = data.fail_counts;
  256. this.importParams.percentage = ((self.successCount+self.errorCount)/data.counts)*100;
  257. if(self.errorCount>0){
  258. this.active=3;
  259. }
  260. self.importDialogVisible = false;
  261. location.reload();
  262. } else {
  263. this.importDialogVisible = false;
  264. this.$message.error(e.data.msg);
  265. }
  266. }).catch(e => {
  267. this.btnLoading = false;
  268. });
  269. },
  270. beforeClose() {
  271. if (this.importParams.percentage < 100) {
  272. this.$confirm('导入用户尚未完成, 是否确认关闭?', '警告', {
  273. confirmButtonText: '确定',
  274. cancelButtonText: '取消',
  275. type: 'warning'
  276. }).then(() => {
  277. this.importDialogVisible = false;
  278. navigateTo({r: 'mall/user/import-users'});
  279. }).catch(() => {
  280. });
  281. }
  282. },
  283. download_files(url){
  284. console.log(url);
  285. window.location.href=url;
  286. },
  287. getTempList() {
  288. this.loading = true;
  289. console.log(this.page);
  290. this.$request({
  291. params: {
  292. r: 'mall/user/get-user-import-log',
  293. },
  294. method: 'post',
  295. data: {
  296. page: this.page
  297. }
  298. }).then(e => {
  299. this.loading = false;
  300. if (e.data.code == 0) {
  301. this.temp_list = e.data.data.list;
  302. this.pageCount = e.data.data.page_count;
  303. this.currentPage = e.data.data.page;
  304. this.total_count = e.data.data.pagination.total_count;
  305. }
  306. });
  307. },
  308. pagination(currentPage) {
  309. this.checkedAll = false;
  310. this.selFormArr = [];
  311. this.page = currentPage;
  312. this.getTempList();
  313. },
  314. currentChange(e) { //分页点击
  315. this.page = e;
  316. this.getTempList();
  317. console.log(e, '这是他点击了那个页面');
  318. },
  319. },
  320. mounted: function () {
  321. }
  322. });
  323. </script>
  324. <style scoped>
  325. img {
  326. display: block;
  327. }
  328. .nav {
  329. background: #ffffff;
  330. border-radius: 5px;
  331. padding: 26px 24px;
  332. margin-bottom: 10px;
  333. /*color: #808695;*/
  334. }
  335. .cate_header {
  336. font-size: 14px;
  337. color: #808695;
  338. }
  339. .cate_title {
  340. margin-right: 24px;
  341. }
  342. .cate_item_active {
  343. color: #2DB7F5;
  344. background: #EDF6FF;
  345. }
  346. .template_body {
  347. background: #fff;
  348. border-radius: 0px 0 5px 5px;
  349. padding: 0px 49px 70px;
  350. }
  351. .template_item {
  352. width: 220px;
  353. margin: 0 38px 60px 0;
  354. cursor: pointer;
  355. }
  356. .template_img_box {
  357. width: 220px;
  358. height: 430px;
  359. /* border: 1px solid #BFBFBF; */
  360. border-radius: 18px;
  361. overflow: hidden;
  362. position: relative;
  363. background: url('resources/img/mall/decorate/duihuakuang240.png');
  364. background-size: 100% 100%;
  365. }
  366. .template_img_block {
  367. width: 95.7%;
  368. height: 399px;
  369. position: absolute;
  370. left: 50%;
  371. transform: translateX(-50%);
  372. top: 26px;
  373. border-radius: 0 0 15px 15px;
  374. overflow: hidden;
  375. }
  376. .template_img {
  377. width: 100%;
  378. position: absolute;
  379. left: 50%;
  380. transform: translateX(-50%);
  381. }
  382. .mask {
  383. background: rgba(0, 0, 0, 0.5);
  384. width: 100%;
  385. height: 100%;
  386. position: absolute;
  387. top: 0;
  388. left: 0;
  389. z-index: 5;
  390. opacity: 0;
  391. transition: all 0.3s;
  392. flex-direction: column;
  393. }
  394. .template_item:hover .mask {
  395. opacity: 1;
  396. }
  397. .temp_preview_small {
  398. width: 80px;
  399. height: 30px;
  400. border-radius: 5px;
  401. text-align: center;
  402. line-height: 30px;
  403. background: #ffffff;
  404. color: #313131;
  405. font-size: 12px;
  406. }
  407. .temp_preview {
  408. width: 170px;
  409. height: 30px;
  410. border-radius: 30px;
  411. background: #2DB7F5;
  412. color: #ffffff;
  413. text-align: center;
  414. line-height: 30px;
  415. font-size: 12px;
  416. margin-bottom: 8px;
  417. }
  418. .template_text {
  419. font-size: 14px;
  420. color: #515A6E;
  421. padding: 0 12px;
  422. }
  423. .template_title {
  424. margin: 10px 0 6px;
  425. }
  426. .use_number {
  427. font-size: 14px;
  428. align-items: center;
  429. color: #C5C8CE;
  430. }
  431. /* 公共样式 */
  432. .flex {
  433. display: -webkit-box;
  434. display: -webkit-flex;
  435. /* #ifndef APP-NVUE */
  436. display: flex;
  437. /* #endif */
  438. }
  439. .flex-x-center {
  440. display: -webkit-box;
  441. display: -webkit-flex;
  442. /* #ifndef APP-NVUE */
  443. display: flex;
  444. /* #endif */
  445. -webkit-box-pack: center;
  446. -webkit-justify-content: center;
  447. -ms-flex-pack: center;
  448. justify-content: center;
  449. }
  450. .flex-x-between {
  451. display: -webkit-box;
  452. display: -webkit-flex;
  453. /* #ifndef APP-NVUE */
  454. display: flex;
  455. /* #endif */
  456. -webkit-box-pack: space-between;
  457. -webkit-justify-content: space-between;
  458. -ms-flex-pack: space-between;
  459. justify-content: space-between;
  460. }
  461. .flex-y-center {
  462. display: -webkit-box;
  463. display: -webkit-flex;
  464. /* #ifndef APP-NVUE */
  465. display: flex;
  466. /* #endif */
  467. -webkit-box-align: center;
  468. -webkit-align-items: center;
  469. -ms-flex-align: center;
  470. -ms-grid-row-align: center;
  471. align-items: center;
  472. }
  473. /* 溢出隐藏 */
  474. .over1 {
  475. text-overflow: -o-ellipsis-lastline;
  476. overflow: hidden;
  477. text-overflow: ellipsis;
  478. display: -webkit-box;
  479. -webkit-line-clamp: 1;
  480. -webkit-box-orient: vertical;
  481. }
  482. .over2 {
  483. text-overflow: -o-ellipsis-lastline;
  484. overflow: hidden;
  485. text-overflow: ellipsis;
  486. display: -webkit-box;
  487. -webkit-line-clamp: 2;
  488. -webkit-box-orient: vertical;
  489. }
  490. .pagination {
  491. width: 100%;
  492. flex-direction: row-reverse;
  493. }
  494. .pop {
  495. position: absolute;
  496. width: 100%;
  497. height: 100%;
  498. top: 0;
  499. left: 0;
  500. background: rgba(0, 0, 0, 0.5);
  501. }
  502. /* 预览框 */
  503. .preview_box {
  504. width: 377px;
  505. height: 760px;
  506. background: url('statics/img/mall/decorate/duihuakuang.png')no-repeat;
  507. position: relative;
  508. }
  509. .preview_content {
  510. background: #ffffff;
  511. width: 357px;
  512. height: 696px;
  513. position: absolute;
  514. top: 56px;
  515. left: 50.2%;
  516. transform: translateX(-50%);
  517. border-radius: 0 0 37px 36px;
  518. scrollbar-width: none;
  519. /* firefox */
  520. -ms-overflow-style: none;
  521. /* IE 10+ */
  522. overflow-x: hidden;
  523. overflow-y: auto;
  524. }
  525. .preview_content::-webkit-scrollbar {
  526. display: none;
  527. /* Chrome Safari */
  528. }
  529. .preview_img {
  530. width: 100%;
  531. }
  532. .el-dialog__body {
  533. padding: 0;
  534. width: 377px;
  535. height: 760px;
  536. }
  537. .el-dialog__header {
  538. display: none;
  539. }
  540. .el-dialog {
  541. min-width: 377px;
  542. max-width: 377px;
  543. background: transparent;
  544. border: 0;
  545. box-shadow: none;
  546. }
  547. .header_box {
  548. padding: 25px;
  549. background: #fff;
  550. border-radius: 5px 5px 0 0;
  551. color: #808695;
  552. }
  553. .add_temp_right {
  554. width: 400px;
  555. }
  556. .el-card {
  557. background: transparent;
  558. box-shadow: none !important;
  559. border: 0;
  560. }
  561. .el-card__body {
  562. padding: 0;
  563. }
  564. .logo_text {
  565. width: 56px;
  566. height: 21px;
  567. border-radius: 30px;
  568. background: #FF7161;
  569. text-align: center;
  570. line-height: 21px;
  571. color: #fff;
  572. }
  573. .logo_text2 {
  574. background: #C5C8CE;
  575. }
  576. </style>