按租户拉取goods
This commit is contained in:
@@ -2,6 +2,23 @@
|
||||
<div class="app-container">
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :model="queryParams" :inline="true" label-width="90px">
|
||||
<el-form-item label="租户ID">
|
||||
<el-select
|
||||
v-model="queryParams.tenantId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择租户"
|
||||
style="width: 220px"
|
||||
:loading="tenantLoading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in tenantOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="用户ID">
|
||||
<el-input v-model="queryParams.userId" clearable placeholder="所属用户ID" style="width: 140px" />
|
||||
</el-form-item>
|
||||
@@ -65,9 +82,8 @@
|
||||
<el-button
|
||||
type="warning"
|
||||
icon="el-icon-refresh"
|
||||
:loading="syncLoading"
|
||||
style="margin-left: 12px"
|
||||
@click="handleSyncFromHxr"
|
||||
@click="openSyncDialog"
|
||||
>
|
||||
同步货品
|
||||
</el-button>
|
||||
@@ -139,6 +155,32 @@
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<el-dialog title="同步货品" :visible.sync="syncDialogVisible" width="520px" @close="resetSyncForm">
|
||||
<el-form ref="syncFormRef" :model="syncForm" :rules="syncFormRules" label-width="100px">
|
||||
<el-form-item label="租户ID" prop="tenantId">
|
||||
<el-select
|
||||
v-model="syncForm.tenantId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择租户"
|
||||
style="width: 100%"
|
||||
:loading="tenantLoading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in tenantOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="syncDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="syncLoading" @click="submitSyncFromHxr">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="帮我抢单" :visible.sync="rushBuyDialogVisible" width="520px" @close="resetRushBuyForm">
|
||||
<el-form ref="rushBuyFormRef" :model="rushBuyForm" :rules="rushBuyRules" label-width="130px">
|
||||
<el-form-item label="租户ID">
|
||||
@@ -254,6 +296,7 @@ import {
|
||||
syncLbGoodsFromHxr,
|
||||
updateLbGoods
|
||||
} from '@/api/lb-goods'
|
||||
import { getAllTenantList } from '@/api/tenant'
|
||||
import { getBusinessHeaders } from '@/utils/business-headers'
|
||||
|
||||
function emptyForm() {
|
||||
@@ -328,6 +371,15 @@ export default {
|
||||
loading: false,
|
||||
submitLoading: false,
|
||||
syncLoading: false,
|
||||
syncDialogVisible: false,
|
||||
tenantLoading: false,
|
||||
tenantOptions: [],
|
||||
syncForm: {
|
||||
tenantId: ''
|
||||
},
|
||||
syncFormRules: {
|
||||
tenantId: [{ required: true, message: '请选择租户', trigger: 'change' }]
|
||||
},
|
||||
rushBuyLoading: false,
|
||||
rushBuyDialogVisible: false,
|
||||
apiToken: '',
|
||||
@@ -359,6 +411,7 @@ export default {
|
||||
queryParams: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
tenantId: '',
|
||||
userId: '',
|
||||
title: '',
|
||||
sellerId: '',
|
||||
@@ -379,6 +432,8 @@ export default {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getTenantOptions()
|
||||
this.initDefaultTenantFilter()
|
||||
this.fetchList()
|
||||
},
|
||||
methods: {
|
||||
@@ -387,31 +442,74 @@ export default {
|
||||
const value = headers && headers['X-Tenant-Id']
|
||||
return value ? String(value).trim() : ''
|
||||
},
|
||||
initDefaultTenantFilter() {
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (tenantId) this.queryParams.tenantId = tenantId
|
||||
},
|
||||
getApiTokenParam() {
|
||||
const token = (this.apiToken || '').trim()
|
||||
return token ? { token } : {}
|
||||
},
|
||||
handleSyncFromHxr() {
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (!tenantId) {
|
||||
this.$message.error('未获取到租户ID,请先登录或配置业务请求头中的租户')
|
||||
return
|
||||
}
|
||||
this.syncLoading = true
|
||||
syncLbGoodsFromHxr({ tenantId, ...this.getApiTokenParam() })
|
||||
.then((res) => {
|
||||
const isSuccess = res && (res.success === true || res.code === 200 || res.code === 20000)
|
||||
if (!isSuccess) {
|
||||
this.$message.error((res && res.message) || '同步货品失败')
|
||||
return
|
||||
getTenantOptions() {
|
||||
this.tenantLoading = true
|
||||
getAllTenantList()
|
||||
.then((response) => {
|
||||
if (response && (response.code === 20000 || response.code === 200)) {
|
||||
const tenantList = Array.isArray(response.data) ? response.data : (response.data?.data || [])
|
||||
this.tenantOptions = tenantList.map((item) => ({
|
||||
value: item.id,
|
||||
label: item.tenantName ? `${item.tenantName} (${item.tenantCode || '-'})` : (item.tenantCode || item.id)
|
||||
}))
|
||||
} else {
|
||||
this.tenantOptions = []
|
||||
}
|
||||
this.$message.success((res && res.message) || '同步货品成功')
|
||||
this.fetchList()
|
||||
})
|
||||
.catch(() => {
|
||||
this.tenantOptions = []
|
||||
})
|
||||
.finally(() => {
|
||||
this.syncLoading = false
|
||||
this.tenantLoading = false
|
||||
})
|
||||
},
|
||||
openSyncDialog() {
|
||||
const defaultTenantId = (this.queryParams.tenantId || '').trim() || this.getTenantIdFromBusinessHeaders()
|
||||
this.syncForm = {
|
||||
tenantId: defaultTenantId || ''
|
||||
}
|
||||
this.syncDialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.syncFormRef && this.$refs.syncFormRef.clearValidate()
|
||||
})
|
||||
},
|
||||
resetSyncForm() {
|
||||
this.syncForm = { tenantId: '' }
|
||||
this.$refs.syncFormRef && this.$refs.syncFormRef.resetFields()
|
||||
},
|
||||
submitSyncFromHxr() {
|
||||
this.$refs.syncFormRef.validate((valid) => {
|
||||
if (!valid) return
|
||||
const tenantId = (this.syncForm.tenantId || '').trim()
|
||||
if (!tenantId) {
|
||||
this.$message.error('请选择租户')
|
||||
return
|
||||
}
|
||||
this.syncLoading = true
|
||||
syncLbGoodsFromHxr({ tenantId, ...this.getApiTokenParam() })
|
||||
.then((res) => {
|
||||
const isSuccess = res && (res.success === true || res.code === 200 || res.code === 20000)
|
||||
if (!isSuccess) {
|
||||
this.$message.error((res && res.message) || '同步货品失败')
|
||||
return
|
||||
}
|
||||
this.$message.success((res && res.message) || '同步货品成功')
|
||||
this.syncDialogVisible = false
|
||||
this.fetchList()
|
||||
})
|
||||
.finally(() => {
|
||||
this.syncLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
openRushBuyDialog() {
|
||||
this.rushBuyDialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
@@ -490,7 +588,7 @@ export default {
|
||||
status: parseOptionalInt(this.queryParams.status),
|
||||
currentPage: this.queryParams.currentPage || undefined
|
||||
}
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
const tenantId = (this.queryParams.tenantId || '').trim() || undefined
|
||||
if (tenantId) params.tenantId = tenantId
|
||||
if (Array.isArray(this.createdAtRange) && this.createdAtRange.length === 2) {
|
||||
params.createdAtStart = this.createdAtRange[0]
|
||||
@@ -513,6 +611,7 @@ export default {
|
||||
this.queryParams = {
|
||||
current: 1,
|
||||
size: 10,
|
||||
tenantId: '',
|
||||
userId: '',
|
||||
title: '',
|
||||
sellerId: '',
|
||||
|
||||
Reference in New Issue
Block a user