diff --git a/base-vue/src/main.js b/base-vue/src/main.js index e12bece..ee31c82 100644 --- a/base-vue/src/main.js +++ b/base-vue/src/main.js @@ -47,6 +47,12 @@ Vue.prototype.$genders=['男','女'] // 保存整站vuex本地储存初始状态 window.SITE_CONFIG['storeState'] = cloneDeep(store.state) +Vue.filter('findByValue', (array, value) => { + if (!Array.isArray(array)) return '' + const item = array.find(item => String(item.value) === String(value)) + return item ? item.label : '' +}) + /* eslint-disable no-new */ new Vue({ el: '#app', diff --git a/base-vue/src/utils/dict.js b/base-vue/src/utils/dict.js index c9b4e89..365e067 100644 --- a/base-vue/src/utils/dict.js +++ b/base-vue/src/utils/dict.js @@ -1,60 +1,44 @@ -import httpRequest from '@/utils/httpRequest' - -export default class Dict { - constructor(dict = {}) { - this.dict = dict - } - async init(names) { - if (names === undefined || names === null) { - throw new Error('need Dict names') +export const apiUtils = { + data () { + return { + dictData: [] } - const ps = [] - names.forEach(n => { - ps.push(httpRequest({ - url: httpRequest.adornUrl(`/api/dict/dictDetail?code=${n}&page=0&size=9999`), + }, + activated () { + Promise.all( + this.dictConfigs.map(config => + this.fetchData(config.url, config.type, config.code, config.value, config.label) + ) + ).then((data) => { + this.dictData = [...data] + console.log(this.dictData) + }).catch(err => { + console.error('某个请求失败:', err) + }) + }, + methods: { + fetchData(url, type, code, valueKey, labelKey) { + const _url = type === 'dict' ? `/api/dict/dictDetail?code=${code}&page=0&size=9999` : `${url}?&page=0&size=9999` + return this.$http({ + url: this.$http.adornUrl(_url), method: 'get' }).then(({data}) => { - this.dict[n] = [...data.content] - })) - }) - await Promise.all(ps) - } - - get() { - return this.dict - } -} - -const myDict = new Dict() - -function dictDetail (names) { - return { - data () { - return { - dicts: names, - dictsOpt: myDict.get('contract_type') - } - }, - filters: { - dictLabel (index, array) { - if (array === null || array === undefined) { - return null + let list = [] + if (type === 'dict') { + list = [...data.content] } - const value = String(index) - const valueToLabelMap = new Map(array.map(item => [String(item.value), item.label])) - const label = valueToLabelMap.get(value) - return label - } - }, - beforeCreate () { - myDict.init(names).then(() => { - this.dictsOpt = myDict.get() + if (type === 'list') { + data.page.list.map(item => { + item.value = String(item[valueKey]) + item.label = item[labelKey] + }) + list = [...data.page.list] + } + return list + }).catch(err => { + console.error('请求失败:', err) }) } } } -export { - dictDetail -} - diff --git a/base-vue/src/views/modules/contract/contract-add-or-update.vue b/base-vue/src/views/modules/contract/contract-add-or-update.vue index e7c4095..b2cb03d 100644 --- a/base-vue/src/views/modules/contract/contract-add-or-update.vue +++ b/base-vue/src/views/modules/contract/contract-add-or-update.vue @@ -10,7 +10,7 @@ @@ -41,7 +41,7 @@ @@ -153,6 +153,24 @@ + + + + + + { if (data && data.code === 0) { - this.dataForm.contractType = data.contract.contractType + this.dataForm.contractType = String(data.contract.contractType) this.dataForm.isMaster = data.contract.isMaster this.dataForm.contractNumber = data.contract.contractNumber this.dataForm.clientId = data.contract.clientId this.dataForm.materialJson = data.contract.materialJson this.dataForm.isAcceptance = data.contract.isAcceptance this.dataForm.remarks = data.contract.remarks - this.materData = JSON.parse(data.contract.materialJson) + this.materData = JSON.parse(data.contract.materialJson).material } }) this.getFile() @@ -376,7 +393,7 @@ 'isMaster': this.dataForm.isMaster, 'contractNumber': this.dataForm.contractNumber, 'clientId': this.dataForm.clientId, - 'materialJson': JSON.stringify(this.materData), + 'materialJson': JSON.stringify({material: this.materData, total: this.dataForm.totalSum}), 'isAcceptance': this.dataForm.isAcceptance, 'remarks': this.dataForm.remarks, 'storageId': `${ids}${this.dataForm.storageId}` @@ -389,6 +406,7 @@ duration: 1500, onClose: () => { this.$refs.upload.clearFiles() + this.activeName = 'first' this.visible = false this.$emit('refreshDataList') } diff --git a/base-vue/src/views/modules/contract/contract.vue b/base-vue/src/views/modules/contract/contract.vue index b699975..9b8a7bc 100644 --- a/base-vue/src/views/modules/contract/contract.vue +++ b/base-vue/src/views/modules/contract/contract.vue @@ -28,32 +28,13 @@ header-align="center" align="center" label="合同ID"> - + label="验收时间"> - + @@ -136,7 +117,7 @@