<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item style="width: 300px">
        <div style="display: flex; justify-content: center; font-size: 20px; font-weight: 500" class="mt20, title">
          {{ xxfbName }}
        </div>
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          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-table v-loading="loading" :data="ryList">
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="是否查看" align="center" prop="isView">
        <template slot-scope="scope">
          <span>{{ scope.row.isView == '1' ? "已查看" : "未查看" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否反馈" align="center" prop="feedback">
        <template slot-scope="scope">
          <span>{{ scope.row.feedback == '1' ? "已反馈" : "未反馈" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="家长反馈" align="center" prop="ryFk">
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idCard"/>
      <el-table-column label="姓名" align="center" prop="studentName"/>
      <el-table-column label="班级" align="center" prop="classAlias"/>
      <template
        v-for="key in Object.keys(dynamicTitle)"
      >
        <el-table-column :key="key" :prop="key" :label="dynamicTitle[key]">
        </el-table-column>
      </template>

    </el-table>


  </div>
</template>

<script>
import {dataList} from "@/api/smartSchool/gradeWork/infoPublish/dataView.js";

export default {
  name: "DataView",
  data() {
    return {
      xxfbName: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信息发布内容表格数据
      ryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        idCard: null,
        studentName: null,
      },
      // 表单参数
      form: {},
      // 动态标题
      dynamicTitle: {}
    };
  },
  created() {
    this.xxfbId = this.$route.query && this.$route.query.id
    this.xxfbName = this.$route.query && this.$route.query.xxfbName
    this.getList();
  },
  activated() {
    this.xxfbId = this.$route.query && this.$route.query.id
    this.xxfbName = this.$route.query && this.$route.query.xxfbName
    this.getList();
  },
  methods: {
    /** 查询信息发布内容列表 */
    getList() {
      this.loading = true;
      dataList(this.queryParams, this.xxfbId).then(response => {
        this.ryList = response.data;
        //获取标题
        const titles = response.titles ?? {};
        Object.keys(titles).forEach(key => {
          if (titles[key]) {
            this.dynamicTitle[key] = titles[key];
          }
        })
        this.loading = false;
      }).catch(error => {
        this.loading = false;
      });
      ;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 【重置】按钮 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery()
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },

  }
};
</script>
