|
@@ -1,21 +1,15 @@
|
|
|
<template>
|
|
|
<div class="box">
|
|
|
- <div class="con">
|
|
|
- <h1>订单导入</h1>
|
|
|
- <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
|
|
|
- <h1 style="color:#0099FF;">用户导入字段</h1>
|
|
|
- <ex-table
|
|
|
- :columns="columns"
|
|
|
- :table="table"
|
|
|
- :data="tableData"
|
|
|
- >
|
|
|
-
|
|
|
- </ex-table>
|
|
|
- </div>
|
|
|
- <div class="btn">
|
|
|
- <el-button type="primary" @click="submit">提交</el-button>
|
|
|
- <el-button @click="cancel">取消</el-button>
|
|
|
- </div>
|
|
|
+ <div class="con">
|
|
|
+ <h1>订单导入</h1>
|
|
|
+ <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
|
|
|
+ <h1 style="color: #0099ff">用户导入字段</h1>
|
|
|
+ <ex-table :columns="columns" :table="table" :data="tableData"> </ex-table>
|
|
|
+ </div>
|
|
|
+ <div class="btn">
|
|
|
+ <el-button type="primary" @click="submit">提交</el-button>
|
|
|
+ <el-button @click="cancel">取消</el-button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -23,14 +17,11 @@
|
|
|
import asyncRequest from "@/apis/service/orderEntry/orderImport";
|
|
|
import resToken from "@/mixins/resToken";
|
|
|
import { province_list, city_list, county_list } from "@/assets/js/area-data";
|
|
|
-import {columns} from "./columns";
|
|
|
+import { columns } from "./columns";
|
|
|
export default {
|
|
|
mixins: [resToken],
|
|
|
data() {
|
|
|
-
|
|
|
return {
|
|
|
-
|
|
|
-
|
|
|
ruleForm: {
|
|
|
order_addr: [], //收货地址
|
|
|
},
|
|
@@ -50,8 +41,6 @@ export default {
|
|
|
},
|
|
|
// 表格 - 列参数
|
|
|
columns: columns,
|
|
|
-
|
|
|
-
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
@@ -67,7 +56,7 @@ export default {
|
|
|
return false;
|
|
|
},
|
|
|
handleSuccess({ results, header }) {
|
|
|
- console.log("表格导入数据",results,"表格表头",header)
|
|
|
+ console.log("表格导入数据", results, "表格表头", header);
|
|
|
if (results.length === 0) {
|
|
|
this.$message.error("表格无有效数据!");
|
|
|
return;
|
|
@@ -88,7 +77,7 @@ export default {
|
|
|
"订单备注",
|
|
|
"收货人",
|
|
|
"联系电话",
|
|
|
- "联系地址"
|
|
|
+ "联系地址",
|
|
|
];
|
|
|
if (head.length !== header.length) {
|
|
|
// console.log("自定义head长度",head.length)
|
|
@@ -99,14 +88,14 @@ export default {
|
|
|
let hederOk = true;
|
|
|
head.forEach((v1, i1) => {
|
|
|
if (v1 !== header[i1].replace(/\s*/g, "")) {
|
|
|
- console.log(v1)
|
|
|
- console.log(header[i1])
|
|
|
+ console.log(v1);
|
|
|
+ console.log(header[i1]);
|
|
|
hederOk = false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!hederOk) {
|
|
|
- console.log(hederOk)
|
|
|
+ console.log(hederOk);
|
|
|
this.$message.error("表头与导入模板不匹配!");
|
|
|
return;
|
|
|
}
|
|
@@ -116,14 +105,13 @@ export default {
|
|
|
// let tableOk = true;
|
|
|
this.ruleForm.order_addr = [];
|
|
|
list.forEach((v1) => {
|
|
|
-
|
|
|
let b = Object.values(v1);
|
|
|
-
|
|
|
+
|
|
|
// let item = this.get_code(b[3], b[4], b[5]);
|
|
|
let model = {
|
|
|
platform_code: b[0] + "",
|
|
|
po_code: b[1] + "",
|
|
|
- platform_time: this.formatDate(b[2],"/")+ "",
|
|
|
+ platform_time: this.formatDate(b[2], "/") + "",
|
|
|
sale_source: b[3] + "",
|
|
|
plat_code: b[4] + "",
|
|
|
price: b[5] + "",
|
|
@@ -137,50 +125,72 @@ export default {
|
|
|
contactor: b[13] + "",
|
|
|
mobile: b[14] + "",
|
|
|
addr: b[15] + "",
|
|
|
-
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
this.tableData.push(model);
|
|
|
});
|
|
|
|
|
|
- console.log(this.tableData)
|
|
|
+ console.log(this.tableData);
|
|
|
},
|
|
|
//取消
|
|
|
- cancel(){
|
|
|
+ cancel() {
|
|
|
this.tableData = [];
|
|
|
},
|
|
|
//日期转换
|
|
|
formatDate(numb, format) {
|
|
|
- const time = new Date((numb - 1) * 24 * 3600000 + 1)
|
|
|
- time.setYear(time.getFullYear() - 70)
|
|
|
- const year = time.getFullYear() + ''
|
|
|
- const month = time.getMonth() + 1 + ''
|
|
|
- const date = time.getDate() + ''
|
|
|
+ const time = new Date((numb - 1) * 24 * 3600000 + 1);
|
|
|
+ time.setYear(time.getFullYear() - 70);
|
|
|
+ const year = time.getFullYear() + "";
|
|
|
+ const month = time.getMonth() + 1 + "";
|
|
|
+ const date = time.getDate() + "";
|
|
|
if (format && format.length === 1) {
|
|
|
- return year + format + month + format + date
|
|
|
+ return year + format + month + format + date;
|
|
|
}
|
|
|
- return year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
|
|
|
+ return (
|
|
|
+ year +
|
|
|
+ (month < 10 ? "0" + month : month) +
|
|
|
+ (date < 10 ? "0" + date : date)
|
|
|
+ );
|
|
|
},
|
|
|
//提交
|
|
|
- async submit(){
|
|
|
- const model = {
|
|
|
- list:this.tableData
|
|
|
- }
|
|
|
+ async submit() {
|
|
|
+ const model = {
|
|
|
+ list: this.tableData,
|
|
|
+ };
|
|
|
|
|
|
+ let obj = [
|
|
|
+ { name: "平台订单号", str: "platform_code" },
|
|
|
+ { name: "销售渠道", str: "sale_source" },
|
|
|
+ { name: "平台商品编号", str: "plat_code" },
|
|
|
+ { name: "单价(元)", str: "price" },
|
|
|
+ { name: "收货人", str: "contactor" },
|
|
|
+ { name: "联系电话", str: "mobile" },
|
|
|
+ { name: "联系地址", str: "addr" },
|
|
|
+ ];
|
|
|
+ let flag = true;
|
|
|
+ model.list.forEach((item, index) => {
|
|
|
+ if (flag) {
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (let i = 0; i < obj.length; i++) {
|
|
|
+ let txt = item[obj[i].str].trim();
|
|
|
+ if (txt == "") {
|
|
|
+ this.$message.warning(`第${index + 1}行的${obj[i].name}不能为空`);
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- let flag = model.list.every((item,index)=>{
|
|
|
- return item.platform_code && item.sale_source && item.plat_code
|
|
|
- && item.price && item.contactor && item.mobile && item.addr
|
|
|
- })
|
|
|
-
|
|
|
if(flag){
|
|
|
- alert(flag)
|
|
|
- }else{
|
|
|
- alert(flag)
|
|
|
+ this.submitHttp(model)
|
|
|
}
|
|
|
- return;
|
|
|
-
|
|
|
- const res = await asyncRequest.orderimport(model)
|
|
|
+ },
|
|
|
+ async submitHttp(model) {
|
|
|
+ const res = await asyncRequest.orderimport(model);
|
|
|
if (res && res.code === 0) {
|
|
|
this.$notify.success({
|
|
|
title: "成功!",
|
|
@@ -193,29 +203,28 @@ export default {
|
|
|
} else {
|
|
|
this.$message.warning(res.message);
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
-.box{
|
|
|
- width: 100%;
|
|
|
+.box {
|
|
|
+ width: 100%;
|
|
|
}
|
|
|
-.con{
|
|
|
- width: 100%;
|
|
|
+.con {
|
|
|
+ width: 100%;
|
|
|
|
|
|
- h1{
|
|
|
- margin: 30px 0 30px 20px;
|
|
|
- font-size: 26px;
|
|
|
- color: #333;
|
|
|
- }
|
|
|
+ h1 {
|
|
|
+ margin: 30px 0 30px 20px;
|
|
|
+ font-size: 26px;
|
|
|
+ color: #333;
|
|
|
+ }
|
|
|
}
|
|
|
-.btn{
|
|
|
- width: 50%;
|
|
|
- margin: 50px auto 0;
|
|
|
- display: flex;
|
|
|
- justify-content: space-around;
|
|
|
+.btn {
|
|
|
+ width: 50%;
|
|
|
+ margin: 50px auto 0;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-around;
|
|
|
}
|
|
|
</style>
|