feat: fix 401 auth error and bridge stocktake discrepancies to adjustment module
This commit is contained in:
@ -13,6 +13,9 @@
|
||||
<el-option label="已取消" value="cancelled" />
|
||||
</el-select>
|
||||
<el-button type="primary" @click="fetchData">查询</el-button>
|
||||
<el-button v-if="userStore.hasPermission('stock_adjustment:operation')" type="warning" @click="handleImportStocktake">
|
||||
一键引入盘点差异
|
||||
</el-button>
|
||||
<el-button v-if="userStore.hasPermission('stock_adjustment:operation')" type="success" @click="showDialog = true">
|
||||
新增调整单
|
||||
</el-button>
|
||||
@ -132,8 +135,9 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import request from '@/utils/request'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
@ -182,19 +186,20 @@ const selectedStock = ref<any>(null)
|
||||
async function fetchData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
page: page.value.toString(),
|
||||
limit: limit.value.toString()
|
||||
const res = await request({
|
||||
url: '/api/v1/stock/adjustment/list',
|
||||
method: 'get',
|
||||
params: {
|
||||
page: page.value,
|
||||
limit: limit.value,
|
||||
keyword: keyword.value || undefined,
|
||||
adjust_type: searchAdjustType.value || undefined,
|
||||
status: searchStatus.value || undefined
|
||||
}
|
||||
})
|
||||
if (keyword.value) params.append('keyword', keyword.value)
|
||||
if (searchAdjustType.value) params.append('adjust_type', searchAdjustType.value)
|
||||
if (searchStatus.value) params.append('status', searchStatus.value)
|
||||
|
||||
const res = await fetch(`/api/v1/stock/adjustment/list?${params}`)
|
||||
const json = await res.json()
|
||||
if (json.code === 200) {
|
||||
list.value = json.data.items
|
||||
total.value = json.data.total
|
||||
if (res.code === 200) {
|
||||
list.value = res.data.items
|
||||
total.value = res.data.total
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('获取数据失败')
|
||||
@ -207,18 +212,19 @@ async function fetchData() {
|
||||
async function fetchStocks() {
|
||||
stockLoading.value = true
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
source_table: form.value.source_table,
|
||||
page: stockPage.value.toString(),
|
||||
limit: stockLimit.value.toString()
|
||||
const res = await request({
|
||||
url: '/api/v1/stock/adjustment/stocks',
|
||||
method: 'get',
|
||||
params: {
|
||||
source_table: form.value.source_table,
|
||||
page: stockPage.value,
|
||||
limit: stockLimit.value,
|
||||
keyword: stockKeyword.value || undefined
|
||||
}
|
||||
})
|
||||
if (stockKeyword.value) params.append('keyword', stockKeyword.value)
|
||||
|
||||
const res = await fetch(`/api/v1/stock/adjustment/stocks?${params}`)
|
||||
const json = await res.json()
|
||||
if (json.code === 200) {
|
||||
stockList.value = json.data.items
|
||||
stockTotal.value = json.data.total
|
||||
if (res.code === 200) {
|
||||
stockList.value = res.data.items
|
||||
stockTotal.value = res.data.total
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('获取库存失败')
|
||||
@ -263,13 +269,12 @@ async function submitForm() {
|
||||
|
||||
submitLoading.value = true
|
||||
try {
|
||||
const res = await fetch('/api/v1/stock/adjustment/create', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form.value)
|
||||
const res = await request({
|
||||
url: '/api/v1/stock/adjustment/create',
|
||||
method: 'post',
|
||||
data: form.value
|
||||
})
|
||||
const json = await res.json()
|
||||
if (json.code === 200) {
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('提交成功')
|
||||
showDialog.value = false
|
||||
fetchData()
|
||||
@ -283,7 +288,7 @@ async function submitForm() {
|
||||
}
|
||||
selectedStock.value = null
|
||||
} else {
|
||||
ElMessage.error(json.msg || '提交失败')
|
||||
ElMessage.error(res.msg || '提交失败')
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('提交失败')
|
||||
@ -292,6 +297,31 @@ async function submitForm() {
|
||||
}
|
||||
}
|
||||
|
||||
// 一键引入盘点差异
|
||||
async function handleImportStocktake() {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要将当前所有的盘点差异导入为盘盈盘亏单吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
const res = await request({
|
||||
url: '/api/v1/stock/adjustment/import-from-stocktake',
|
||||
method: 'post'
|
||||
})
|
||||
if (res.code === 200) {
|
||||
ElMessage.success(`成功导入 ${res.data.count} 条盘点差异记录`)
|
||||
fetchData()
|
||||
} else {
|
||||
ElMessage.error(res.msg || '导入失败')
|
||||
}
|
||||
} catch (e) {
|
||||
if (e !== 'cancel') {
|
||||
ElMessage.error('导入失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user