This commit is contained in:
Leo
2025-11-14 00:02:45 +08:00
parent 47951ab5ea
commit 101b3dae54
2 changed files with 63 additions and 50 deletions

View File

@@ -43,7 +43,7 @@ export function delErpProduct(ids) {
}) })
} }
// 拉取商品列表 // 拉取商品列表(单页,兼容)
export function pullProductList(data) { export function pullProductList(data) {
return request({ return request({
url: '/jarvis/erpProduct/pull', url: '/jarvis/erpProduct/pull',
@@ -52,6 +52,15 @@ export function pullProductList(data) {
}) })
} }
// 全量同步商品(自动遍历所有页码)
export function syncAllProducts(data) {
return request({
url: '/jarvis/erpProduct/syncAll',
method: 'post',
params: data
})
}
// 批量上架 // 批量上架
export function batchPublish(data) { export function batchPublish(data) {
return request({ return request({

View File

@@ -54,11 +54,11 @@
<el-button <el-button
type="primary" type="primary"
plain plain
icon="el-icon-download" icon="el-icon-refresh"
size="mini" size="mini"
@click="handlePull" @click="handleSyncAll"
v-hasPermi="['jarvis:erpProduct:pull']" v-hasPermi="['jarvis:erpProduct:pull']"
>拉取商品</el-button> >全量同步</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
@@ -208,11 +208,11 @@
@pagination="getList" @pagination="getList"
/> />
<!-- 拉取商品对话框 --> <!-- 全量同步对话框 -->
<el-dialog title="拉取闲鱼商品" :visible.sync="pullDialogVisible" width="500px" append-to-body> <el-dialog title="全量同步闲鱼商品" :visible.sync="syncDialogVisible" width="500px" append-to-body>
<el-form ref="pullForm" :model="pullForm" label-width="100px"> <el-form ref="syncForm" :model="syncForm" label-width="100px">
<el-form-item label="ERP应用"> <el-form-item label="ERP应用">
<el-select v-model="pullForm.appid" placeholder="请选择ERP应用" style="width: 100%"> <el-select v-model="syncForm.appid" placeholder="请选择ERP应用" style="width: 100%">
<el-option <el-option
v-for="item in erpAccountList" v-for="item in erpAccountList"
:key="item.value" :key="item.value"
@@ -222,7 +222,8 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="商品状态"> <el-form-item label="商品状态">
<el-select v-model="pullForm.productStatus" placeholder="请选择(留空为全部)" clearable style="width: 100%"> <el-select v-model="syncForm.productStatus" placeholder="请选择(留空为全部)" clearable style="width: 100%">
<el-option label="全部" :value="null" />
<el-option label="上架" :value="1" /> <el-option label="上架" :value="1" />
<el-option label="下架" :value="2" /> <el-option label="下架" :value="2" />
<el-option label="已售" :value="3" /> <el-option label="已售" :value="3" />
@@ -230,19 +231,15 @@
<el-option label="审核中" :value="23" /> <el-option label="审核中" :value="23" />
</el-select> </el-select>
<div style="color: #909399; font-size: 12px; margin-top: 5px;"> <div style="color: #909399; font-size: 12px; margin-top: 5px;">
提示留空表示拉取全部状态的商品 <div> 留空表示同步全部状态的商品</div>
<div> 系统将自动遍历所有页码同步所有商品</div>
<div> 会自动更新本地已有商品删除远程已不存在的商品</div>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="页码">
<el-input-number v-model="pullForm.pageNo" :min="1" :max="1000" style="width: 100%" />
</el-form-item>
<el-form-item label="每页大小">
<el-input-number v-model="pullForm.pageSize" :min="1" :max="200" style="width: 100%" />
</el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitPull" :loading="pulling"> </el-button> <el-button type="primary" @click="submitSyncAll" :loading="syncing">开始同步</el-button>
<el-button @click="pullDialogVisible = false"> </el-button> <el-button @click="syncDialogVisible = false"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
@@ -336,7 +333,7 @@
</template> </template>
<script> <script>
import { listErpProduct, getErpProduct, delErpProduct, pullProductList, batchPublish, batchDownShelf, getERPAccounts, getUsernames } from "@/api/system/erpProduct"; import { listErpProduct, getErpProduct, delErpProduct, pullProductList, syncAllProducts, batchPublish, batchDownShelf, getERPAccounts, getUsernames } from "@/api/system/erpProduct";
export default { export default {
name: "ErpProduct", name: "ErpProduct",
@@ -369,15 +366,13 @@ export default {
}, },
// ERP账号列表 // ERP账号列表
erpAccountList: [], erpAccountList: [],
// 拉取对话框 // 全量同步对话框
pullDialogVisible: false, syncDialogVisible: false,
pullForm: { syncForm: {
appid: null, appid: null,
productStatus: null, productStatus: null
pageNo: 1,
pageSize: 50
}, },
pulling: false, syncing: false,
// 查看对话框 // 查看对话框
viewDialogVisible: false, viewDialogVisible: false,
viewForm: null, viewForm: null,
@@ -460,42 +455,51 @@ export default {
this.single = selection.length !== 1; this.single = selection.length !== 1;
this.multiple = !selection.length; this.multiple = !selection.length;
}, },
/** 拉取商品按钮操作 */ /** 全量同步按钮操作 */
handlePull() { handleSyncAll() {
if (!this.queryParams.appid) { if (!this.queryParams.appid) {
this.$modal.msgWarning("请先选择ERP账号"); this.$modal.msgWarning("请先选择ERP账号");
return; return;
} }
this.pullDialogVisible = true; this.syncDialogVisible = true;
this.pullForm = { this.syncForm = {
appid: this.queryParams.appid, appid: this.queryParams.appid,
productStatus: null, productStatus: null
pageNo: 1,
pageSize: 50
}; };
}, },
/** 提交拉取 */ /** 提交全量同步 */
submitPull() { submitSyncAll() {
if (!this.pullForm.appid) { if (!this.syncForm.appid) {
this.$modal.msgWarning("请选择ERP账号"); this.$modal.msgWarning("请选择ERP账号");
return; return;
} }
this.pulling = true;
pullProductList(this.pullForm).then(response => { this.$confirm(
if (response.code === 200) { '全量同步将自动遍历所有页码,同步所有商品数据,并删除远程已不存在的本地商品。是否继续?',
// 使用msg信息可能是成功或提示信息 '确认全量同步',
this.$modal.msgSuccess(response.msg || "拉取成功"); {
// 如果拉取成功,刷新列表 confirmButtonText: '确定同步',
if (response.msg && response.msg.includes("成功拉取并保存") && response.msg.match(/\d+/)) { cancelButtonText: '取消',
this.getList(); type: 'warning'
}
} else {
this.$modal.msgError(response.msg || "拉取失败");
} }
this.pullDialogVisible = false; ).then(() => {
this.pulling = false; this.syncing = true;
syncAllProducts(this.syncForm).then(response => {
if (response.code === 200) {
this.$modal.msgSuccess(response.msg || "同步成功");
this.syncDialogVisible = false;
// 刷新列表
this.getList();
} else {
this.$modal.msgError(response.msg || "同步失败");
}
this.syncing = false;
}).catch((error) => {
this.$modal.msgError(error.message || "同步失败");
this.syncing = false;
});
}).catch(() => { }).catch(() => {
this.pulling = false; // 用户取消
}); });
}, },
/** 查看按钮操作 */ /** 查看按钮操作 */