<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="udid" prop="udid">
        <el-input
          v-model="queryParams.udid"
          placeholder="请输入唯一标识值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校编码" prop="collegeCode">
        <el-input
          v-model="queryParams.collegeCode"
          placeholder="请输入学校编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入地区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校名称" prop="collegeName">
        <el-input
          v-model="queryParams.collegeName"
          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="['back:pdProcessData: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="['back:pdProcessData: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="['back:pdProcessData: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="['back:pdProcessData:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pdProcessDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="udid" align="center" prop="udid" />
      <el-table-column label="数据类型" align="center" prop="dataType" />
      <el-table-column label="学校编码" align="center" prop="collegeCode" />
      <el-table-column label="学校名称" align="center" prop="collegeName" />
      <el-table-column label="批次" align="center" prop="batch" />
      <el-table-column label="科目" align="center" prop="course" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="地区" align="center" prop="location" />
      <el-table-column label="请求参数" align="center" prop="dataBinary" />
      <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="['back:pdProcessData:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['back:pdProcessData: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="udid" prop="udid">
          <el-input v-model="form.udid" placeholder="请输入唯一标识值" />
        </el-form-item>
        <el-form-item label="youzySignature" prop="youzySignature">
          <el-input v-model="form.youzySignature" placeholder="请输入youzySignature" />
        </el-form-item>
        <el-form-item label="sign" prop="sign">
          <el-input v-model="form.sign" placeholder="请输入sign" />
        </el-form-item>
        <el-form-item label="eagleToken" prop="eagleToken">
          <el-input v-model="form.eagleToken" placeholder="请输入eagleToken" />
        </el-form-item>
        <el-form-item label="uDfv" prop="uDfv">
          <el-input v-model="form.uDfv" placeholder="请输入uDfv" />
        </el-form-item>
        <el-form-item label="uToken" prop="xToken">
          <el-input v-model="form.xToken" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="uToken" prop="uToken">
          <el-input v-model="form.uToken" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="uDfs" prop="uDfs">
          <el-input v-model="form.uDfs" placeholder="请输入uDfs" />
        </el-form-item>
        <el-form-item label="wToken" prop="wToken">
          <el-input v-model="form.wToken" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="host" prop="host">
          <el-input v-model="form.host" placeholder="请输入host" />
        </el-form-item>
        <el-form-item label="userAgent" prop="userAgent">
          <el-input v-model="form.userAgent" placeholder="请输入userAgent" />
        </el-form-item>
        <el-form-item label="请求参数" prop="dataBinary">
          <el-input v-model="form.dataBinary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="请求url" prop="compressed">
          <el-input v-model="form.compressed" placeholder="请输入请求url" />
        </el-form-item>
        <el-form-item label="原始数据" prop="originalData">
          <el-input v-model="form.originalData" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="学校编码" prop="collegeCode">
          <el-input v-model="form.collegeCode" placeholder="请输入学校编码" />
        </el-form-item>
        <el-form-item label="批次" prop="batch">
          <el-input v-model="form.batch" placeholder="请输入批次" />
        </el-form-item>
        <el-form-item label="选科" prop="course">
          <el-input v-model="form.course" placeholder="请输入选科" />
        </el-form-item>
        <el-form-item label="年份" prop="year">
          <el-input v-model="form.year" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="地区" prop="location">
          <el-input v-model="form.location" placeholder="请输入地区" />
        </el-form-item>
        <el-form-item label="学校名称" prop="collegeName">
          <el-input v-model="form.collegeName" placeholder="请输入学校名称" />
        </el-form-item>
        <el-form-item label="请求结果" prop="result">
          <el-input v-model="form.result" type="textarea" 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 { listPdProcessData, getPdProcessData, delPdProcessData, addPdProcessData, updatePdProcessData } from "@/api/back/pdProcessData";

export default {
  name: "PdProcessData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据处理表格数据
      pdProcessDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        udid: null,
        youzySignature: null,
        sign: null,
        eagleToken: null,
        uDfv: null,
        xToken: null,
        uToken: null,
        uDfs: null,
        wToken: null,
        contentType: null,
        host: null,
        userAgent: null,
        dataBinary: null,
        compressed: null,
        originalData: null,
        dataType: null,
        collegeCode: null,
        provinceCode: null,
        batch: null,
        course: null,
        year: null,
        location: null,
        collegeName: null,
        result: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询数据处理列表 */
    getList() {
      this.loading = true;
      listPdProcessData(this.queryParams).then(response => {
        this.pdProcessDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        udid: null,
        youzySignature: null,
        sign: null,
        eagleToken: null,
        uDfv: null,
        xToken: null,
        uToken: null,
        uDfs: null,
        wToken: null,
        contentType: null,
        host: null,
        userAgent: null,
        dataBinary: null,
        compressed: null,
        originalData: null,
        dataType: null,
        collegeCode: null,
        provinceCode: null,
        batch: null,
        course: null,
        year: null,
        location: null,
        createTime: null,
        updateTime: null,
        collegeName: null,
        result: 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.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据处理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPdProcessData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据处理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePdProcessData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPdProcessData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据处理编号为"' + ids + '"的数据项？').then(function() {
        return delPdProcessData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('back/pdProcessData/export', {
        ...this.queryParams
      }, `pdProcessData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
