<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="院考学校" prop="schoolName">
        <el-input v-model="queryParams.schoolName" placeholder="请输入院考学校" />
      </el-form-item>
      <el-form-item label="年份" prop="acceptYear">
        <el-date-picker clearable
                        v-model="queryParams.acceptYear"
                        type="year"
                        value-format="yyyy"
                        placeholder="请选择年分">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="专业" prop="majorId">
        <el-select v-model="queryParams.majorId" placeholder="请选择专业" >
          <el-option v-for="item in majorList"
                     :value="item.majorId"
                     :key="item.majorId"
                     :label="item.majorName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mall:mallTestSchoolRecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mall:mallTestSchoolRecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mall:mallTestSchoolRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mall:mallTestSchoolRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallTestSchoolRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="院考学校" align="center" prop="schoolName" />
      <el-table-column label="专业" align="center" prop="majorName" />
      <el-table-column label="年份" align="center" prop="acceptYear" />
      <el-table-column label="所需文化分" align="center" prop="needCulture" />
      <el-table-column label="合格线" align="center" prop="passScore" />
      <el-table-column label="满分线" align="center" prop="fullScore" />
      <el-table-column label="录取前提" align="center" prop="acceptPremise" />
      <el-table-column label="录取原则" align="center" prop="acceptRule" />
      <el-table-column label="最低分" align="center" prop="acceptLowest" />
      <el-table-column label="考试内容" align="center" prop="examContent" />
      <el-table-column label="招生人数" align="center" prop="acceptNum" />
      <el-table-column label="联考要求" align="center" prop="examRequire" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mall:mallTestSchoolRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallTestSchoolRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改校考院校记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="院考学校" prop="schoolName">
          <el-input v-model="form.schoolName" placeholder="请输入院考学校" />
        </el-form-item>
        <el-form-item label="年份" prop="acceptYear">
          <el-date-picker clearable
                          v-model="form.acceptYear"
                          type="year"
                          value-format="yyyy"
                          placeholder="请选择年分">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="专业" prop="majorId">
          <el-select v-model="form.majorId" placeholder="请选择专业" >
            <el-option v-for="item in majorList"
                       :value="item.majorId"
                       :key="item.majorId"
                       :label="item.majorName"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="所需文化分" prop="needCulture">
          <el-input v-model="form.needCulture" placeholder="请输入所需文化分" />
        </el-form-item>
        <el-form-item label="合格线" prop="passScore">
          <el-input-number :min="0" :precision="0" controls-position="right" v-model="form.passScore" placeholder="请输入合格线" />
        </el-form-item>
        <el-form-item label="满分线" prop="fullScore">
          <el-input-number :min="0" :precision="0" controls-position="right" v-model="form.fullScore" placeholder="请输入满分线" />
        </el-form-item>

        <!-- 录取前提 accept_premise -->
        <el-form-item label="录取前提" prop="acceptPremise">
           <el-input v-model="form.acceptPremise" placeholder="请输入录取前提" />
        </el-form-item>
        <!-- 录取原则 accept_rule -->
        <el-form-item label="录取原则" prop="acceptRule">
           <el-input v-model="form.acceptRule" placeholder="请输入录取原则" />
        </el-form-item>
        <!-- 最低分 accept_lowest  数字 -->
        <!-- <el-form-item label="最低分" prop="acceptLowest">
          <el-input-number :min="0" :precision="0" controls-position="right"
          v-model="form.acceptLowest" placeholder="请输入最低分" />
        </el-form-item> -->
        <!-- 最低分 accept_lowest  String -->
        <el-form-item label="最低分" prop="acceptLowest">
          <el-input v-model="form.acceptLowest" placeholder="请输入最低分" />
        </el-form-item>
        <!-- 考试内容 exam_content -->
        <el-form-item label="考试内容" prop="examContent">
           <el-input v-model="form.examContent" placeholder="请输入考试内容" />
        </el-form-item>
        <!-- 招生人数 accept_num  数字 -->
        <el-form-item label="招生人数" prop="acceptNum">
          <el-input-number :min="0" :precision="0" controls-position="right"
          v-model="form.acceptNum" placeholder="请输入招生人数" />
        </el-form-item>
          <!-- 非必_联考要求 exam_require -->
          <el-form-item label="联考要求" >
           <el-input v-model="form.examRequire" placeholder="请输入联考要求" />
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listMallTestSchoolRecord, getMallTestSchoolRecord, delMallTestSchoolRecord, addMallTestSchoolRecord, updateMallTestSchoolRecord } from "@/api/mall/mallTestSchoolRecord";
import {selectMajorListByLowLevel} from "@/api/mall/mallMajorClass";


export default {
  name: "MallTestSchoolRecord",
  props: ["testSchoolId", "schoolName"],
  data() {
    return {
      // 专业列表
      majorList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 校考院校记录表格数据
      mallTestSchoolRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        testInfoId: null,
        testSchoolId: null,
        majorId: null,
        acceptYear: null,
        needCulture: null,
        passScore: null,
        fullScore: null,
        createTime: null,
        updateTime: null,
        delFlag: null,
        schoolName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        testInfoId: [
          { required: true, message: "院考记录id不能为空", trigger: "blur" }
        ],
        testSchoolId: [
          { required: true, message: "院考学校id不能为空", trigger: "blur" }
        ],
        majorId: [
          { required: true, message: "专业id不能为空", trigger: "blur" }
        ],
        acceptYear: [
          { required: true, message: "年份不能为空", trigger: "blur" }
        ],
        needCulture: [
          { required: true, message: "所需文化分不能为空", trigger: "blur" }
        ],
        passScore: [
          { required: true, message: "合格线不能为空", trigger: "blur" }
        ],
        fullScore: [
          { required: true, message: "满分线不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "删除标记(0-正常,1-删除)不能为空", trigger: "blur" }
        ],

        acceptPremise: [
          { required: true, message: "录取前提不能为空", trigger: "blur" }
        ],
        acceptRule: [
          { required: true, message: "录取原则不能为空", trigger: "blur" }
        ],
        acceptLowest: [
          { required: true, message: "最低分不能为空", trigger: "blur" }
        ],
        examContent: [
          { required: true, message: "考试内容不能为空", trigger: "blur" }
        ],
        acceptNum: [
          { required: true, message: "招生人数不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getMajorList();
  },
  methods: {
    /** 查询校考院校记录列表 */
    getList() {
      this.loading = true;
      if (this.testSchoolId != null){
        this.queryParams.testSchoolId = this.testSchoolId;
      }
      console.log(this.testSchoolId);
      listMallTestSchoolRecord(this.queryParams).then(response => {
        this.mallTestSchoolRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        testInfoId: null,
        testSchoolId: null,
        majorId: null,
        acceptYear: null,
        needCulture: null,
        passScore: null,
        fullScore: null,
        createTime: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.testInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.testSchoolId != null){
        this.form.testSchoolId = this.testSchoolId;
        this.form.schoolName = this.schoolName;
      }
      this.open = true;
      this.title = "添加校考院校记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const testInfoId = row.testInfoId || this.ids
      getMallTestSchoolRecord(testInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改校考院校记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.testInfoId != null) {
            updateMallTestSchoolRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallTestSchoolRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const testInfoIds = row.testInfoId || this.ids;
      this.$modal.confirm('是否确认删除校考院校记录编号为"' + testInfoIds + '"的数据项？').then(function() {
        return delMallTestSchoolRecord(testInfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mall/mallTestSchoolRecord/export', {
        ...this.queryParams
      }, `mallTestSchoolRecord_${new Date().getTime()}.xlsx`)
    },
    /** 二级专业列表 */
    getMajorList(){
      selectMajorListByLowLevel().then(response=>{
        this.majorList = response.data;
      })
    }
  }
};
</script>
