123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <template>
- <Modal
- class="modify-student"
- v-model="modalIsShow"
- :title="title"
- :mask-closable="false"
- width="450"
- @on-visible-change="visibleChange"
- >
- <Form
- ref="modalFormComp"
- class="modal-form"
- :model="modalForm"
- :rules="rules"
- :key="modalForm.id"
- :label-width="100"
- style="width: 340px;"
- >
- <FormItem prop="name" label="姓名">
- <Input
- size="large"
- v-model.trim="modalForm.name"
- placeholder="请输入姓名"
- clearable
- ></Input>
- </FormItem>
- <FormItem prop="examNumber" label="考号">
- <Input
- size="large"
- v-model.trim="modalForm.examNumber"
- placeholder="请输入考号"
- clearable
- ></Input>
- </FormItem>
- <FormItem prop="areaCode" label="考区">
- <Select
- size="large"
- v-model="modalForm.areaCode"
- @on-change="areaChange"
- placeholder="请选择考区"
- >
- <Option
- v-for="area in cascadeList"
- :key="area.areaCode"
- :value="area.areaCode"
- :label="area.areaName"
- ></Option>
- </Select>
- </FormItem>
- <FormItem prop="school" label="学校">
- <Select
- size="large"
- v-model="modalForm.school"
- @on-change="schoolChange"
- placeholder="请选择学校"
- >
- <Option
- v-for="(item, index) in schools"
- :key="index"
- :value="item.school"
- :label="item.school"
- ></Option>
- </Select>
- </FormItem>
- <FormItem prop="examRoom" label="考场">
- <Select
- size="large"
- v-model="modalForm.examRoom"
- placeholder="请选择考场"
- >
- <Option
- v-for="(room, index) in rooms"
- :key="index"
- :value="room"
- :label="room"
- ></Option>
- </Select>
- </FormItem>
- </Form>
- <div slot="footer">
- <Button shape="circle" type="primary" :disabled="isSubmit" @click="submit"
- >确认</Button
- >
- <Button shape="circle" @click="cancel">取消</Button>
- </div>
- </Modal>
- </template>
- <script>
- import { updateStudent } from "@/api";
- const initModalForm = {
- id: null,
- name: "",
- examNumber: "",
- areaCode: "",
- school: "",
- examRoom: ""
- };
- export default {
- name: "modify-student",
- props: {
- instance: {
- type: Object,
- default() {
- return {};
- }
- },
- cascadeList: {
- type: Array,
- default() {
- return [];
- }
- }
- },
- computed: {
- isEdit() {
- return !!this.instance.id;
- },
- title() {
- return (this.isEdit ? "编辑" : "新增") + "考生信息";
- }
- },
- data() {
- return {
- modalIsShow: false,
- isSubmit: false,
- schools: [],
- rooms: [],
- modalForm: { ...initModalForm },
- rules: {
- name: [
- {
- required: true,
- message: "请输入姓名",
- trigger: "change"
- }
- ],
- examNumber: [
- {
- required: true,
- message: "请输入考号",
- trigger: "change"
- }
- ],
- areaCode: [
- {
- required: true,
- message: "请选择考区",
- trigger: "change"
- }
- ],
- schoolId: [
- {
- required: true,
- message: "请选择学校",
- trigger: "change"
- }
- ],
- examRoom: [
- {
- required: true,
- message: "请选择考场",
- trigger: "change"
- }
- ]
- }
- };
- },
- methods: {
- initData(val) {
- this.$refs.modalFormComp.resetFields();
- if (val.id) {
- this.modalForm = this.$objAssign(initModalForm, val);
- } else {
- this.modalForm = { ...initModalForm };
- }
- },
- visibleChange(visible) {
- if (visible) {
- this.initData(this.instance);
- }
- },
- areaChange() {
- const curArea = this.cascadeList.find(
- item => item.areaCode === this.modalForm.areaCode
- );
- this.schools = curArea.schools;
- this.rooms = [];
- this.modalForm.examRoom = null;
- if (curArea.schools.length === 1) {
- this.modalForm.school = curArea.schools[0].school;
- this.schoolChange();
- }
- },
- schoolChange() {
- const curSchool = this.schools.find(
- item => item.school === this.modalForm.school
- );
- this.rooms = curSchool.rooms;
- this.modalForm.examRoom = null;
- },
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- async submit() {
- const valid = await this.$refs.modalFormComp.validate();
- if (!valid) return;
- if (this.isSubmit) return;
- this.isSubmit = true;
- const data = await updateStudent(this.modalForm).catch(() => {});
- this.isSubmit = false;
- if (!data) return;
- this.$Message.success(this.title + "成功!");
- this.$emit("modified");
- this.cancel();
- }
- }
- };
- </script>
|