diff --git a/src/views/dictionary/institutions/components/HospitalForm.vue b/src/views/dictionary/institutions/components/HospitalForm.vue index 504d4c89..70d647af 100644 --- a/src/views/dictionary/institutions/components/HospitalForm.vue +++ b/src/views/dictionary/institutions/components/HospitalForm.vue @@ -9,8 +9,19 @@ >
- - + + @@ -20,10 +31,16 @@ - + - + @@ -45,10 +62,22 @@
- - - - - {{ isEN ? item.HospitalName : item.HospitalNameCN }} - - - + @change="handleChange" + > + + + - + - + { RankOther: '', RankOtherCN: '', HospitalId: '', + HospitalName: null, + HospitalNameCN: null, WorkPartTime: null, WorkPartTimeEn: null, UniversityAffiliated: null, @@ -616,11 +632,18 @@ export default { trigger: 'blur', }, ], - HospitalId: [ + HospitalName: [ { required: true, - message: this.$t('common:ruleMessage:select'), - trigger: 'blur', + message: this.$t('common:ruleMessage:specify'), + trigger: ['blur', 'change'], + }, + ], + HospitalNameCN: [ + { + required: true, + message: this.$t('common:ruleMessage:specify'), + trigger: ['blur', 'change'], }, ], UniversityAffiliated: [ @@ -648,16 +671,72 @@ export default { loading: false, dictionaryList: {}, otherId: 'ef84e9cb-f1a6-49d7-b6da-34be2c12abd5', + hospitalSelectList: [], } }, computed: { ...mapGetters(['hospitalList']), }, + watch: { + hospitalList: { + handler() { + if (!Array.isArray(this.hospitalList) || this.hospitalList.length <= 0) + return false + this.hospitalSelectList = [] + this.hospitalList.forEach((item) => { + if (this.isEN) { + this.hospitalSelectList.push({ + value: item.HospitalName, + ...item, + }) + } else { + this.hospitalSelectList.push({ + value: item.HospitalNameCN, + ...item, + }) + } + }) + }, + deep: true, + }, + }, mounted() { this.getDicData() store.dispatch('global/getHospital') }, methods: { + handleChange(v) { + if (v) return + this.form.UniversityAffiliated = null + this.form.City = null + this.form.UniversityAffiliatedCN = null + this.form.CityCN = null + }, + querySearch(queryString, cb) { + var hospitalList = this.hospitalSelectList + var results = queryString + ? hospitalList.filter(this.createFilter(queryString)) + : hospitalList + // 调用 callback 返回建议列表的数据 + cb(results) + }, + createFilter(queryString) { + return (hospitalList) => { + if (this.isEN) { + return ( + hospitalList.HospitalName.toLowerCase().indexOf( + queryString.toLowerCase() + ) >= 0 + ) + } else { + return ( + hospitalList.HospitalNameCN.toLowerCase().indexOf( + queryString.toLowerCase() + ) >= 0 + ) + } + } + }, openEdit() { this.form = defaultForm() Object.keys(this.form).forEach((key) => { @@ -666,8 +745,6 @@ export default { } }) this.model_cfg.visible = true - console.log(this.form) - console.log(this.DATA) }, handleCancle() { this.form = defaultForm() @@ -680,8 +757,13 @@ export default { if (this.reviewerId) { this.form.Id = this.reviewerId } + let data = Object.assign({}, this.form) + if (!this.hospitalList.find((item) => item.Id === data.HospitalId)) { + data.HospitalName = data.HospitalId + data.HospitalId = null + } this.loading = true - let res = await addOrUpdateDoctorBasicInfoAndEmployment(this.form) + let res = await addOrUpdateDoctorBasicInfoAndEmployment(data) this.loading = false if (res.IsSuccess) { this.$emit('update:reviewerId', res.Result.Id) @@ -701,13 +783,18 @@ export default { }) .catch(() => {}) }, - handleHospitalChange(value) { - const item = this.hospitalList.filter((item) => item.Id === value) - if (item.length) { - this.form.UniversityAffiliated = item[0].UniversityAffiliated - this.form.City = item[0].City - this.form.UniversityAffiliatedCN = item[0].UniversityAffiliatedCN - this.form.CityCN = item[0].CityCN + handleSelect(value) { + const item = value + if (item) { + this.form.UniversityAffiliated = item.UniversityAffiliated + this.form.City = item.City + this.form.UniversityAffiliatedCN = item.UniversityAffiliatedCN + this.form.CityCN = item.CityCN + } else { + this.form.UniversityAffiliated = null + this.form.City = null + this.form.UniversityAffiliatedCN = null + this.form.CityCN = null } }, },