Authored by htoooth

fix

... ... @@ -14,7 +14,7 @@ export default {
name: 'CheckboxSize',
props: {
sortId: {
type: String
type: Number
},
selectSizes: {
type: Array,
... ...
<template>
<div>
<input type="file" accept=".xlsx" @change="handleChange">
<div @click="handleClick" style="display: inline-block;">
<input ref="input" type="file" accept=".xlsx" @change="handleChange">
<slot></slot>
</div>
</template>
... ... @@ -9,9 +9,13 @@
import request from 'axios';
export default {
name: 'XlsxUpload',
props: {
action: {
type: String
type: String,
default() {
return '/upload/xlsx';
}
},
onSuccess: {
type: Function,
... ... @@ -44,6 +48,9 @@
};
},
methods: {
handleClick() {
this.$refs.input.click();
},
handleChange(e) {
this.files = e.target.files;
this.onChange(this.files);
... ...
... ... @@ -110,7 +110,7 @@
</Form-item>
<Form-item label="尺寸" prop="selectSize">
<CheckboxSize v-model="table.selectedSizes" :sort-id="product.smallSortId" @on-add="addSize" @on-remove="removeSize"></CheckboxSize>
<CheckboxSize v-model="product.selectSize" :sort-id="product.smallSortId" @on-add="addSize" @on-remove="removeSize"></CheckboxSize>
</Form-item>
<Row>
... ... @@ -387,11 +387,11 @@ export default {
salesPrice: [
{ required: true, trigger: 'blur', validator: validateMustLessRetailPrice},
],
selectSize: [
{ required: true, trigger: 'change', validator: validateColor},
],
selectColor: [
{ required: true, trigger: 'change', validator: validateSize},
{ required: true, trigger: 'NONE', validator: validateColor},
],
selectSize: [
{ required: true, trigger: 'NONE', validator: validateSize},
],
},
years: 2018
... ... @@ -590,6 +590,8 @@ export default {
this.refreshTable();
let changeSize = _.first(sizes);
this.table.selectedSizes.push(changeSize);
this.table.data.forEach((c) => {
this.addSizeData(c, changeSize);
});
... ... @@ -613,6 +615,7 @@ export default {
color.sizeId.splice(index, 1);
color.sizeCode.splice(index, 1);
color.operator.splice(index, 1);
this.table.selectedSizes.splice(index, 1);
}
},
addSizeData: function(color, findSize) {
... ... @@ -755,22 +758,6 @@ export default {
return this.product.maxSortName + '/' + this.product.middleSortName + '/' + this.product.smallSortName;
}
},
watch: {
'table.selectedSizes': function(newVal, oldVal) {
if (newVal.length === 0) {
this.table.showValidateSize = true;
} else {
this.table.showValidateSize = false;
}
},
'table.selectedColors': function(newVal) {
if (newVal.length === 0) {
this.table.showValidateColor = true;
} else {
this.table.showValidateColor = false;
}
}
},
components: {
CheckboxAge,
RadioSeason,
... ...
... ... @@ -10,11 +10,12 @@
<Form-item label="上传文件:">
<XlsxUpload
ref="upload"
action="//jsonplaceholder.typicode.com/posts/"
:on-success="uploadSuccess"
:on-error="uploadError">
:on-error="uploadError"
:on-change="uploadChange">
<Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
</XlsxUpload>
<span>{{name}}</span>
</Form-item>
<Form-item label="说明:">
<div style="display: inline-block">
... ... @@ -22,7 +23,7 @@
<li>1、上传文件必须是 <span style="color: red;">.xlsx</span> 文件</li>
<li>2、第一行为标题栏:<strong>skn | sku | 库存数量</strong></li>
<li>3、每次最多导入1000条数据</li>
<li>4、<a href="">下载样例</a></li>
<li>4、<a href="/example.xlsx">下载样例</a></li>
</ul>
</div>
</Form-item>
... ... @@ -30,8 +31,8 @@
</div>
<div slot="footer" style="text-align: center">
<Button type="primary" size="large" :loading="modal_loading" @click="submit">保存</Button>
<Button type="primary" size="large" @click="cancel">取消</Button>
<Button type="primary" size="large" :loading="modal_loading" @click="save">保存</Button>
<Button type="primary" size="large" @click="close">取消</Button>
</div>
</Modal>
</template>
... ... @@ -40,30 +41,60 @@
export default {
data() {
return {
url: '',
model: true,
model: false,
modal_loading: false,
fileName: ''
};
},
methods: {
show() {
this.reset();
this.model = true;
},
beforeUpload() {
if (this.$refs.upload.fileList !== 1) {
this.$refs.upload.fileList.splice(0, 1);
uploadSuccess(result) {
this.modal_loading = false;
if (result.code === 200) {
this.$Notice.success({
title: '更新库存成功',
});
this.close();
} else {
this.$Notice.error({
title: '保存失败,请重试',
});
}
},
uploadSuccess(response, file, fileList) {
},
uploadError(error, file, fileList) {
uploadError() {
this.modal_loading = false;
this.$Notice.error({
title: '保存失败,请重试',
});
},
submit() {
uploadChange(files) {
if (files.length === 0) {
return;
}
this.fileName = files[0].name;
},
cancel() {
close() {
this.model = false;
},
save() {
this.modal_loading = true;
return this.$refs.upload.upload();
},
reset() {
this.modal_loading = false;
this.fileName = '';
}
},
computed: {
name() {
return this.fileName || '未选择任何文件';
}
}
};
... ...
... ... @@ -15,7 +15,7 @@
<FilterItem>
<Button type="primary" @click="filterSearch">筛选</Button>
<Button type="primary" @click="showImportStore">导入库存</Button>
<Button type="warning" @click="showImportStore">导入库存</Button>
<Button @click="clearFilter">清空条件</Button>
</FilterItem>
</LayoutFilter>
... ...
... ... @@ -146,11 +146,10 @@ function getProduct(skn) {
}
function addNoneItem(objArray) {
if (objArray.inputType === 'checkbox') {
return objArray;
}
objArray.forEach(obj => {
if (obj.inputType === 'checkbox') {
return;
}
obj.idNameList && obj.idNameList.unshift({id: 0, text: '请选择' + obj.attributeName});
});
... ...
... ... @@ -40,6 +40,7 @@
"vue-html5-editor": "^1.1.1",
"vue-router": "^2.2.0",
"vue-template-compiler": "^2.2.6",
"xlsx2json": "^1.0.0",
"yoho-cookie": "^1.2.0",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "^0.2.18",
... ...
... ... @@ -41,6 +41,7 @@ app.use(cookieSession({
app.use(compression());
app.use(favicon(path.join(__dirname, '/favicon.ico')));
app.use(Express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
... ...
... ... @@ -7,6 +7,7 @@
const Context = require('../framework/context');
const FileService = require('../service/file-service');
const XlsxService = require('../service/xlsx-service');
const Api = require('../common/api');
const apiDomain = require('../common/api-domain');
const fs = require('fs');
... ... @@ -17,6 +18,7 @@ class FileController extends Context {
super();
this.api = this.instance(Api);
this.fileService = this.instance(FileService);
this.xlsxService = this.instance(XlsxService);
}
uploadImage(req, res, next) {
let files = req.files && req.files.file || [];
... ... @@ -79,6 +81,23 @@ class FileController extends Context {
}).catch(next);
}
}
uploadXlsx(req, res, next) {
let file = req.files && req.files.file;
return this.xlsxService.handle(file.path).then((result) => {
if (result.code === 200) {
return res.json({
code: 200,
message: '保存成功'
});
} else {
return res.json({
code: 500,
message: result.message
});
}
}).catch(next);
}
}
module.exports = FileController;
... ...
... ... @@ -18,6 +18,7 @@ let router = Express.Router(); // eslint-disable-line
router.post('/login', middleware(UserController, 'login'));
router.post('/logout', middleware(UserController, 'logout'));
router.post('/upload/image', multipartMiddleware, middleware(FileController, 'uploadImage'));
router.post('/upload/xlsx', multipartMiddleware, middleware(FileController, 'uploadXlsx'));
module.exports = router;
... ...
/**
* Created by TaoHuang on 2017/5/17.
*/
const Context = require('../framework/context');
const xlsx2json = require('xlsx2json');
const Api = require('../common/api');
const apiDomain = global.yoho.apiDomain;
const _ = require('lodash');
const xlsxRead = (fileName) => {
return xlsx2json(fileName, {
dataStartingRow: 2,
mapping: {
productSkn: 'A',
productSku: 'B',
number: 'c'
}
});
};
class XlsxService extends Context {
constructor() {
super();
this.api = this.instance(Api);
}
handle(fileName) {
return xlsxRead(fileName).then((jsonArray) => {
let data = _.first(jsonArray);
if (!data) {
return Promise.reject(new Error('数据为空'));
}
return this.postJitStore(data);
});
}
postJitStore(params) {
let data = {
brandAuthData: null,
authLevel: true,
storageType: 3,
virtualInventoryBos: params
};
return this.api.post(apiDomain.erp.importJitStorage, data);
}
}
module.exports = XlsxService;
... ...