<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="provinceId">
        <el-select v-model="queryParams.provinceId"  >
            <el-option
              v-for="province in provinceList"
              :key="province.id"
              :label="province.name"
              :value="province.id"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="年份" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入填报年份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="志愿数量" prop="wishNum">
        <el-input
          v-model="queryParams.wishNum"
          placeholder="请输入志愿数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="志愿格式" prop="wishForm">
        <el-input
          v-model="queryParams.wishForm"
          placeholder="请输入志愿格式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="填报要求" prop="submitDemand">
        <el-input
          v-model="queryParams.submitDemand"
          placeholder="请输入填报要求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="批次" prop="batchId">
        <el-select v-model="queryParams.batchId" >
            <el-option
              v-for="batch in batchList"
              :key="batch.batchId"
              :label="batch.batchName"
              :value="batch.batchId"
            ></el-option>
          </el-select>
      </el-form-item>
      <!-- <el-form-item label="创建时间" prop="createAt">
        <el-input
          v-model="queryParams.createAt"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateAt">
        <el-input
          v-model="queryParams.updateAt"
          placeholder="请输入更新时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标记" prop="delFlag">
        <el-input
          v-model="queryParams.delFlag"
          placeholder="请输入删除标记"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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:mallBatchDetail: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:mallBatchDetail: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:mallBatchDetail: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:mallBatchDetail:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mallBatchDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="详情编号"   align="center" prop="batchDetailId" />
       <el-table-column label="批次" width="180"  align="center" prop="batchId" >
        <template slot-scope="scope">
          <el-select v-model="scope.row.batchId"  disabled >
            <el-option
              v-for="batch in batchList"
              :key="batch.batchId"
              :label="batch.batchName"
              :value="batch.batchId"
            ></el-option>
          </el-select>
        </template>
      </el-table-column> 
      <el-table-column label="省份"  width="110" align="center" prop="provinceId" >
        <template slot-scope="scope">
          <el-select v-model="scope.row.provinceId" disabled >
            <el-option
              v-for="province in provinceList"
              :key="province.id"
              :label="province.name"
              :value="province.id"
            ></el-option>
          </el-select>
        </template>
      </el-table-column> 
      <el-table-column label="年份" align="center" prop="year" /> 
      <el-table-column label="填报时间" align="center" prop="submitTime" />
      <el-table-column label="志愿方式" align="center" prop="wishType" />
      <el-table-column label="志愿数量" align="center" prop="wishNum" />
      <el-table-column label="志愿格式" align="center" prop="wishForm" />
      <el-table-column label="院校类型" align="center" prop="schoolType" />
      <el-table-column label="计算方式" align="center" prop="countType" />
      <el-table-column label="填报要求" align="center" prop="submitDemand" />
      <el-table-column label="批次线" align="center" prop="batchLine" />
      <el-table-column label="说明" align="center" prop="description" show-overflow-tooltip />
      <el-table-column label="创建时间" align="center" prop="createAt" />
      <!-- <el-table-column label="更新时间" align="center" prop="updateAt" />
      <el-table-column label="删除标记" align="center" prop="delFlag" /> -->
      <el-table-column label="操作" align="center"  fixed="right" 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:mallBatchDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mall:mallBatchDetail: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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="批次">
          <el-select v-model="form.batchId"  >
            <el-option
              v-for="batch in batchList"
              :key="batch.batchId"
              :label="batch.batchName"
              :value="batch.batchId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="省份" prop="provinceId">
           <el-select v-model="form.provinceId" >
            <el-option
              v-for="province in provinceList"
              :key="province.id"
              :label="province.name"
              :value="province.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年份" prop="year">
          <el-date-picker
            v-model="form.year"
            value-format="yyyy"
            type="year"
            placeholder="选择年">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="填报时间" prop="submitTime">
          <el-input v-model="form.submitTime" placeholder="请输入填报时间" />
        </el-form-item>
        <el-form-item label="志愿数量" prop="wishNum">
          <el-input v-model="form.wishNum" placeholder="请输入志愿数量" />
        </el-form-item>
        <el-form-item label="志愿格式" prop="wishForm">
          <el-input v-model="form.wishForm" placeholder="请输入志愿格式" />
        </el-form-item>
        <el-form-item label="志愿方式" prop="wishType">
          <el-input v-model="form.wishType" placeholder="请输入志愿方式" />
        </el-form-item>
        <el-form-item label="院校类型" prop="schoolType">
          <el-input v-model="form.schoolType" placeholder="请输入院校类型" />
        </el-form-item>
        <el-form-item label="计算方式" prop="countType">
          <el-input v-model="form.countType" placeholder="请输入计算方式" />
        </el-form-item>
        <el-form-item label="填报要求" prop="submitDemand">
          <el-input v-model="form.submitDemand" placeholder="请输入填报要求" />
        </el-form-item>
        <el-form-item label="批次线" prop="batchLine">
          <el-input v-model="form.batchLine" placeholder="请输入批次线" />
        </el-form-item>
        <el-form-item label="说明" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <!-- <el-form-item label="创建时间" prop="createAt">
          <el-input v-model="form.createAt" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateAt">
          <el-input v-model="form.updateAt" placeholder="请输入更新时间" />
        </el-form-item>
        <el-form-item label="删除标记(0-正常,1-删除)" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记(0-正常,1-删除)" />
        </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 { listMallBatchDetail, getMallBatchDetail, delMallBatchDetail, addMallBatchDetail, updateMallBatchDetail } from "@/api/mall/mallBatchDetail";
import {listMallBatch} from "@/api/mall/mallBatch";
import {listRegion} from "@/api/mall/region";

export default {
  name: "MallBatchDetail",
  data() {
    return {
      //省份列表
      provinceList:{},
      //批次列表
      batchList:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 批次说明表格数据
      mallBatchDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        provinceId: null,
        submitTime: null,
        wishType: null,
        wishNum: null,
        wishForm: null,
        schoolType: null,
        countType: null,
        submitDemand: null,
        batchLine: null,
        description: null,
        createAt: null,
        updateAt: null,
        delFlag: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        provinceId: [
          { required: true, message: "省份id不能为空", trigger: "blur" }
        ],
        submitTime: [
          { required: true, message: "填报时间不能为空", trigger: "blur" }
        ],
        wishType: [
          { required: true, message: "志愿方式不能为空", trigger: "change" }
        ],
        wishNum: [
          { required: true, message: "志愿数量不能为空", trigger: "blur" }
        ],
        wishForm: [
          { required: true, message: "志愿格式不能为空", trigger: "blur" }
        ],
        schoolType: [
          { required: true, message: "院校类型不能为空", trigger: "change" }
        ],
        countType: [
          { required: true, message: "计算方式不能为空", trigger: "change" }
        ],
        submitDemand: [
          { required: true, message: "填报要求不能为空", trigger: "blur" }
        ],
        batchLine: [
          { required: true, message: "批次线不能为空", trigger: "blur" }
        ],
        description: [
          { required: true, message: "说明不能为空", trigger: "blur" }
        ],
        // createAt: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" }
        // ],
        // updateAt: [
        //   { required: true, message: "更新时间不能为空", trigger: "blur" }
        // ],
        // delFlag: [
        //   { required: true, message: "删除标记(0-正常,1-删除)不能为空", trigger: "blur" }
        // ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询批次说明列表 */
    getList() {
      this.loading = true;
      //查批次列表
      listMallBatch().then(response =>{
        this.batchList = response.rows;
      });
      //省列表
      listRegion({"type":'1'}).then(response =>{
        this.provinceList = response.rows;
      });
      listMallBatchDetail(this.queryParams).then(response => {
        this.mallBatchDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        batchDetailId: null,
        provinceId: null,
        submitTime: null,
        wishType: null,
        wishNum: null,
        wishForm: null,
        schoolType: null,
        countType: null,
        submitDemand: null,
        batchLine: null,
        description: null,
        createAt: null,
        updateAt: 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.batchDetailId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加批次说明";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const batchDetailId = row.batchDetailId || this.ids
      getMallBatchDetail(batchDetailId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改批次说明";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.batchDetailId != null) {
            updateMallBatchDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMallBatchDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const batchDetailIds = row.batchDetailId || this.ids;
      this.$modal.confirm('是否确认删除批次说明编号为"' + batchDetailIds + '"的数据项？').then(function() {
        return delMallBatchDetail(batchDetailIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mall/mallBatchDetail/export', {
        ...this.queryParams
      }, `mallBatchDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
