12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <template>
- <el-select
- v-model="selected"
- class="class-select"
- :placeholder="placeholder"
- filterable
- :clearable="clearable"
- :disabled="disabled"
- @change="select"
- >
- <el-option
- v-for="item in optionList"
- :key="item.name"
- :value="item.name"
- :label="item.name"
- >
- </el-option>
- </el-select>
- </template>
- <script>
- import { commonCollegeMajorClassQuery } from "../../modules/base/api";
- export default {
- name: "class-select",
- props: {
- disabled: { type: Boolean, default: false },
- placeholder: { type: String, default: "请选择" },
- value: { type: [Number, String], default: "" },
- clearable: { type: Boolean, default: true },
- majorName: { type: String, default: "" },
- examId: { type: String, default: "" },
- cascader: { type: Boolean, default: false },
- },
- data() {
- return {
- optionList: [],
- selected: "",
- };
- },
- watch: {
- value: {
- immediate: true,
- handler(val) {
- this.selected = val;
- },
- },
- majorName(val, oldval) {
- if (val !== oldval) {
- this.search();
- this.$emit("input", "");
- this.$emit("change", {});
- }
- },
- examId(val, oldval) {
- if (val !== oldval) {
- this.search();
- this.$emit("input", "");
- this.$emit("change", {});
- }
- },
- },
- async created() {
- this.search();
- },
- methods: {
- async search() {
- this.optionList = [];
- if (!this.examId) return;
- if (this.cascader && !this.majorName) return;
- const res = await commonCollegeMajorClassQuery({
- majorName: this.majorName,
- examId: this.examId,
- dictionaryEnum: "CLAZZ",
- });
- this.optionList = res;
- },
- select() {
- this.$emit("input", this.selected);
- this.$emit(
- "change",
- this.optionList.find((item) => item.name === this.selected)
- );
- },
- },
- };
- </script>
|