Authored by htoooth

import

@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 7
8 <script> 8 <script>
9 import request from 'axios'; 9 import request from 'axios';
  10 + import _ from 'lodash';
10 11
11 export default { 12 export default {
12 name: 'XlsxUpload', 13 name: 'XlsxUpload',
@@ -40,6 +41,12 @@ @@ -40,6 +41,12 @@
40 default() { 41 default() {
41 return {}; 42 return {};
42 } 43 }
  44 + },
  45 + data: {
  46 + type: Object,
  47 + default() {
  48 + return {};
  49 + }
43 } 50 }
44 }, 51 },
45 data() { 52 data() {
@@ -55,7 +62,7 @@ @@ -55,7 +62,7 @@
55 this.files = e.target.files; 62 this.files = e.target.files;
56 this.onChange(this.files); 63 this.onChange(this.files);
57 }, 64 },
58 - upload() { 65 + upload(data) {
59 let files = this.files; 66 let files = this.files;
60 let postFiles = Array.prototype.slice.call(files); 67 let postFiles = Array.prototype.slice.call(files);
61 68
@@ -65,12 +72,14 @@ @@ -65,12 +72,14 @@
65 return; 72 return;
66 } 73 }
67 74
68 - return this.post(postFiles[0]); 75 + Object.assign(this.data, data);
  76 +
  77 + return this.post(postFiles[0], this.data);
69 }, 78 },
70 clear() { 79 clear() {
71 this.files = null; 80 this.files = null;
72 }, 81 },
73 - post(file) { 82 + post(file, params) {
74 let _this = this; 83 let _this = this;
75 let config = { 84 let config = {
76 onUploadProgress(processEvent) { 85 onUploadProgress(processEvent) {
@@ -81,6 +90,12 @@ @@ -81,6 +90,12 @@
81 90
82 data.append('file', file); 91 data.append('file', file);
83 92
  93 + if (!_.isEmpty(params)) {
  94 + _.each(params, (v, k) => {
  95 + data.append(k, v);
  96 + });
  97 + }
  98 +
84 return request.post(this.action, data, config) 99 return request.post(this.action, data, config)
85 .then((result) => { 100 .then((result) => {
86 _this.onSuccess(result.data); 101 _this.onSuccess(result.data);
@@ -27,8 +27,14 @@ @@ -27,8 +27,14 @@
27 <Option v-for="item in operator.list" :value="item.id" :key="item">{{ item.label }}</Option> 27 <Option v-for="item in operator.list" :value="item.id" :key="item">{{ item.label }}</Option>
28 </Select> 28 </Select>
29 </FilterItem> 29 </FilterItem>
  30 +
  31 + <FilterItem label="品牌">
  32 + <SelectBrand v-model="brandId"></SelectBrand>
  33 + </FilterItem>
  34 +
30 <FilterItem label="上传文件"> 35 <FilterItem label="上传文件">
31 <Input v-model="xlsxFile" style="width: 300px"></Input> 36 <Input v-model="xlsxFile" style="width: 300px"></Input>
  37 +
32 <XlsxUpload 38 <XlsxUpload
33 ref="xlsxUpload" 39 ref="xlsxUpload"
34 :action="action" 40 :action="action"
@@ -40,6 +46,7 @@ @@ -40,6 +46,7 @@
40 </XlsxUpload> 46 </XlsxUpload>
41 </FilterItem> 47 </FilterItem>
42 48
  49 +
43 <FilterItem> 50 <FilterItem>
44 <Button type="primary" @click="upload">开始上传</Button> 51 <Button type="primary" @click="upload">开始上传</Button>
45 </FilterItem> 52 </FilterItem>
@@ -48,7 +55,7 @@ @@ -48,7 +55,7 @@
48 </template> 55 </template>
49 56
50 <script> 57 <script>
51 - import {SelectCategory} from 'components/select'; 58 + import {SelectCategory, SelectBrand} from 'components/select';
52 59
53 export default { 60 export default {
54 data() { 61 data() {
@@ -72,7 +79,8 @@ @@ -72,7 +79,8 @@
72 ] 79 ]
73 }, 80 },
74 xlsxFile: '', 81 xlsxFile: '',
75 - action: '', 82 + brandId: '',
  83 + action: '/importSeller',
76 sort: { 84 sort: {
77 first: { 85 first: {
78 label: '选择类目', 86 label: '选择类目',
@@ -121,7 +129,7 @@ @@ -121,7 +129,7 @@
121 this.xlsxFile = files[0].name; 129 this.xlsxFile = files[0].name;
122 }, 130 },
123 upload() { 131 upload() {
124 - this.$refs.xlsxUpload.upload(); 132 + this.$refs.xlsxUpload.upload({brandId: this.brandId});
125 }, 133 },
126 onSuccess(data) { 134 onSuccess(data) {
127 135
@@ -134,7 +142,8 @@ @@ -134,7 +142,8 @@
134 } 142 }
135 }, 143 },
136 components: { 144 components: {
137 - SelectCategory 145 + SelectCategory,
  146 + SelectBrand
138 } 147 }
139 }; 148 };
140 </script> 149 </script>
@@ -64,7 +64,8 @@ let domainApis = { @@ -64,7 +64,8 @@ let domainApis = {
64 getBindProduct: '/SellerShopController/getBindProduct', 64 getBindProduct: '/SellerShopController/getBindProduct',
65 addCategoryLinkProduct: '/SellerShopController/addCategoryLinkProduct', 65 addCategoryLinkProduct: '/SellerShopController/addCategoryLinkProduct',
66 deleteCategoryLinkProduct: '/SellerShopController/deleteCategoryLinkProduct', 66 deleteCategoryLinkProduct: '/SellerShopController/deleteCategoryLinkProduct',
67 - getRemoteImageUrlBySku: '/product/getRemoteImageUrlBySku' 67 + getRemoteImageUrlBySku: '/product/getRemoteImageUrlBySku',
  68 + importSeller: '/batch/importSeller'
68 }, 69 },
69 shop: { 70 shop: {
70 login: '/loginInter', 71 login: '/loginInter',
@@ -95,6 +95,20 @@ class FileController extends Context { @@ -95,6 +95,20 @@ class FileController extends Context {
95 next(); 95 next();
96 }).catch(next); 96 }).catch(next);
97 } 97 }
  98 +
  99 + importSeller(req, res, next) {
  100 + let file = req.files && req.files.file;
  101 +
  102 + this.api.upload(apiDomain.platform.importSeller, {
  103 + brandId: req.body.brandId,
  104 + shopsId: req.cookies._sign,
  105 + userId: req.session.LOGIN_UID,
  106 + file: fs.createReadStream(file.path),
  107 + type: 'sellerProductImport'
  108 + }).then((result) => {
  109 + res.json(result);
  110 + }).catch(next);
  111 + }
98 } 112 }
99 113
100 module.exports = FileController; 114 module.exports = FileController;
@@ -22,5 +22,6 @@ router.post('/logout', middleware(UserController, 'logout')); @@ -22,5 +22,6 @@ router.post('/logout', middleware(UserController, 'logout'));
22 router.post('/switchShop', before, auth, middleware(UserController, 'switchShop')); 22 router.post('/switchShop', before, auth, middleware(UserController, 'switchShop'));
23 router.post('/upload/image', before, auth, multipartMiddleware, middleware(FileController, 'uploadImage')); 23 router.post('/upload/image', before, auth, multipartMiddleware, middleware(FileController, 'uploadImage'));
24 router.post('/upload/xlsx', before, auth, multipartMiddleware, middleware(FileController, 'uploadXlsx')); 24 router.post('/upload/xlsx', before, auth, multipartMiddleware, middleware(FileController, 'uploadXlsx'));
  25 +router.post('/importSeller', before, auth, multipartMiddleware, middleware(FileController, 'importSeller'));
25 26
26 module.exports = router; 27 module.exports = router;