AnalysisSystemForRadionucli.../src/views/spectrumAnalysis/components/Modals/SpectrumCommentsModal.vue

91 lines
2.2 KiB
Vue
Raw Normal View History

<template>
<custom-modal v-model="visible" title="Spectrum Comments" :okHandler="handleOk" :footer="isAdd ? undefined : null">
<a-spin :spinning="isLoading">
<a-textarea v-model="comments" :rows="8" :disabled="!isAdd"></a-textarea>
</a-spin>
</custom-modal>
</template>
<script>
2023-09-26 14:40:08 +08:00
import { getAction, putAction } from '@/api/manage'
import ModalMixin from '@/mixins/ModalMixin'
import SampleDataMixin from '../../SampleDataMixin'
export default {
mixins: [ModalMixin, SampleDataMixin],
props: {
isAdd: {
type: Boolean,
2023-09-26 14:40:08 +08:00
default: true,
},
},
data() {
return {
isLoading: false,
2023-09-26 14:40:08 +08:00
comments: '',
}
},
methods: {
// ModalMixin 中的生命周期方法
beforeModalOpen() {
if (this.isAdd) {
this.comments = ''
2023-09-26 14:40:08 +08:00
this.getTotalComment()
} else {
this.getInfo()
}
},
2023-09-26 14:40:08 +08:00
// View接口
async getInfo() {
try {
this.isLoading = true
const { sampleId, inputFileName: fileName } = this.sampleData
const { success, result, message } = await getAction('/gamma/viewComment', {
sampleId,
2023-09-26 14:40:08 +08:00
fileName,
})
this.isLoading = false
if (success) {
this.comments = result
} else {
this.$message.error(message)
}
} catch (error) {
console.error(error)
}
},
2023-09-26 14:40:08 +08:00
// Add 获取 Comment 接口
async getTotalComment() {
try {
this.isLoading = true
const { inputFileName: fileName } = this.sampleData
const { success, result, message } = await getAction('/gamma/viewGeneralComment', {
fileName,
})
this.isLoading = false
if (success) {
this.comments = result
} else {
this.$message.error(message)
}
} catch (error) {
console.error(error)
}
},
async handleOk() {
const { inputFileName: fileName } = this.sampleData
const { success, message } = await putAction(`/gamma/addComment?fileName=${fileName}&comment=${this.comments}`)
if (!success) {
this.$message.error(message)
throw new Error(message)
}
},
},
}
</script>
<style></style>