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