Commit 1bb53049 by 张立顺

feat 功能联调

1 parent bebfdf3e
......@@ -44,12 +44,24 @@ export function getProductServiceItems(data) {
return request(data, "post");
}
// 批量导入
// 批量导入(通用,已拆分为轻改/延保)
export function productImport(data) {
data.method = `${path}productManager.import`;
return request(data, "post", ["file"]);
}
// 轻改SKU批量导入(code -1 时直接展示响应 message,无需 errCode 配置)
export function qinggaiImport(data) {
data.method = `${path}productManager.qinggai.import`;
return request(data, "post", ["file"], { useResponseMessage: true });
}
// 延保SKU批量导入(code -1 时直接展示响应 message,无需 errCode 配置)
export function yanbaoImport(data) {
data.method = `${path}productManager.yanbao.import`;
return request(data, "post", ["file"], { useResponseMessage: true });
}
// 获取延保类服务项目
export function getExtendServiceItems(data) {
data.method = `${path}vd.item.queryExtendServiceItemsConfig`;
......
......@@ -120,9 +120,11 @@ service.interceptors.response.use(
// }
const dataAxios = response.data;
const ruleResult = baseConfig.axios.result;
const errCodeMsg = baseConfig.errCode;
const errCodeMsg = baseConfig.errCode || {};
const errCodes = Object.keys(errCodeMsg);
const returnAll = response.config.headers["return-all"];
// 请求级配置:为 true 时,code 为 -1 直接使用响应的 message,不查 errCode 配置
const useResponseMessage = response.config.useResponseMessage;
// console.log("baseConfig", baseConfig)
// console.log("response", response)
......@@ -150,17 +152,20 @@ service.interceptors.response.use(
case ruleResult.code_error_value:
// [ 示例 ] code === -1 代表需将返回的message弹窗展示
return errorCreate(`${dataAxios[ruleResult.message_key]}`);
default:
default: {
// 不是正确的 code
// console.log(dataAxios)
// errorCreate(`${dataAxios[ruleResult.message_key]}`)
// 请求配置 useResponseMessage 时:code 为 -1 直接使用响应的 message
const codeStr = String(dataAxios[ruleResult.code_key] ?? "");
const isCodeMinusOne = codeStr === "-1" || +dataAxios[ruleResult.code_key] === -1;
if (useResponseMessage && isCodeMinusOne) {
return errorCreate(`${dataAxios[ruleResult.message_key]}`);
}
if (errCodes.includes(dataAxios[ruleResult.code_key])) {
return errorCreate(`${errCodeMsg[dataAxios[ruleResult.code_key]]}`);
} else {
// 返回约定定义之外的错误码直接取message
return errorCreate(`${dataAxios[ruleResult.message_key]}`);
}
break;
// 返回约定定义之外的错误码直接取message
return errorCreate(`${dataAxios[ruleResult.message_key]}`);
}
}
},
......
......@@ -33,20 +33,16 @@
<div class="d2-container-content">
<d2-table-header>
<template #left>
<span>
<!-- 新增产品 -->
<span style="display: inline-block;margin-right: 10px;">
<auth-button category="Button" :show-btn-ids="['9030701']" />
</span>
<!-- 批量导入 -->
<auth-button category="Button"
:show-btn-ids="['9030707']"
style="display: inline-block;" />
<!-- 批量导入 -->
<auth-button category="Button"
<!-- <span> -->
<!-- 新增产品 -->
<!-- <span style="display: inline-block;margin-right: 10px;"> -->
<auth-button category="Button" :show-btn-ids="['9030701', '9030707', '9030709']" />
<!-- </span> -->
<!-- 批量导入 -->
<!-- <auth-button category="Button"
:show-btn-ids="['9030707']"
style="display: inline-block;" />
</span>
style="display: inline-block;" /> -->
<!-- </span> -->
</template>
<!-- 导出 -->
<auth-button category="Button"
......@@ -95,8 +91,9 @@
:drawer-detail-visible="drawerSkuDetailVisible"
:position-type-list="positionTypeList"
@handleDrawerClose="handleSkuDrawerClose" />
<!-- 轻改SKU批量导入 -->
<d2-dialog :is-visible="fileVisible"
title="上传文件"
title="批量导入轻改SKU"
@closeDialog="handleBatchImport"
@confirmDialog="handleConfirmImport">
<slot>
......@@ -114,16 +111,53 @@
:span="4">
<el-button class="import-btn">
导入文件
<input id="fileUpload"
<input id="fileUploadQinggai"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
class="import-input"
type="file"
@change="importFile($event)">
@change="importFile($event, 'qinggai')">
<el-link class="import-template"
icon="el-icon-link"
type="primary"
@click="exportTemplate">
模版下载
@click="exportTemplate('qinggai')">
轻改模版下载
</el-link>
</el-button>
</el-col>
</el-form-item>
</el-form>
</slot>
</d2-dialog>
<!-- 延保SKU批量导入 -->
<d2-dialog :is-visible="fileVisibleExtension"
title="批量导入延保SKU"
@closeDialog="handleBatchImportExtension"
@confirmDialog="handleConfirmImportExtension">
<slot>
<el-form ref="fileRuleFormExtension"
label-width="120px"
:model="fileFormExtension"
:rules="fileRules">
<el-form-item label="导入文件:"
prop="fileName">
<el-col :span="16">
<el-input v-model="fileFormExtension.fileName"
readonly />
</el-col>
<el-col class="m-l-md"
:span="4">
<el-button class="import-btn">
导入文件
<input id="fileUploadYanbao"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
class="import-input"
type="file"
@change="importFile($event, 'yanbao')">
<el-link class="import-template"
icon="el-icon-link"
type="primary"
@click="exportTemplate('yanbao')">
延保模版下载
</el-link>
</el-button>
</el-col>
......@@ -137,7 +171,7 @@
<script>
import { baseGoodsDelete } from "@api/commodity";
import { getAllCategory, getBrandSupplyMerchant } from "@api/product";
import { getProductManageListPageLimit, getProductManageListPageSku, productImport, upgradeGoodsDelete } from "@api/productManage";
import { getProductManageListPageLimit, getProductManageListPageSku, qinggaiImport, upgradeGoodsDelete, yanbaoImport } from "@api/productManage";
import { mapActions, mapMutations, mapState } from "vuex";
import { BaseData } from "@/common/constants";
import { Util } from "@/common/util";
......@@ -412,6 +446,10 @@ export default {
},
fileForm: {},
fileVisible: false,
fileInfo: null,
fileFormExtension: {},
fileVisibleExtension: false,
fileInfoExtension: null,
// 新 SPU 接口不返回 upgradeGoodsList,此时所有行均为 SPU 级
spuOnlyMode: false,
commodityDetailInfoSkuId: "", // 商品详情SKU ID
......@@ -721,14 +759,21 @@ export default {
onShowSkuModeChange() {
this.$refs.productManageTable && this.$refs.productManageTable.refreshTable(true, true);
},
// 模板下载
exportTemplate() {
let params = {};
params.method = "dj.api.smartcarlife.productManager.template.export";
// 模板下载:type 为 qinggai 或 yanbao
exportTemplate(type) {
const methodMap = {
qinggai: "dj.api.smartcarlife.productManager.qinggai.template.export",
yanbao: "dj.api.smartcarlife.productManager.yanbao.template.export",
};
const nameMap = {
qinggai: "轻改SKU批量导入模板",
yanbao: "延保SKU批量导入模版",
};
const params = { method: methodMap[type] };
const list = [
...this.dowloadList,
{
name: "门店模板",
name: nameMap[type],
exportParam: JSON.stringify(params),
status: "waiting",
timeid: new Date().getTime(),
......@@ -739,44 +784,47 @@ export default {
handleBatchImport() {
this.fileVisible = !this.fileVisible;
this.$refs.fileRuleForm && this.$refs.fileRuleForm.resetFields();
this.fileInfo = null;
},
handleBatchImportExtension() {
this.fileVisibleExtension = !this.fileVisibleExtension;
this.$refs.fileRuleFormExtension && this.$refs.fileRuleFormExtension.resetFields();
this.fileInfoExtension = null;
},
// 上传文件,转码为base64
importFile(e) {
// 上传文件,转码为base64;type 为 qinggai 或 yanbao
importFile(e, type) {
if (!e.target.files || !e.target.files[0])
return;
const size = e.target.files[0].size / 1024 / 1024;
const formKey = type === "qinggai" ? "fileForm" : "fileFormExtension";
const fileInfoKey = type === "qinggai" ? "fileInfo" : "fileInfoExtension";
const inputId = type === "qinggai" ? "fileUploadQinggai" : "fileUploadYanbao";
if (size < 9) {
this.$set(this.fileForm, "fileName", e.target.files[0].name);
// // 转码base64
this.$set(this[formKey], "fileName", e.target.files[0].name);
const reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
reader.onload = (event) => {
const imgFile = event.target.result;
const arrBase64 = imgFile.split(",");
this.fileInfo = e.target.files[0].name.split(".")[e.target.files[0].name.split(".")?.length - 1] + "@" + arrBase64[1];
document.getElementById("fileUpload").value = "";
this[fileInfoKey] = e.target.files[0].name.split(".")[e.target.files[0].name.split(".")?.length - 1] + "@" + arrBase64[1];
document.getElementById(inputId).value = "";
};
} else {
this.notice.errorTips("上传文件不可超过9M");
document.getElementById("fileUpload").value = "";
document.getElementById(inputId).value = "";
}
},
handleConfirmImport() {
this.$refs.fileRuleForm.validate((valid) => {
if (valid) {
let params = {
file: this.fileInfo,
};
productImport(params).then((res) => {
qinggaiImport({ file: this.fileInfo }).then((res) => {
if (res) {
// 异步处理文件上传 把id传入处理轮询
const list = [...this.updateList, {
name: this.fileForm.fileName,
ifSuccess: false,
uuid: res,
type: "upload",
}];
this.actionSetDownloadList({ list, type: "updateList" });
this.notice.okTips("上传成功");
this.handleBatchImport();
......@@ -785,6 +833,25 @@ export default {
}
});
},
handleConfirmImportExtension() {
this.$refs.fileRuleFormExtension.validate((valid) => {
if (valid) {
yanbaoImport({ file: this.fileInfoExtension }).then((res) => {
if (res) {
const list = [...this.updateList, {
name: this.fileFormExtension.fileName,
ifSuccess: false,
uuid: res,
type: "upload",
}];
this.actionSetDownloadList({ list, type: "updateList" });
this.notice.okTips("上传成功");
this.handleBatchImportExtension();
}
});
}
});
},
handleReset() {
this.searchForm = this.$options.data.call(this).searchForm;
this.tempGoodsType = [];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!