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 @@