diff --git a/.env.development b/.env.development index fbc58ec..b68c1ee 100644 --- a/.env.development +++ b/.env.development @@ -1,17 +1,8 @@ # just a flag ENV='development' -#VUE_APP_BASE_API = http://192.168.60.99:8004/ -VUE_APP_UPLOAD_API = http://192.168.60.99:8004/api/admin/upload-file -VUE_APP_OA_URL= http://192.168.60.18:8001 -VUE_APP_OA_URL_TYPE = '{"采购入库":51,"请示入库":54,"调拨入库":55,"领用出库":56,"处置出库":57,"调令出库":53}' - - -#正式 - -VUE_APP_BASE_API = http://192.168.60.99:8004 -#VUE_APP_UPLOAD_API = http://192.168.60.99:9004/api/admin/upload-file - -# 正式oa -#VUE_APP_OA_URL = http://192.168.60.18:2021 -#VUE_APP_OA_URL_TYPE = '{"采购入库":51,"请示入库":54,"调拨入库":55,"领用出库":56,"处置出库":57,"调令出库":53}' +# 本地开发环境配置 +VUE_APP_BASE_API=http://wzgl.localhost/ +VUE_APP_UPLOAD_API=http://wzgl.localhost/api/admin/upload-file +VUE_APP_OA_URL=http://192.168.60.18:8001 +VUE_APP_OA_URL_TYPE='{"采购入库":51,"请示入库":54,"调拨入库":55,"领用出库":56,"处置出库":57,"调令出库":53}' diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 53fc51a..8f8d0f6 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -18,7 +18,8 @@ const getDefaultState = () => { token: getToken(), name: '', avatar: '', - roles: [] + roles: [], + area_id: null } } @@ -39,6 +40,9 @@ const mutations = { }, SET_ROLES: (state, roles) => { state.roles = roles + }, + SET_AREA_ID: (state, area_id) => { + state.area_id = area_id } } @@ -48,7 +52,7 @@ const actions = { }, userInfo) { const { token, - tp, + tp, loginId } = userInfo @@ -57,8 +61,8 @@ const actions = { token: token, tp: tp, loginId: loginId - }).then(response => { - // console.log(response) + }).then(response => { + // console.log(response) const { data @@ -105,7 +109,7 @@ const actions = { state }) { return new Promise((resolve, reject) => { - getInfo(state.token).then(response => { + getInfo(state.token).then(response => { if (!response) { reject('身份验证失败请重新登录') } @@ -113,12 +117,14 @@ const actions = { const { roles, name, - avatar + avatar, + area_id } = response commit('SET_ROLES', roles) commit('SET_NAME', name) commit('SET_AVATAR', avatar) + commit('SET_AREA_ID', area_id) resolve(response) }).catch(error => { reject(error) @@ -131,7 +137,7 @@ const actions = { commit, state }) { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { console.log('logout', state.token) logout(state.token).then(() => { removeToken() // must remove token first @@ -161,4 +167,4 @@ export default { state, mutations, actions -} +} diff --git a/src/views/floodEntry/components/addEntry.vue b/src/views/floodEntry/components/addEntry.vue index 175bdfd..aaef8a7 100644 --- a/src/views/floodEntry/components/addEntry.vue +++ b/src/views/floodEntry/components/addEntry.vue @@ -282,40 +282,43 @@ export default { }) }, async getDetail() { - const res = await show({ - id: this.id, - table_name: this.tableName - }) - this.form = { - rukuriqi: res?.rukuriqi || '', - jingbanren: res?.jingbanren || '', - fujian: res?.fujian ? (Array.isArray(res.fujian) ? res.fujian : JSON.parse(res.fujian)) : [], - beizhu: res?.beizhu || '', - rukuwuzi: res?.rukuwuzi ? (Array.isArray(res.rukuwuzi) ? res.rukuwuzi : JSON.parse(res.rukuwuzi)) : [] - } - - // 处理附件列表 - if (this.form.fujian && this.form.fujian.length > 0) { - // 这里需要根据实际情况获取文件信息,暂时使用id构造fileList - this.fileList = this.form.fujian.map((id, index) => ({ - id: id, + try { + const data = await show({ + id: this.id, + table_name: this.tableName + }, true) + this.form = { + rukuriqi: data?.rukuriqi || '', + jingbanren: data?.jingbanren || '', + fujian: [], + beizhu: data?.beizhu || '', + rukuwuzi: [] + } + if (data?.fujian) { + const f = data.fujian + this.form.fujian = Array.isArray(f) ? f : (typeof f === 'string' && f ? JSON.parse(f) : []) + } + this.fileList = (this.form.fujian || []).map((id, index) => ({ + id: typeof id === 'object' ? id?.id : id, name: `附件${index + 1}`, url: '' })) - } - // 处理入库物资列表 - if (res.rukuwuzi) { - try { - this.materialList = Array.isArray(res.rukuwuzi) ? res.rukuwuzi : JSON.parse(res.rukuwuzi) - } catch (e) { - this.materialList = [] - } - } else { this.materialList = [] + if (data?.rukuwuzi) { + try { + const raw = typeof data.rukuwuzi === 'string' ? JSON.parse(data.rukuwuzi) : data.rukuwuzi + this.materialList = Array.isArray(raw) ? raw : [] + } catch (e) { + this.materialList = [] + } + } + } catch (e) { + Message({ type: 'error', message: '获取详情失败:' + (e?.message || '未知错误') }) + this.resetForm() } }, - submit() { + async submit() { // 验证入库物资 if (!this.materialList || this.materialList.length === 0) { Message({ @@ -334,35 +337,17 @@ export default { rukuwuzi: JSON.stringify(this.materialList) } - if (this.type === 'add') { - save(submitData).then(res => { - Message({ - type: 'success', - message: '新增成功' - }) - this.isShow = false - this.$emit('refresh') - }).catch(err => { - Message({ - type: 'error', - message: '新增失败:' + (err.message || '未知错误') - }) - }) - } else if (this.type === 'editor') { - submitData.id = this.id - save(submitData).then(res => { - Message({ - type: 'success', - message: '编辑成功' - }) - this.isShow = false - this.$emit('refresh') - }).catch(err => { - Message({ - type: 'error', - message: '编辑失败:' + (err.message || '未知错误') - }) - }) + const isAdd = this.type === 'add' + if (!isAdd) submitData.id = this.id + + try { + await save(submitData) + Message({ type: 'success', message: isAdd ? '新增成功' : '编辑成功' }) + this.isShow = false + this.$emit('refresh') + } catch (err) { + const msg = err?.response?.data?.errmsg || err?.message || '未知错误' + Message({ type: 'error', message: (isAdd ? '新增失败:' : '编辑失败:') + msg }) } } } diff --git a/src/views/floodEntry/components/addOutbound.vue b/src/views/floodEntry/components/addOutbound.vue index f2e8799..2e2a831 100644 --- a/src/views/floodEntry/components/addOutbound.vue +++ b/src/views/floodEntry/components/addOutbound.vue @@ -305,39 +305,43 @@ export default { }) }, async getDetail() { - const res = await show({ - id: this.id, - table_name: this.tableName - }) - this.form = { - chukuriqi: res?.chukuriqi || '', - jingbanren: res?.jingbanren || '', - fujian: res?.fujian ? (Array.isArray(res.fujian) ? res.fujian : JSON.parse(res.fujian)) : [], - beizhu: res?.beizhu || '', - chukuwuzi: res?.chukuwuzi ? (Array.isArray(res.chukuwuzi) ? res.chukuwuzi : JSON.parse(res.chukuwuzi)) : [] - } - - // 处理附件列表 - if (this.form.fujian && this.form.fujian.length > 0) { - this.fileList = this.form.fujian.map((id, index) => ({ - id: id, + try { + const data = await show({ + id: this.id, + table_name: this.tableName + }, true) + this.form = { + chukuriqi: data?.chukuriqi || '', + jingbanren: data?.jingbanren || '', + fujian: [], + beizhu: data?.beizhu || '', + chukuwuzi: [] + } + if (data?.fujian) { + const f = data.fujian + this.form.fujian = Array.isArray(f) ? f : (typeof f === 'string' && f ? JSON.parse(f) : []) + } + this.fileList = (this.form.fujian || []).map((id, index) => ({ + id: typeof id === 'object' ? id?.id : id, name: `附件${index + 1}`, url: '' })) - } - // 处理出库物资列表 - if (res.chukuwuzi) { - try { - this.materialList = Array.isArray(res.chukuwuzi) ? res.chukuwuzi : JSON.parse(res.chukuwuzi) - } catch (e) { - this.materialList = [] - } - } else { this.materialList = [] + if (data?.chukuwuzi) { + try { + const raw = typeof data.chukuwuzi === 'string' ? JSON.parse(data.chukuwuzi) : data.chukuwuzi + this.materialList = Array.isArray(raw) ? raw : [] + } catch (e) { + this.materialList = [] + } + } + } catch (e) { + Message({ type: 'error', message: '获取详情失败:' + (e?.message || '未知错误') }) + this.resetForm() } }, - submit() { + async submit() { // 验证出库物资 if (!this.materialList || this.materialList.length === 0) { Message({ @@ -376,35 +380,17 @@ export default { chukuwuzi: JSON.stringify(this.materialList) } - if (this.type === 'add') { - save(submitData).then(res => { - Message({ - type: 'success', - message: '新增成功' - }) - this.isShow = false - this.$emit('refresh') - }).catch(err => { - Message({ - type: 'error', - message: '新增失败:' + (err.message || '未知错误') - }) - }) - } else if (this.type === 'editor') { - submitData.id = this.id - save(submitData).then(res => { - Message({ - type: 'success', - message: '编辑成功' - }) - this.isShow = false - this.$emit('refresh') - }).catch(err => { - Message({ - type: 'error', - message: '编辑失败:' + (err.message || '未知错误') - }) - }) + const isAdd = this.type === 'add' + if (!isAdd) submitData.id = this.id + + try { + await save(submitData) + Message({ type: 'success', message: isAdd ? '新增成功' : '编辑成功' }) + this.isShow = false + this.$emit('refresh') + } catch (err) { + const msg = err?.response?.data?.errmsg || err?.message || '未知错误' + Message({ type: 'error', message: (isAdd ? '新增失败:' : '编辑失败:') + msg }) } } } diff --git a/src/views/floodEntry/components/selectMaterial.vue b/src/views/floodEntry/components/selectMaterial.vue index c951e82..81e4a7b 100644 --- a/src/views/floodEntry/components/selectMaterial.vue +++ b/src/views/floodEntry/components/selectMaterial.vue @@ -74,9 +74,19 @@ import { index } from '@/api/system/baseForm.js' import { index as getCangkuList } from '@/api/system/baseForm.js' import { Message } from 'element-ui' +import { mapState } from 'vuex' +import { getparameteritem } from '@/api/system/dictionary.js' export default { name: 'SelectMaterial', + computed: { + ...mapState('user', ['area_id']), + userAreaName() { + if (this.area_id == null || this.area_id === '') return '' + const area = (this.areaList || []).find(item => item.id == this.area_id) + return area ? area.value : '' + } + }, data() { return { isShow: false, @@ -84,6 +94,7 @@ export default { materialList: [], selectedMaterials: [], // 选中的物资 cangkuList: [], + areaList: [], searchForm: { keyword: '', guanliancangku: '' @@ -97,23 +108,43 @@ export default { }, created() { this.getCangku() + this.getAreaList() }, methods: { + async getAreaList() { + try { + const res = await getparameteritem('area') + this.areaList = res?.detail ?? [] + } catch (e) { + this.areaList = [] + } + }, async getCangku() { - const res = await getCangkuList({ - page_size: 999, - page: 1, - table_name: 'materialstorages' - }) - this.cangkuList = res.data || [] + try { + const res = await getCangkuList({ + page_size: 999, + page: 1, + table_name: 'materialstorages' + }) + const list = res?.data ?? [] + // 有 area_id 时,只展示本区域仓库 + if (this.area_id != null && this.area_id !== '') { + this.cangkuList = list.filter(item => item.quyu_id == this.area_id) + } else { + this.cangkuList = list + } + } catch (e) { + this.cangkuList = [] + } }, show() { this.isShow = true - this.searchForm = { - keyword: '', - guanliancangku: '' - } + this.searchForm = { keyword: '', guanliancangku: '' } this.selectedMaterials = [] + this.pagination.page = 1 + // area_id 变化后重新获取仓库(避免登录后切换账号/区域不一致) + this.getCangku() + this.getAreaList() this.getMaterialList() }, handleClose() { @@ -122,21 +153,22 @@ export default { async getMaterialList() { this.loading = true const filters = [] - if (this.searchForm.keyword) { - filters.push({ - 'key': 'xianwuzimingcheng', - 'op': 'like', - 'value': this.searchForm.keyword - }) + filters.push({ key: 'xianwuzimingcheng', op: 'like', value: this.searchForm.keyword }) } - if (this.searchForm.guanliancangku) { - filters.push({ - 'key': 'guanliancangku', - 'op': 'eq', - 'value': this.searchForm.guanliancangku - }) + filters.push({ key: 'guanliancangku', op: 'eq', value: this.searchForm.guanliancangku }) + } + // 有 area_id 时:flood_materials 表没有 quyu_id,只存了 quyu(区域名称) + // 所以这里用 quyu = 区域名称 来筛选 + if (this.area_id != null && this.area_id !== '') { + // 确保已拿到区域名称 + if (!this.userAreaName) { + await this.getAreaList() + } + if (this.userAreaName) { + filters.push({ key: 'quyu', op: 'eq', value: this.userAreaName }) + } } try { @@ -146,13 +178,11 @@ export default { table_name: 'flood_materials', filter: filters }) - this.materialList = res.data || [] - this.pagination.total = res.total || 0 - } catch (error) { - Message({ - type: 'error', - message: '获取物资列表失败' - }) + this.materialList = res?.data ?? [] + this.pagination.total = res?.total ?? 0 + } catch (e) { + Message({ type: 'error', message: '获取物资列表失败' }) + this.materialList = [] } finally { this.loading = false } diff --git a/src/views/floodEntry/index.vue b/src/views/floodEntry/index.vue index 3b102cf..07a24ba 100644 --- a/src/views/floodEntry/index.vue +++ b/src/views/floodEntry/index.vue @@ -119,52 +119,45 @@ export default { } }, mounted() { - // this.getindex() + this.getindex() }, methods: { async getindex(page) { this.loading = true - if (page == 'page') { + if (page === 'page') { this.select.pageIndex = 1 } - const filters = [{ - 'key': 'jingbanren', - 'op': 'like', - 'value': this.select.jingbanren ? this.select.jingbanren : '' - }] + const filters = [] - // 处理入库日期范围查询 + if (this.select.jingbanren) { + filters.push({ key: 'jingbanren', op: 'like', value: this.select.jingbanren }) + } + if (this.select.keyword) { + filters.push({ key: 'beizhu', op: 'like', value: this.select.keyword }) + } if (this.select.rukuriqi && this.select.rukuriqi.length === 2) { filters.push({ - 'key': 'rukuriqi', - 'op': 'gte', - 'value': this.select.rukuriqi[0] - }) - filters.push({ - 'key': 'rukuriqi', - 'op': 'lte', - 'value': this.select.rukuriqi[1] + key: 'rukuriqi', + op: 'range', + value: `${this.select.rukuriqi[0]},${this.select.rukuriqi[1]}` }) } - // 关键词搜索(可以搜索备注等字段) - if (this.select.keyword) { - filters.push({ - 'key': 'beizhu', - 'op': 'like', - 'value': this.select.keyword + try { + const res = await index({ + page_size: this.select.pageSize, + page: this.select.pageIndex, + table_name: this.customForm.tableName, + filter: filters }) + this.list = res.data || [] + this.total = res.total ?? 0 + } catch (e) { + this.list = [] + this.total = 0 + } finally { + this.loading = false } - - const res = await index({ - page_size: this.select.pageSize, - page: this.select.pageIndex, - table_name: this.customForm.tableName, - filter: filters - }) - this.list = res.data - this.total = res.total - this.loading = false }, pageChange(e) { @@ -180,12 +173,11 @@ export default { destroy({ id: row.id, table_name: this.customForm.tableName - }).then(res => { - Message({ - type: 'success', - message: '删除成功' - }) + }).then(() => { + Message({ type: 'success', message: '删除成功' }) this.getindex() + }).catch(() => { + Message({ type: 'error', message: '删除失败' }) }) } } diff --git a/src/views/floodEntry/outbound.vue b/src/views/floodEntry/outbound.vue index 66feac4..4b782ba 100644 --- a/src/views/floodEntry/outbound.vue +++ b/src/views/floodEntry/outbound.vue @@ -119,52 +119,45 @@ export default { } }, mounted() { - // this.getindex() + this.getindex() }, methods: { async getindex(page) { this.loading = true - if (page == 'page') { + if (page === 'page') { this.select.pageIndex = 1 } - const filters = [{ - 'key': 'jingbanren', - 'op': 'like', - 'value': this.select.jingbanren ? this.select.jingbanren : '' - }] + const filters = [] - // 处理出库日期范围查询 + if (this.select.jingbanren) { + filters.push({ key: 'jingbanren', op: 'like', value: this.select.jingbanren }) + } + if (this.select.keyword) { + filters.push({ key: 'beizhu', op: 'like', value: this.select.keyword }) + } if (this.select.chukuriqi && this.select.chukuriqi.length === 2) { filters.push({ - 'key': 'chukuriqi', - 'op': 'gte', - 'value': this.select.chukuriqi[0] - }) - filters.push({ - 'key': 'chukuriqi', - 'op': 'lte', - 'value': this.select.chukuriqi[1] + key: 'chukuriqi', + op: 'range', + value: `${this.select.chukuriqi[0]},${this.select.chukuriqi[1]}` }) } - // 关键词搜索(可以搜索备注等字段) - if (this.select.keyword) { - filters.push({ - 'key': 'beizhu', - 'op': 'like', - 'value': this.select.keyword + try { + const res = await index({ + page_size: this.select.pageSize, + page: this.select.pageIndex, + table_name: this.customForm.tableName, + filter: filters }) + this.list = res.data || [] + this.total = res.total ?? 0 + } catch (e) { + this.list = [] + this.total = 0 + } finally { + this.loading = false } - - const res = await index({ - page_size: this.select.pageSize, - page: this.select.pageIndex, - table_name: this.customForm.tableName, - filter: filters - }) - this.list = res.data - this.total = res.total - this.loading = false }, pageChange(e) { @@ -180,12 +173,11 @@ export default { destroy({ id: row.id, table_name: this.customForm.tableName - }).then(res => { - Message({ - type: 'success', - message: '删除成功' - }) + }).then(() => { + Message({ type: 'success', message: '删除成功' }) this.getindex() + }).catch(() => { + Message({ type: 'error', message: '删除失败' }) }) } } diff --git a/src/views/storages/components/addMater.vue b/src/views/storages/components/addMater.vue index e263c4a..9e65618 100644 --- a/src/views/storages/components/addMater.vue +++ b/src/views/storages/components/addMater.vue @@ -18,7 +18,7 @@
一级分类
- +
@@ -53,7 +63,17 @@ 二级分类
- +
@@ -63,7 +83,17 @@ 所属种类
- +
@@ -73,7 +103,27 @@ 区域:
- + + + +
@@ -282,6 +332,10 @@ import { import { index as getFenleilist } from '@/api/fenlei.js' +import { + getparameteritem +} from '@/api/system/dictionary.js' +import { mapState } from 'vuex' export default { props: { // 是否为本地模式(不提交到接口,只返回数据) @@ -290,6 +344,9 @@ export default { default: false } }, + computed: { + ...mapState('user', ['area_id']) + }, data() { return { isShow: false, @@ -298,8 +355,13 @@ export default { titleName: '', tableName: 'flood_materials', cangkuList: [], - fenleiList: [], + filteredCangkuList: [], + areaList: [], + fenleiList: [], fenleiName: '', + yijifenleiValue: [], + erjifenleiValue: [], + fenleiValue: [], form: { guanliancangku: '', cangkumingcheng: '', @@ -331,6 +393,26 @@ export default { guanliancangku: [{ required: true, message: '请选择仓库' + }], + fenlei: [{ + required: true, + message: '请选择所属种类(三级分类)', + trigger: 'change' + }], + quyu: [{ + required: true, + message: '区域不能为空', + trigger: 'blur' + }], + xianwuzimingcheng: [{ + required: true, + message: '请输入现物资名称', + trigger: 'blur' + }], + shuliang: [{ + required: true, + message: '请输入数量', + trigger: 'blur' }] } } @@ -339,53 +421,201 @@ export default { isShow(newVal) { if (newVal) { this.titleName = this.type === 'add' ? `新增物资` : `编辑物资` + // 设置区域值 + this.setUserArea() + // 过滤仓库列表 + this.filterCangkuList() + // 重置级联选择器 + this.yijifenleiValue = [] + this.erjifenleiValue = [] + this.fenleiValue = [] if (this.type === 'editor') { this.getDetail() } } else { this.id = '' this.type = '' + this.yijifenleiValue = [] + this.erjifenleiValue = [] + this.fenleiValue = [] this.$refs['dialog'].reset() } } }, created() { this.getFenlei() + this.getAreaList() }, methods: { + // 移除 children=[] + // 说明:不要“过滤掉叶子节点”,而是把空 children 删掉(这样第三级叶子仍然显示且可选) + removeEmptyChildren(node) { + if (Array.isArray(node)) { + return node.map(child => { + if (child.children) { + child.children = this.removeEmptyChildren(child.children) + if (child.children.length === 0) { + delete child.children + } + } + return child + }) + } + return [] + }, async getFenlei() { const res = await getFenleilist({ tree: 1, sort_type: 'ASC', sort_name: 'sort' }) - this.fenleiList = res + this.fenleiList = this.removeEmptyChildren(res) + }, + async getAreaList() { + try { + const res = await getparameteritem('area') + this.areaList = res.detail || [] + } catch (error) { + console.error('获取区域列表失败', error) + } + }, + setUserArea() { + // 根据用户的 area_id 设置区域名称 + if (this.area_id && this.areaList.length > 0) { + const area = this.areaList.find(item => item.id == this.area_id) + if (area) { + this.form.quyu = area.value + } + } + }, + filterCangkuList() { + // 根据用户的 area_id 过滤仓库列表 + // 如果用户没有 area_id(null、undefined 或空值),显示所有仓库 + if (this.area_id != null && this.area_id !== '') { + this.filteredCangkuList = this.cangkuList.filter(item => item.quyu_id == this.area_id) + } else { + // 如果没有 area_id,显示所有仓库 + this.filteredCangkuList = this.cangkuList + } + }, + // 根据 cascader value(路径id数组)拿到每一级节点 + getPathNodes(value) { + if (!Array.isArray(value) || value.length === 0) return null + const pathNodes = [] + let currentList = this.fenleiList + for (const nodeId of value) { + const node = (currentList || []).find(item => item.id == nodeId) + if (!node) return null + pathNodes.push(node) + currentList = node.children + } + return pathNodes }, - changeFenlei(e) { - console.log('e', e) - this.form.fenlei = e[e.length - 1] - console.log(this.$refs.cascaders.getCheckedNodes()) - let data = this.$refs.cascaders.getCheckedNodes() ? this.$refs.cascaders.getCheckedNodes()[0].data : null - if (data) { - this.fenleiName = data.name + // 任意一个分类选择后:同步三个分类字段 + 同步三个 cascader + handleFenleiSelected(value) { + if (!Array.isArray(value) || value.length === 0) { + this.form.yijifenlei = '' + this.form.erjifenlei = '' + this.form.fenlei = '' + this.yijifenleiValue = [] + this.erjifenleiValue = [] + this.fenleiValue = [] + return + } + + const pathNodes = this.getPathNodes(value) + if (!pathNodes || pathNodes.length === 0) { + Message({ type: 'error', message: '分类数据异常,请重新选择' }) + this.yijifenleiValue = [] + this.erjifenleiValue = [] + this.fenleiValue = [] + return + } + + const lastNode = pathNodes[pathNodes.length - 1] + // 仅允许选择叶子节点(removeEmptyChildren 后,叶子节点一般没有 children) + if (lastNode && lastNode.children && lastNode.children.length > 0) { + Message({ type: 'warning', message: '必须选择到最后一级' }) + return } - console.log(this.form.fenlei) + + this.form.yijifenlei = pathNodes[0]?.name || '' + this.form.erjifenlei = pathNodes[1]?.name || '' + this.form.fenlei = lastNode?.name || '' + + // 三个 cascader 同步成同一路径 + this.yijifenleiValue = value + this.erjifenleiValue = value + this.fenleiValue = value + }, + changeYijifenlei(value) { + this.handleFenleiSelected(value) + }, + changeErjifenlei(value) { + this.handleFenleiSelected(value) + }, + changeFenlei(value) { + this.handleFenleiSelected(value) }, setCkList(e) { if (e) { this.cangkuList = e + // 设置仓库列表后,立即过滤 + this.filterCangkuList() } }, changeCk(e) { if (e) { - const selectedWarehouse = this.cangkuList.find(item => e === item.id) + const selectedWarehouse = this.filteredCangkuList.find(item => e === item.id) if (selectedWarehouse) { this.form.guanliancangku = selectedWarehouse.id this.form.cangkumingcheng = selectedWarehouse.cangkumingcheng + + // 如果用户没有 area_id,根据仓库的 quyu_id 自动填充区域名 + if ((this.area_id == null || this.area_id === '') && selectedWarehouse.quyu_id && this.areaList.length > 0) { + const area = this.areaList.find(item => item.id == selectedWarehouse.quyu_id) + if (area) { + this.form.quyu = area.value + } + } } console.log(this.form.guanliancangku) } }, + // 根据分类名称查找对应的 ID 路径 + findFenleiPath(list, targetName, path = []) { + for (let i = 0; i < list.length; i++) { + const node = list[i] + const currentPath = [...path, node.id] + + if (node.name === targetName) { + return currentPath + } + + if (node.children && node.children.length > 0) { + const found = this.findFenleiPath(node.children, targetName, currentPath) + if (found) { + return found + } + } + } + return null + }, + // 设置级联选择器的值(编辑时回显) + setCascaderValue() { + // 以“所属种类”优先回显(最稳定),找到路径后同步三套 cascader + if (!this.fenleiList || this.fenleiList.length === 0) return + + const targetName = this.form.fenlei || this.form.erjifenlei || this.form.yijifenlei + if (!targetName) return + + const path = this.findFenleiPath(this.fenleiList, targetName) + if (path && path.length > 0) { + this.yijifenleiValue = path + this.erjifenleiValue = path + this.fenleiValue = path + } + }, async getDetail() { const res = await show({ id: this.id, @@ -417,8 +647,11 @@ export default { chubeicengji: res?.chubeicengji, shifouzhanshi: res?.shifouzhanshi, is_chart: res?.is_chart - } + // 设置级联选择器的值(需要等待 fenleiList 加载完成) + this.$nextTick(() => { + this.setCascaderValue() + }) }, submit() { console.log('this.form', this.form) @@ -433,6 +666,34 @@ export default { }) return } + if (!this.form.fenlei) { + Message({ + type: 'warning', + message: '请选择所属种类(三级分类)' + }) + return + } + if (!this.form.quyu) { + Message({ + type: 'warning', + message: '区域不能为空' + }) + return + } + if (!this.form.xianwuzimingcheng) { + Message({ + type: 'warning', + message: '请输入现物资名称' + }) + return + } + if (!this.form.shuliang) { + Message({ + type: 'warning', + message: '请输入数量' + }) + return + } // 触发事件,返回物资数据 this.$emit('material-added', { ...this.form }) @@ -442,8 +703,38 @@ export default { return } - // 正常模式,提交到接口 + // 正常模式,提交到接口前验证必填字段 if (this.type === 'add') { + // 验证必填字段 + if (!this.form.fenlei) { + Message({ + type: 'warning', + message: '请选择所属种类(三级分类)' + }) + return + } + if (!this.form.quyu) { + Message({ + type: 'warning', + message: '区域不能为空' + }) + return + } + if (!this.form.xianwuzimingcheng) { + Message({ + type: 'warning', + message: '请输入现物资名称' + }) + return + } + if (!this.form.shuliang) { + Message({ + type: 'warning', + message: '请输入数量' + }) + return + } + save({ table_name: this.tableName, ...this.form diff --git a/src/views/storages/floodmaterialfile.vue b/src/views/storages/floodmaterialfile.vue index a29e7c7..b2f922c 100644 --- a/src/views/storages/floodmaterialfile.vue +++ b/src/views/storages/floodmaterialfile.vue @@ -17,11 +17,13 @@ @@ -23,13 +23,18 @@ - + + + +