|
@@ -0,0 +1,257 @@
|
|
|
|
+<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">提交</el-button>
|
|
|
|
+ <el-button>取消</el-button>
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import { province_list, city_list, county_list } from "@/assets/js/area-data";
|
|
|
|
+import {columns} from "./columns";
|
|
|
|
+export default {
|
|
|
|
+ data() {
|
|
|
|
+ const validatemobile = (rule, value, callback) => {
|
|
|
|
+ if (value === "") {
|
|
|
|
+ callback(new Error("联系电话不能为空!"));
|
|
|
|
+ } else {
|
|
|
|
+ if (!isMobile(value)) {
|
|
|
|
+ callback(new Error("联系电话格式不正确!"));
|
|
|
|
+ } else {
|
|
|
|
+ callback();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ const validateWeight = (rule, value, callback) => {
|
|
|
|
+ if (value === "") {
|
|
|
|
+ callback(new Error("收货总数不能为空!"));
|
|
|
|
+ } else {
|
|
|
|
+ if (!isnumber(value)) {
|
|
|
|
+ callback(new Error("收货总数仅支持整数!"));
|
|
|
|
+ } else {
|
|
|
|
+ callback();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ return {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ruleForm: {
|
|
|
|
+ order_addr: [], //收货地址
|
|
|
|
+ },
|
|
|
|
+ // 表格 - 参数
|
|
|
|
+ table: {
|
|
|
|
+ stripe: true,
|
|
|
|
+ border: true,
|
|
|
|
+ // _defaultHeader_: ["setcol"],
|
|
|
|
+ },
|
|
|
|
+ tableData: [],
|
|
|
|
+ tableHeader: [],
|
|
|
|
+ // 表格 - 分页
|
|
|
|
+ pageInfo: {
|
|
|
|
+ size: 15,
|
|
|
|
+ curr: 1,
|
|
|
|
+ total: 0,
|
|
|
|
+ },
|
|
|
|
+ // 表格 - 列参数
|
|
|
|
+ columns: columns,
|
|
|
|
+
|
|
|
|
+ rules: {
|
|
|
|
+
|
|
|
|
+ receipt_quantity: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ validator: validateWeight,
|
|
|
|
+ trigger: "blur",
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+
|
|
|
|
+ contactor: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ trigger: "blur",
|
|
|
|
+ message: "联系人不能为空",
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ mobile: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ validator: validatemobile,
|
|
|
|
+ trigger: "blur",
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ addr_code: [
|
|
|
|
+ {
|
|
|
|
+ type: "array",
|
|
|
|
+ required: true,
|
|
|
|
+ message: "收货省市区不能为空",
|
|
|
|
+ trigger: "change",
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ addr: [
|
|
|
|
+ {
|
|
|
|
+ required: true,
|
|
|
|
+ message: "详细地址不能为空",
|
|
|
|
+ trigger: "blur",
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ beforeUpload(file) {
|
|
|
|
+ const isLt1M = file.size / 1024 / 1024 < 1;
|
|
|
|
+ if (isLt1M) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ this.$message({
|
|
|
|
+ message: "请不要上传大于1MB的文件.",
|
|
|
|
+ type: "warning",
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ },
|
|
|
|
+ handleSuccess({ results, header }) {
|
|
|
|
+ if (results.length === 0) {
|
|
|
|
+ this.$message.error("表格无有效数据!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let head = [
|
|
|
|
+ "收货总数",
|
|
|
|
+ "收货联系人",
|
|
|
|
+ "收货联系电话",
|
|
|
|
+ "收货省名称",
|
|
|
|
+ "收货市名称",
|
|
|
|
+ "收货区名称",
|
|
|
|
+ "详细地址",
|
|
|
|
+ ];
|
|
|
|
+ if (head.length !== header.length) {
|
|
|
|
+ this.$message.error("表头与导入模板不匹配!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let hederOk = true;
|
|
|
|
+ head.forEach((v1, i1) => {
|
|
|
|
+ if (v1 !== header[i1].replace(/\s*/g, "")) {
|
|
|
|
+ hederOk = false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (!hederOk) {
|
|
|
|
+ this.$message.error("表头与导入模板不匹配!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.tableHeader = header;
|
|
|
|
+ this.tableData = [];
|
|
|
|
+ let list = results;
|
|
|
|
+ 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 = {
|
|
|
|
+ receipt_quantity: b[0] + "",
|
|
|
|
+ contactor: b[1] + "",
|
|
|
|
+ mobile: b[2] + "",
|
|
|
|
+ in_addr: b[3] + "/" + b[4] + "/" + b[5],
|
|
|
|
+ addr_code_name: item.name + "",
|
|
|
|
+ addr_code: item.code,
|
|
|
|
+ addr: b[6] + "",
|
|
|
|
+ edit: false,
|
|
|
|
+ };
|
|
|
|
+ this.ruleForm.order_addr.push(model);
|
|
|
|
+ });
|
|
|
|
+ if (!tableOk) {
|
|
|
|
+ this.$message.error("最晚收货日期不正确,请将表格格式转为文本上传!");
|
|
|
|
+ }
|
|
|
|
+ console.log(this.ruleForm.order_add)
|
|
|
|
+ },
|
|
|
|
+ get_code(name1, name2, name3) {
|
|
|
|
+ let name = "",
|
|
|
|
+ code = [];
|
|
|
|
+ if (name1 && name2 && name3) {
|
|
|
|
+ for (let x in province_list) {
|
|
|
|
+ if (name1 === province_list[x]) {
|
|
|
|
+ code.push(x);
|
|
|
|
+ name += province_list[x];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (code.length === 1) {
|
|
|
|
+ for (let y in city_list) {
|
|
|
|
+ if (name2 === city_list[y]) {
|
|
|
|
+ code.push(y);
|
|
|
|
+ name += "/" + city_list[y];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (code.length === 2) {
|
|
|
|
+ for (let z in county_list) {
|
|
|
|
+ if (name3 === county_list[z]) {
|
|
|
|
+ code.push(z);
|
|
|
|
+ name += "/" + county_list[z];
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (code.length === 3) {
|
|
|
|
+ let str1 = "",
|
|
|
|
+ str2 = "",
|
|
|
|
+ isok = false;
|
|
|
|
+ str1 = code[0].slice(0, 2);
|
|
|
|
+ str2 = code[1].slice(2, 4);
|
|
|
|
+ if (
|
|
|
|
+ code[1].indexOf(str1) === 0 &&
|
|
|
|
+ code[2].indexOf(str1) === 0 &&
|
|
|
|
+ code[2].indexOf(str2) == 2
|
|
|
|
+ ) {
|
|
|
|
+ isok = true;
|
|
|
|
+ }
|
|
|
|
+ if (!isok) {
|
|
|
|
+ name = "";
|
|
|
|
+ code = [];
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ name = "";
|
|
|
|
+ code = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return { name: name, code: code };
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.box{
|
|
|
|
+ width: 100%;
|
|
|
|
+}
|
|
|
|
+.con{
|
|
|
|
+ width: 100%;
|
|
|
|
+
|
|
|
|
+ h1{
|
|
|
|
+ margin: 30px 0 30px 20px;
|
|
|
|
+ font-size: 26px;
|
|
|
|
+ color: #333;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+.btn{
|
|
|
|
+ width: 50%;
|
|
|
|
+ margin: 50px auto 0;
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: space-around;
|
|
|
|
+}
|
|
|
|
+</style>
|