|
@@ -1,123 +1,70 @@
|
|
<template>
|
|
<template>
|
|
<el-dialog
|
|
<el-dialog
|
|
v-loading="loading"
|
|
v-loading="loading"
|
|
- title="导入数据"
|
|
|
|
|
|
+ :title="title"
|
|
:center="true"
|
|
:center="true"
|
|
align="left"
|
|
align="left"
|
|
- top="20vh"
|
|
|
|
- width="700px"
|
|
|
|
|
|
+ top="8vh"
|
|
|
|
+ width="1040px"
|
|
:close-on-click-modal="false"
|
|
:close-on-click-modal="false"
|
|
:visible.sync="showModelThis"
|
|
:visible.sync="showModelThis"
|
|
element-loading-text="拼命加载中"
|
|
element-loading-text="拼命加载中"
|
|
element-loading-spinner="el-icon-loading"
|
|
element-loading-spinner="el-icon-loading"
|
|
element-loading-background="rgba(0, 0, 0, 0.8)"
|
|
element-loading-background="rgba(0, 0, 0, 0.8)"
|
|
- append-to-body
|
|
|
|
@close="closeModel"
|
|
@close="closeModel"
|
|
|
|
+ append-to-body
|
|
>
|
|
>
|
|
- <el-card>
|
|
|
|
- <el-row :gutter="10">
|
|
|
|
- <el-col :span="24">
|
|
|
|
- <el-form
|
|
|
|
- ref="ruleForm"
|
|
|
|
- :model="ruleForm"
|
|
|
|
- status-icon
|
|
|
|
- :rules="rules"
|
|
|
|
- label-width="110px"
|
|
|
|
- class="demo-ruleForm"
|
|
|
|
- >
|
|
|
|
- <el-form-item label="表格文件" prop="execl">
|
|
|
|
- <el-card shadow="never" :body-style="{ padding: '0px' }">
|
|
|
|
- <div class="excelUploadBox" v-if="!isfile">
|
|
|
|
- <i class="el-icon-receiving"></i>
|
|
|
|
- <span class="boxM"> 点击此处,上传文件!</span>
|
|
|
|
-
|
|
|
|
- <upload-excel
|
|
|
|
- :accept="'.xls'"
|
|
|
|
- class="excelUpload"
|
|
|
|
- :uploadcondition="beforeAvatarUpload"
|
|
|
|
- @UploadErrorEvent="UploadErrorEvent"
|
|
|
|
- @UploadSuccessEvent="UploadSuccessEvent"
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- <div v-else class="excelUploadRes clear">
|
|
|
|
- <i class="el-icon-document fl"></i>
|
|
|
|
- <span class="fl"> {{ ruleForm.execl.name }}</span>
|
|
|
|
- <i class="el-icon-close fr" @click="fileClose"></i>
|
|
|
|
- </div>
|
|
|
|
- </el-card>
|
|
|
|
- </el-form-item>
|
|
|
|
- </el-form>
|
|
|
|
- </el-col>
|
|
|
|
- <el-col :span="24" style="text-align: right">
|
|
|
|
- <el-button v-if="!isDetail" type="primary" @click="submitForm"
|
|
|
|
- >保 存
|
|
|
|
- </el-button>
|
|
|
|
- <el-button @click="showModelThis = false">{{
|
|
|
|
- isDetail ? "关 闭" : "取 消"
|
|
|
|
- }}</el-button>
|
|
|
|
- </el-col>
|
|
|
|
- </el-row>
|
|
|
|
|
|
+ <el-card style="margin-top: -25px">
|
|
|
|
+ <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
|
|
|
|
+ <el-table
|
|
|
|
+ :data="tableData"
|
|
|
|
+ size="mini"
|
|
|
|
+ border
|
|
|
|
+ max-height="400px"
|
|
|
|
+ highlight-current-row
|
|
|
|
+ style="width: 100%; margin-top: 20px"
|
|
|
|
+ >
|
|
|
|
+ <el-table-column prop="invNo" label="收货总数" width="100" />
|
|
|
|
+ <el-table-column
|
|
|
|
+ prop="inv_type_name"
|
|
|
|
+ label="最晚收货日期"
|
|
|
|
+ width="142"
|
|
|
|
+ />
|
|
|
|
+ <el-table-column prop="inv_code" label="收货联系人" width="85" />
|
|
|
|
+ <el-table-column prop="inv_number" label="收货联系电话" width="110" />
|
|
|
|
+ <el-table-column
|
|
|
|
+ prop="inv_total"
|
|
|
|
+ label="收货省市区(导入值)"
|
|
|
|
+ width="130"
|
|
|
|
+ />
|
|
|
|
+ <el-table-column prop="createtime" label="收货省市区(系统识别后)" />
|
|
|
|
+ <el-table-column prop="createtime" label="详细地址" width="150" />
|
|
|
|
+ </el-table>
|
|
|
|
+ <div class="tr" style="padding: 10px 0 0 0">
|
|
|
|
+ <el-button type="primary" size="small" @click="submitForm"
|
|
|
|
+ >保 存
|
|
|
|
+ </el-button>
|
|
|
|
+ </div>
|
|
</el-card>
|
|
</el-card>
|
|
</el-dialog>
|
|
</el-dialog>
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
import asyncRequest from "@/apis/service/sellOut/salesOrder/detail";
|
|
import asyncRequest from "@/apis/service/sellOut/salesOrder/detail";
|
|
import resToken from "@/mixins/resToken";
|
|
import resToken from "@/mixins/resToken";
|
|
|
|
+import { province_list, city_list, county_list } from "@/assets/js/area-data";
|
|
import { isnumber, isnumber2, isAlphanumeric } from "@/utils/validate";
|
|
import { isnumber, isnumber2, isAlphanumeric } from "@/utils/validate";
|
|
export default {
|
|
export default {
|
|
name: "Account",
|
|
name: "Account",
|
|
props: ["showModel", "id", "sitem"],
|
|
props: ["showModel", "id", "sitem"],
|
|
mixins: [resToken],
|
|
mixins: [resToken],
|
|
data() {
|
|
data() {
|
|
- const validatePrice = (rule, value, callback) => {
|
|
|
|
- if (value === "") {
|
|
|
|
- callback(new Error("不能为空!"));
|
|
|
|
- } else {
|
|
|
|
- if (isnumber2(value)) {
|
|
|
|
- callback();
|
|
|
|
- } else {
|
|
|
|
- callback(new Error("仅支持整数或两位小数!"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- const validateWeight = (rule, value, callback) => {
|
|
|
|
- if (value === "") {
|
|
|
|
- callback(new Error("不能为空!"));
|
|
|
|
- } else {
|
|
|
|
- if (!isnumber(value)) {
|
|
|
|
- callback(new Error("仅支持整数!"));
|
|
|
|
- } else {
|
|
|
|
- callback();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- const validateCode = (rule, value, callback) => {
|
|
|
|
- if (value === "") {
|
|
|
|
- callback(new Error("不能为空!"));
|
|
|
|
- } else {
|
|
|
|
- if (!isAlphanumeric(value)) {
|
|
|
|
- callback(new Error("仅支持字母和数字!"));
|
|
|
|
- } else {
|
|
|
|
- callback();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
return {
|
|
return {
|
|
|
|
+ tableData: [],
|
|
|
|
+ tableHeader: [],
|
|
|
|
+ title: "",
|
|
|
|
+ showModelThis: false,
|
|
loading: false,
|
|
loading: false,
|
|
- showModelThis: this.showModel,
|
|
|
|
- isfile: false,
|
|
|
|
- ruleForm: {
|
|
|
|
- execl: "",
|
|
|
|
- },
|
|
|
|
- rules: {
|
|
|
|
- execl: [
|
|
|
|
- {
|
|
|
|
- required: true,
|
|
|
|
- message: "请选择文件",
|
|
|
|
- trigger: "change",
|
|
|
|
- },
|
|
|
|
- ],
|
|
|
|
- },
|
|
|
|
|
|
+ newTime: 0,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
@@ -133,130 +80,189 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
+ mounted() {
|
|
|
|
+ this.get_code();
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
closeModel() {
|
|
closeModel() {
|
|
console.log("closeModel!!");
|
|
console.log("closeModel!!");
|
|
},
|
|
},
|
|
- async resetForm() {
|
|
|
|
- // 重置
|
|
|
|
- await this.$nextTick(() => {
|
|
|
|
- if (this.$refs.ruleForm) {
|
|
|
|
- this.$refs.ruleForm.resetFields();
|
|
|
|
- this.$refs.ruleForm.clearValidate();
|
|
|
|
- this.ruleForm = {
|
|
|
|
- execl: "",
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ beforeUpload(file) {
|
|
|
|
+ const isLt1M = file.size / 1024 / 1024 < 1;
|
|
|
|
+ if (isLt1M) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.$message({
|
|
|
|
+ message: "请不要上传大于1MB的文件.",
|
|
|
|
+ type: "warning",
|
|
});
|
|
});
|
|
|
|
+ return false;
|
|
},
|
|
},
|
|
- beforeAvatarUpload(file) {
|
|
|
|
- console.log(file.type);
|
|
|
|
- let isJPG = false;
|
|
|
|
- if (file.type === "application/vnd.ms-excel") {
|
|
|
|
- isJPG = true;
|
|
|
|
|
|
+ handleSuccess({ results, header }) {
|
|
|
|
+ let head = [
|
|
|
|
+ "收货总数",
|
|
|
|
+ "最晚收货日期",
|
|
|
|
+ "收货联系人",
|
|
|
|
+ "收货联系电话",
|
|
|
|
+ "收货省名称",
|
|
|
|
+ "收货市名称",
|
|
|
|
+ "收货区名称",
|
|
|
|
+ "详细地址",
|
|
|
|
+ ];
|
|
|
|
+ if (head.length !== header.length) {
|
|
|
|
+ this.$message.error("表头与导入模板不匹配!");
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- const isLt2M = file.size / 1024 / 1024 < 3;
|
|
|
|
- if (!isJPG) {
|
|
|
|
- this.$message.error("文件格式不正确!");
|
|
|
|
|
|
+ let hederOk = true;
|
|
|
|
+ head.forEach((v1, i1) => {
|
|
|
|
+ if (v1 !== header[i1].replace(/\s*/g, "")) {
|
|
|
|
+ hederOk = false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (!hederOk) {
|
|
|
|
+ this.$message.error("表头与导入模板不匹配!");
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- if (!isLt2M) {
|
|
|
|
- this.$message.error("文件大小不能超过 3MB!");
|
|
|
|
|
|
+ this.tableHeader = header;
|
|
|
|
+ this.tableData = [];
|
|
|
|
+ let list = results;
|
|
|
|
+ console.log(list);
|
|
|
|
+ let tableOk = true;
|
|
|
|
+ this.tableData = [];
|
|
|
|
+ list.forEach((v1) => {
|
|
|
|
+ let b = Object.values(v1);
|
|
|
|
+ let time = this.setTime((b[1] + "").replace(/^\s*|\s*$/g, ""));
|
|
|
|
+ console.log(time);
|
|
|
|
+ console.log(b);
|
|
|
|
+ // console.log(this.get_code(b[4], b[5], b[6]));
|
|
|
|
+ let model = {
|
|
|
|
+ receipt_quantity: b[0],
|
|
|
|
+ arrive_time: time,
|
|
|
|
+
|
|
|
|
+ contactor: b[2],
|
|
|
|
+ mobile: b[3],
|
|
|
|
+ order_addr: b[4],
|
|
|
|
+ addr: b[7],
|
|
|
|
+ };
|
|
|
|
+ this.tableData.push(model);
|
|
|
|
+ });
|
|
|
|
+ if (!tableOk) {
|
|
|
|
+ this.$message.error("最晚收货日期不正确,请将表格格式转为文本上传!");
|
|
}
|
|
}
|
|
- this.isfile = false;
|
|
|
|
- return isJPG && isLt2M;
|
|
|
|
- },
|
|
|
|
- fileClose() {
|
|
|
|
- this.isfile = false;
|
|
|
|
- this.ruleForm.execl = "";
|
|
|
|
- this.$refs.ruleForm.validateField("execl");
|
|
|
|
- },
|
|
|
|
- //图片上传失败
|
|
|
|
- UploadErrorEvent() {
|
|
|
|
- this.isfile = false;
|
|
|
|
- this.$message.error("文件上传失败!");
|
|
|
|
- this.$refs.ruleForm.validateField("execl");
|
|
|
|
},
|
|
},
|
|
- //图片上传成功
|
|
|
|
- UploadSuccessEvent(data) {
|
|
|
|
- console.log(data);
|
|
|
|
- this.isfile = true;
|
|
|
|
- this.ruleForm.execl = data.file;
|
|
|
|
- this.$message.success("文件上传成功!");
|
|
|
|
- this.$refs.ruleForm.validateField("execl");
|
|
|
|
|
|
+ unique(arr) {
|
|
|
|
+ let hash = [];
|
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
|
+ let index = hash.findIndex((v1) => v1.inv_number === arr[i].inv_number);
|
|
|
|
+ if (index === -1) {
|
|
|
|
+ hash.push(arr[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return hash;
|
|
},
|
|
},
|
|
- handleSelectionChange(e, type) {
|
|
|
|
- if (type === 0) {
|
|
|
|
- this.list0 = e;
|
|
|
|
- this.ruleForm.wsm_code = e && e.length > 0 ? e[0].wsm_code : "";
|
|
|
|
- } else {
|
|
|
|
- this.list1 = e;
|
|
|
|
- this.ruleForm.addrid = e && e.length > 0 ? e[0].id : "";
|
|
|
|
|
|
+ setTime(time) {
|
|
|
|
+ time = time.replace(/\//g, "-");
|
|
|
|
+ time = time.replace(/\./g, "-");
|
|
|
|
+ let key = new Date(time).valueOf() + "";
|
|
|
|
+ if (key.length !== 13) {
|
|
|
|
+ time = "";
|
|
}
|
|
}
|
|
- console.log(type);
|
|
|
|
- console.log(this.ruleForm.wsm_code, this.ruleForm.addrid);
|
|
|
|
- console.log(this.ruleForm);
|
|
|
|
|
|
+ return time;
|
|
},
|
|
},
|
|
async initForm() {
|
|
async initForm() {
|
|
- this.isfile = false;
|
|
|
|
|
|
+ this.newTime = 0;
|
|
this.loading = true;
|
|
this.loading = true;
|
|
- await this.resetForm();
|
|
|
|
|
|
+ this.tableData = [];
|
|
|
|
+ this.tableHeader = [];
|
|
|
|
+ this.step = 1;
|
|
|
|
+ this.title = "批量导入收货地址信息";
|
|
|
|
+
|
|
|
|
+ this.changea();
|
|
this.loading = false;
|
|
this.loading = false;
|
|
},
|
|
},
|
|
|
|
+ refreshAll() {
|
|
|
|
+ this.showModelThis = false;
|
|
|
|
+ this.$emit("refresh");
|
|
|
|
+ },
|
|
|
|
+ changea() {
|
|
|
|
+ this.newTime = new Date().valueOf();
|
|
|
|
+ },
|
|
|
|
|
|
- // 保存更改
|
|
|
|
async submitForm() {
|
|
async submitForm() {
|
|
- await this.$refs.ruleForm.validate(async (valid) => {
|
|
|
|
- if (valid) {
|
|
|
|
- const item = JSON.parse(JSON.stringify(this.ruleForm));
|
|
|
|
- if (this.list0.length === 0) {
|
|
|
|
- this.$message.warning("请选择发货仓库!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (this.list1.length === 0) {
|
|
|
|
- this.$message.warning("请选择收货地址!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (this.list0.length !== 1) {
|
|
|
|
- this.$message.warning("只能选择一个发货仓库!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (this.list1.length !== 1) {
|
|
|
|
- this.$message.warning("只能选择一个收货地址!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- let cNum = parseInt(this.list0[0].wsend_num);
|
|
|
|
- let aNum = parseInt(this.list1[0].wsend_num);
|
|
|
|
- let num = parseInt(this.ruleForm.send_num);
|
|
|
|
- if (num > cNum) {
|
|
|
|
- this.$message.warning("发货数量不能大于仓库未发货数量!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (num > aNum) {
|
|
|
|
- this.$message.warning("发货数量不能大于收货地址未发货数量!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- this.loading = true;
|
|
|
|
- console.log(item);
|
|
|
|
- item.post_name = item.post_name.toString();
|
|
|
|
- const res = await asyncRequest.saleout(item);
|
|
|
|
|
|
+ if (!this.loading) {
|
|
|
|
+ if (this.tableData.length < 1) {
|
|
|
|
+ this.$message.error("导入数据不能为空!");
|
|
this.loading = false;
|
|
this.loading = false;
|
|
- if (res && res.code === 0) {
|
|
|
|
- this.$notify.success({
|
|
|
|
- title: "添加成功",
|
|
|
|
- message: "",
|
|
|
|
- });
|
|
|
|
- this.showModelThis = false;
|
|
|
|
- this.$emit("refresh"); //抛出事件给详情页。
|
|
|
|
- } else if (res && res.code >= 100 && res.code <= 104) {
|
|
|
|
- await this.logout();
|
|
|
|
- } else {
|
|
|
|
- this.$message.warning(res.message);
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let arr = this.unique(this.tableData);
|
|
|
|
+ if (arr.length !== this.tableData.length) {
|
|
|
|
+ this.$message.error("收货联系电话不可以重复出现!");
|
|
|
|
+ this.loading = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.loading = true;
|
|
|
|
+ let isok = true;
|
|
|
|
+ let list = [];
|
|
|
|
+ this.tableData.forEach((v1, i1) => {
|
|
|
|
+ let model = Object.assign({}, v1);
|
|
|
|
+ delete model["inv_type_name"];
|
|
|
|
+ for (let key in model) {
|
|
|
|
+ if (model[key] === "") {
|
|
|
|
+ isok = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ list.push(model);
|
|
|
|
+ });
|
|
|
|
+ if (!isok) {
|
|
|
|
+ this.$message.error("导入数据不能出现空值!");
|
|
|
|
+ this.loading = false;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const res = await asyncRequest.receiptimport({ data: list });
|
|
|
|
+ this.loading = false;
|
|
|
|
+ if (res && res.code === 0) {
|
|
|
|
+ this.showModelThis = false;
|
|
|
|
+ this.$emit("refresh");
|
|
|
|
+ } else if (res && res.code >= 100 && res.code <= 104) {
|
|
|
|
+ await this.logout();
|
|
|
|
+ } else if (res && res.code === 1005) {
|
|
|
|
+ this.$message.error(res.message);
|
|
} else {
|
|
} else {
|
|
- console.log("error submit!!");
|
|
|
|
- return false;
|
|
|
|
|
|
+ console.log("其他错误");
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ get_code(name1, name2, name3) {
|
|
|
|
+ let name = [],
|
|
|
|
+ code = [];
|
|
|
|
+ for (let i in province_list) {
|
|
|
|
+ if (name1 === province_list[i]) {
|
|
|
|
+ code.push(i);
|
|
|
|
+ name.push(province_list[i]);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (let i in province_list) {
|
|
|
|
+ if (name1 === province_list[i]) {
|
|
|
|
+ code.push(i);
|
|
|
|
+ name.push(province_list[i]);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (let i in province_list) {
|
|
|
|
+ if (name1 === province_list[i]) {
|
|
|
|
+ code.push(i);
|
|
|
|
+ name.push(province_list[i]);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return { name: [], code: [] };
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|