1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <template>
- <el-select
- v-model="selected"
- class="question-teacher-select"
- placeholder="请选择"
- :style="styles"
- filterable
- :clearable="clearable"
- :disabled="disabled"
- @change="select"
- >
- <el-option
- v-for="item in optionList"
- :key="item.id"
- :value="item.id"
- :label="item.name"
- ></el-option>
- </el-select>
- </template>
- <script>
- import { questionTeatherQuery } from "../../modules/exam/api";
- export default {
- name: "question-teacher-select",
- props: {
- disabled: { type: Boolean, default: false },
- value: { type: [Number, String], default: "" },
- styles: { type: String, default: "" },
- clearable: { type: Boolean, default: true },
- courseCode: { type: String, default: "" },
- schoolId: { type: String, default: "" }
- },
- data() {
- return {
- optionList: [],
- selected: ""
- };
- },
- watch: {
- value: {
- immediate: true,
- handler(val) {
- this.selected = val;
- }
- },
- courseCode(val, oldval) {
- if (val !== oldval) {
- this.search("");
- this.$emit("input", "");
- this.$emit("change", {});
- }
- },
- schoolId(val, oldval) {
- if (val !== oldval) {
- this.search("");
- this.$emit("input", "");
- this.$emit("change", {});
- }
- }
- },
- async created() {
- this.search();
- },
- methods: {
- async search(query) {
- const res = await questionTeatherQuery({
- param: query,
- courseCode: this.courseCode,
- schoolId: this.schoolId
- });
- this.optionList = res;
- },
- select() {
- this.$emit("input", this.selected);
- this.$emit(
- "change",
- this.optionList.find(item => item.id === this.selected)
- );
- }
- }
- };
- </script>
|