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) {
return request({
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) {
return request({

View File

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