import ColCropper from '@/components/col-cropper' import ColUpload from '@/components/col-upload' import request from '@/helpers/request' import { verifyNumberIntegerAndFloat } from '@/helpers/toolsValidate' import { getCodeBaseUrl } from '@/helpers/utils' import { ElButton, ElForm, ElFormItem, ElInput, ElOption, ElOptionGroup, ElRadioButton, ElRadioGroup, ElSelect, ElDialog, ElMessage } from 'element-plus' import { defineComponent } from 'vue' import styles from './index.module.less' export type BackgroundMp3 = { url?: string track?: string } export const validator = (rule, value, callback) => { console.log(value) if (value == '') { callback(new Error('请输入收费价格')) } else if (Number(value) <= 0) { callback(new Error('收费金额必须大于0')) } else { callback() } } export default defineComponent({ name: 'music-operation', data() { const query = this.$route.query return { type: query.type || 'create', subjectList: [], tagList: [], submitLoading: false, reason: '', form: { titleImg: '', accompanimentType: 'HOMEMODE', audioType: 'MP3', xmlFileUrl: '', hasBeat: 0, mp3Url: '', bgmp3Url: '', midiUrl: '', musicSheetName: '', composer: '', musicSubject: null as any, tags: [] as string[], notation: 0, canEvaluate: 1, showFingering: 1, chargeType: 0, musicPrice: '', backgroundMp3s: [ { url: '', track: '' } ] as BackgroundMp3[] }, radioList: [], // 选中的人数 tagStatus: false, music_sheet_service_fee: 0 } }, async mounted() { document.title = this.type === 'create' ? '新建曲谱' : '编辑曲谱' try { await request .get('/api-website/sysConfig/queryByParamName', { params: { paramName: 'music_sheet_service_fee' } }) .then(res => (this.music_sheet_service_fee = res.data.paramValue)) await request.get('/api-website/open/subject/subjectSelect').then(res => { this.subjectList = res.data || [] }) await request.get('/api-website/open/MusicTag/tree').then(res => { this.tagList = res.data || [] }) if (this.$route.query.id) { this.setDetail(this.$route.query.id as string) } } catch {} }, methods: { async setDetail(id: string) { try { const res = await request.get( '/api-website/open/music/sheet/detail/' + id ) this.form.chargeType = res.data.chargeType === 'FREE' ? 0 : 2 this.form.showFingering = res.data.showFingering this.form.notation = res.data.notation this.form.canEvaluate = res.data.canEvaluate if (this.form.chargeType) { this.form.musicPrice = res.data.musicPrice } this.form.composer = res.data.composer this.form.musicSheetName = res.data.musicSheetName this.form.audioType = res.data.audioType this.form.musicSubject = Number(res.data.musicSubject) const musicTag = res.data.musicTag.split(',') this.form.tags = musicTag.map((item: any) => { return Number(item) }) this.radioList = this.form.tags as any this.form.xmlFileUrl = res.data.xmlFileUrl this.form.accompanimentType = res.data.accompanimentType this.form.titleImg = res.data.titleImg // this.form.audioType = res.data.mp3Type if (this.form.audioType === 'MP3') { this.form.hasBeat = res.data.hasBeat || 0 this.form.mp3Url = res.data.metronomeUrl || res.data.url } else { this.form.midiUrl = res.data.midiUrl } this.form.backgroundMp3s = (res.data.background || []).map( (item: any, index: any) => { if (index === 0) { this.form.bgmp3Url = item.metronomeUrl || item.audioFileUrl } return { url: this.form.hasBeat ? item.metronomeUrl : item.audioFileUrl, track: item.track } } ) this.reason = res.data.reason console.log(this.form.bgmp3Url) } catch (error) { console.log(error) } }, createSubmitData() { const { form } = this const beatType = form.hasBeat ? 'MP3_METRONOME' : 'MP3' const mp3Type = form.audioType === 'MP3' ? beatType : 'MIDI' return { audioType: form.audioType, sourceType: 'TEACHER', mp3Type, accompanimentType: form.accompanimentType, titleImg: form.titleImg, hasBeat: form.hasBeat, url: form.hasBeat ? '' : form.mp3Url, metronomeUrl: form.hasBeat ? form.mp3Url : '', showFingering: Number(form.showFingering), notation: Number(form.notation), musicTag: form.tags.join(','), musicSubject: form.musicSubject || undefined, musicSheetName: form.musicSheetName, midiUrl: form.midiUrl, xmlFileUrl: form.xmlFileUrl, canEvaluate: Number(form.canEvaluate), chargeType: form.chargeType === 0 ? 'FREE' : 'CHARGE', composer: form.composer, musicPrice: form.musicPrice, background: form.backgroundMp3s.map(item => ({ audioFileUrl: form.hasBeat ? '' : form.bgmp3Url, track: item.track, metronomeUrl: form.hasBeat ? form.bgmp3Url : '' })) } }, onFormatter(e: any) { e.target.value = verifyNumberIntegerAndFloat(e.target.value) }, onSubmit() { ;(this as any).$refs.form.validate(async (valid: any) => { if (valid) { this.submitLoading = true console.log(this.createSubmitData(), 'createSubmitData') try { if (this.$route.query.id) { await request.post('/api-website/music/sheet/update', { data: { ...this.createSubmitData(), id: this.$route.query.id } }) } else { await request.post('/api-website/music/sheet/create', { data: this.createSubmitData() }) } this.submitLoading = false ElMessage.success('上传成功') sessionStorage.setItem('musicActiveName', 'DOING') this.$router.back() } catch (error) { this.submitLoading = false } } else { this.$nextTick(() => { const isError = document.getElementsByClassName('is-error') isError[0].scrollIntoView({ block: 'center', behavior: 'smooth' }) }) return false } }) }, onDetail(type: string) { let url = `${getCodeBaseUrl('/teacher')}/#/registerProtocol` if (type === 'question') { url = `${getCodeBaseUrl('/teacher')}/muic-standard/question.html` } else if (type === 'music') { url = `${getCodeBaseUrl('/teacher')}/muic-standard/index.html` } window.open(url) } }, render() { return (
扣除手续费后该曲目预计收入为:
每人: {((parseFloat(this.form.musicPrice || '0') || 0) * (100 - this.music_sheet_service_fee)) / 100} 元/人
您的乐谱收入将在学员购买后结算到您的账户中