Commit 1bb53049 by 张立顺

feat 功能联调

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