123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <template>
- <div>
- <el-form :model="forms" size="default" label-width="80px" ref="formRef">
- <!-- <el-form-item
- prop="instrumentIds"
- label="所属分类"
- :rules="[{ required: true, message: '请选择声部分类' }]"
- >
- <el-select
- v-model="forms.instrumentIds"
- placeholder="请选择所属分类"
- clearable
- filterable
- style="width: 50% !important"
- >
- <el-option
- v-for="item in fatherList"
- :key="item.id"
- :label="item.name"
- :value="item.id"
- >
- </el-option>
- </el-select>
- </el-form-item> -->`
- <div
- style="max-height: 400px;min-height: 300px; overflow-x: hidden; overflow-y: auto"
- >
- <el-radio-group v-model="forms.instrumentIds">
- <el-form-item
- v-for="(cbs, index) in cbsSubjectList"
- :key="index"
- :label="cbs.name"
- >
- <template v-if="cbs.instruments && cbs.instruments.length">
- <el-radio
- v-for="(item, index) in cbs.instruments"
- :key="index"
- :label="item.id"
- :disabled="item.added && item.id !== defaultId"
- >{{ item.name }}</el-radio
- >
- </template>
- </el-form-item>
- </el-radio-group>
- </div>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="$emit('close')">取 消</el-button>
- <el-button type="primary" @click="onSubmit" v-preventReClick
- >确 认</el-button
- >
- </div>
- </div>
- </template>
- <script>
- import { api_cbsSubjectPage } from "../api";
- import { subjectUpset } from "@/api/specialSetting";
- export default {
- name: "add-subject",
- props: ["fatherList", "subjectType", "detail"],
- data() {
- return {
- defaultId: null,
- cbsSubjectOption: [],
- cbsSubjectList: [],
- forms: {
- cbsSubjectId: null,
- instrumentIds: null // 分类名称
- }
- };
- },
- mounted() {
- // 修改声部
- if (this.detail.id) {
- this.forms.id = this.detail.id;
- this.forms.instrumentIds = this.detail.instrumentIds
- ? Number(this.detail.instrumentIds)
- : null;
- this.defaultId = this.detail.instrumentIds
- ? Number(this.detail.instrumentIds)
- : null;
- this.getCbsSubject(this.detail.id);
- }
- },
- methods: {
- formatParentId(id, list, ids = []) {
- for (const item of list) {
- if (item.instruments) {
- const cIds = this.formatParentId(id, item.instruments, [
- ...ids,
- item.id
- ]);
- if (cIds.includes(id)) {
- return cIds;
- }
- }
- if (item.id === id) {
- return [...ids, id];
- }
- }
- return ids;
- },
- async getCbsSubject(subjectId) {
- try {
- const { data } = await api_cbsSubjectPage({
- page: 1,
- rows: 999,
- subjectId
- });
- this.cbsSubjectList = data;
- } catch (e) {
- //
- console.log(e, "data");
- }
- },
- async onSubmit() {
- // 提交修改乐器
- if (!this.forms.instrumentIds) {
- this.$message.error("请选择乐器");
- return;
- }
- const ids = this.formatParentId(
- this.forms.instrumentIds,
- this.cbsSubjectList
- );
- this.forms.cbsSubjectId = ids[0];
- subjectUpset({
- tenantId: 1,
- ...this.forms
- }).then(res => {
- if (res.code == 200) {
- this.messageTips("修改", res);
- this.$emit("getList");
- this.$emit("close");
- }
- });
- // this.$refs.formRef.validate(valid => {
- // if (!valid) return;
- // // if (this.detail.id) {
- // // // 修改
- // // } else {
- // // // 添加
- // // }
- // this.$emit("close");
- // });
- },
- messageTips(title, res) {
- if (res.code == 200) {
- this.$message.success(title + "成功");
- } else {
- this.$message.error(res.msg);
- }
- }
- }
- };
- </script>
- <style lang="less" scoped>
- .dialog-footer {
- padding-top: 12px;
- text-align: right;
- }
- /deep/ .el-form-item {
- margin-bottom: 13px;
- }
- </style>
|