123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <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="请选择学校"
- filterable
- allow-create
- @on-create="createSchool"
- >
- <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="请选择考场"
- filterable
- allow-create
- @on-create="createRoom"
- :key="modalForm.school"
- >
- <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: "",
- workId: null,
- examNumber: "",
- areaName: "",
- 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",
- },
- {
- min: 2,
- max: 20,
- message: "姓名长度只能介于2到20之间",
- },
- ],
- examNumber: [
- {
- required: true,
- message: "请输入考号",
- trigger: "change",
- },
- {
- min: 2,
- max: 20,
- message: "考号长度只能介于2到20之间",
- },
- ],
- areaCode: [
- {
- required: true,
- message: "请选择考区",
- trigger: "change",
- },
- ],
- school: [
- {
- required: true,
- message: "请选择学校",
- trigger: "change",
- },
- ],
- examRoom: [
- {
- required: true,
- message: "请选择考场",
- trigger: "change",
- },
- ],
- },
- };
- },
- methods: {
- initData(val) {
- this.$refs.modalFormComp.resetFields();
- this.modalForm = this.$objAssign(initModalForm, val);
- if (val.id) {
- this.reviewInfo();
- }
- },
- visibleChange(visible) {
- if (visible) {
- this.initData(this.instance);
- } else {
- this.$emit("on-close");
- }
- },
- reviewInfo() {
- const curArea = this.cascadeList.find(
- (item) => item.areaCode === this.modalForm.areaCode
- );
- this.schools = curArea.schools;
- const curSchool = this.schools.find(
- (item) => item.school === this.modalForm.school
- );
- this.rooms = curSchool.rooms;
- },
- areaChange() {
- const curArea = this.cascadeList.find(
- (item) => item.areaCode === this.modalForm.areaCode
- );
- this.schools = curArea ? curArea.schools : [];
- this.modalForm.areaName = curArea.areaName;
- 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 ? curSchool.rooms : [];
- this.modalForm.examRoom = null;
- // 后触发更改
- // console.log("school change");
- },
- createSchool(val) {
- this.schools.push({ school: val, rooms: [] });
- // 先创建
- // console.log("school create");
- },
- createRoom(val) {
- this.rooms.push(val);
- },
- 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>
|