<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="60px">
      <el-form-item label="申请人姓名" prop="xm" label-width="100px">
        <el-input v-model="queryParams.xm" placeholder="请输入申请人姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请人身份证" prop="sfzhm" label-width="100px">
        <el-input v-model="queryParams.sfzhm" placeholder="请输入申请人身份证号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="申请人学号" prop="xh" label-width="100px">
        <el-input v-model="queryParams.xh" placeholder="请输入申请人学号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="审核意见" label-width="100px" prop="yj" class="query">
        <el-select v-model="queryParams.yj" clearable placeholder="请选择" @change="handleQuery">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="学年" prop="applyYear" label-width="100px">
        <el-select v-model="queryParams.applyYear" clearable placeholder="请选择" @change="handleQuery">
          <el-option
            v-for="item in yearOptions"
            :key="item.stuYearName"
            :label="item.stuYearName"
            :value="item.stuYearName"
          />
        </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"
              >新增</el-button>
          </el-col> -->
      <!-- <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini"  @click="handleUpdate"
              >修改</el-button>
          </el-col> -->
      <!-- <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini"  @click="handleDelete"
              >删除</el-button>
          </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出全部</el-button>
      </el-col>
      <el-row :span="10">

        <div class="statistics">
   
          <div class="detail">
            <!-- 已审核的 -->
            <div class="reviewed">
              <div v-for="(value,key,index) in countReview" :key="index">
                <span>
                  {{ key }}
                </span>
                <span>:</span>
                <span>
                  {{ value }}
                </span>
              </div>
            </div>
            <!-- 按困难类型统计 -->
            <div class="reviewedDetail">
              (
              <div v-for="(value,key,index) in count" :key="index">
                <span>
                  {{ key }}
                </span>
                <span>:</span>
                <span>
                  {{ value }}
                </span>
              </div>
              )
            </div>
            <!-- 未审核的 -->
            <div class="notReviewed">
              <div v-for="(value,key,index) in countNotReview" :key="index">
                <span>
                  {{ key }}
                </span>
                <span>:</span>
                <span>
                  {{ value }}
                </span>
              </div>
            </div>
          </div>
            
        </div>
      </el-row>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>
    <!-- <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="['system:apply:add']">新增</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="#" align="center" prop="id" />
      <el-table-column label="学年" align="center" prop="applyYear" />
      <el-table-column label="学院" align="center" prop="xy" />
      <!-- <el-table-column label="1:提交,2:班级" align="center" prop="step" /> -->
      <el-table-column label="申请人姓名" align="center" prop="xm" />
      <el-table-column label="性别" align="center" prop="xb" />
      <el-table-column label="民族" align="center" prop="mz" />
      <!-- <el-table-column label="身份证号码" align="center" prop="sfzhm" /> -->
      <el-table-column label="学号" align="center" prop="xh" />
      <el-table-column label="班级" align="center" prop="bj" />
      
      <el-table-column label="出生年月" align="center" prop="csny" />
      <el-table-column label="辅导员审核意见" align="center" prop="bjpyyj">
        <template slot-scope="scope">
          <div v-if="scope.row.bjpyyj">
            <div v-if="scope.row.bjpyyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.bjpyyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.bjpyyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.bjpyyj == '4'">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="二级学院领导审核意见" align="center" prop="ejxyldqmyj">
        <template slot-scope="scope">
          <div v-if="scope.row.ejxyldqmyj">
            <div v-if="scope.row.ejxyldqmyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.ejxyldqmyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.ejxyldqmyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.ejxyldqmyj == '4'">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="学校审核意见" align="center" prop="xsqmyj">
        <template slot-scope="scope">
          <div v-if="scope.row.xsqmyj">
            <div v-if="scope.row.xsqmyj == '1'" style="color: #55aa00">特别困难</div>
            <div v-if="scope.row.xsqmyj == '2'" style="color: #55aa00">比较困难</div>
            <div v-if="scope.row.xsqmyj == '3'" style="color: #55aa00">一般困难</div>
            <div v-if="scope.row.xsqmyj == '4'" style="color: #ff5500">不困难</div>
          </div>
          <div v-else style="color: #ff0000">未审核</div>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <!--    <template slot-scope="scope">
              	<el-button type="primary" icon="el-icon-edit" plain @click="handleUpdate(scope.row)"
              		size="small">编辑</el-button>
              </template> -->
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">详情</el-button>
          <el-button v-if="scope.row.step == 4" size="mini" type="text" icon="el-icon-delete" @click="handleRevoke(scope.row)">撤回</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" />
  </div>
</template>

<script>
import {list} from '@/api/stuYear/index'
import { revoke,countXw } from '@/api/zxj/poverty/apply'
import { addApply, delApply, listXw, updateApply } from '@/api/zxj/poverty/applyjl'
export default {
  name: 'Apply',
  data() {
    return {
      yearOptions:[],
      countReview:{},
      countNotReview:{},
      count:{},
      options: [
        {
          value: '1',
          label: '特别困难',
        },
        {
          value: '2',
          label: '比较困难',
        },
        {
          value: '3',
          label: '一般困难',
        },
        {
          value: '4',
          label: '不困难',
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 困难认定表格数据
      applyList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        step: null,
        xm: null,
        xb: null,
        mz: null,
        sfzhm: null,
        xh: null,
        csny: null,
        knlx: null,
        knlx2: null,
        rkzs: null,
        srly: null,
        hjxz: null,
        hjszd: null,
        jtcy: null,
        jtjzfqk: null,
        jtqcqk: null,
        jtxjzdz: null,
        jzdh: null,
        jtnsr: null,
        rjnsr: null,
        jtzysr: null,
        ssldnl: null,
        hbcjr: null,
        zyssldnl: null,
        tfsj: null,
        sqrqm: null,
        sqrqmrq: null,
        bjpyyj: null,
        pyxzzzqm: null,
        pyxzzzqmrq: null,
        fdyqm: null,
        fdyqmrq: null,
        ejxyldqmyj: null,
        ejxyldqm: null,
        ejxyldqmrq: null,
        xsqmyj: null,
        xsqm: null,
        xsqmrq: null,
        createId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fdyqmrq: [{ required: true, message: '辅导员签名日期不能为空', trigger: 'blur' }],
      },
    }
  },
  created() {
    this.getList()
    this.doCountXw()
    this.listAllYear()
  },
  methods: {
    listAllYear(){
      list().then(res=>{
        this.yearOptions = res.data
      })
    },
    doCountXw(){
      countXw().then(res => {
          let lable = ''
          let reviewedTotal = 0
          let noReviewTotal = 0
          let list = res.data
          for(let i = 0; i < list.length; i++){
              let row = list[i]
              if(row.ejxyldqmyj == '1'){
                lable = '特别困难'
                this.count[lable] = row.countXw
                reviewedTotal = reviewedTotal + row.countXw
                continue
              }
              if(row.ejxyldqmyj == '2'){
                lable = '比较困难'
                 this.count[lable] = row.countXw
                   reviewedTotal = reviewedTotal + row.countXw
                continue
              }
              if(row.ejxyldqmyj == '3'){
                lable = '一般困难'
                 this.count[lable] = row.countXw
                   reviewedTotal = reviewedTotal + row.countXw
                continue
              }
              if(row.ejxyldqmyj == '4'){
                lable = '不困难';this.count[lable] = row.countXw
                reviewedTotal = reviewedTotal + row.countXw
                continue
              }
              if(row.ejxyldqmyj  == null || row.ejxyldqmyj == ''){
                  lable = '未审核'
                  noReviewTotal = noReviewTotal + row.countXw
                   continue
              }

          }
          this.countReview['已审核数量'] = reviewedTotal
          this.countNotReview['未审核数量'] = noReviewTotal


      })
    },
    /** 查询困难认定列表 */
    getList() {
      this.loading = true
      listXw(this.queryParams).then((response) => {
        this.applyList = response.rows
     
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        step: null,
        xm: null,
        xb: null,
        mz: null,
        sfzhm: null,
        xh: null,
        csny: null,
        knlx: null,
        knlx2: null,
        rkzs: null,
        srly: null,
        hjxz: null,
        hjszd: null,
        jtcy: null,
        jtjzfqk: null,
        jtqcqk: null,
        jtxjzdz: null,
        jzdh: null,
        jtnsr: null,
        rjnsr: null,
        jtzysr: null,
        ssldnl: null,
        hbcjr: null,
        zyssldnl: null,
        tfsj: null,
        sqrqm: null,
        sqrqmrq: null,
        bjpyyj: null,
        pyxzzzqm: null,
        pyxzzzqmrq: null,
        fdyqm: null,
        fdyqmrq: null,
        ejxyldqmyj: null,
        ejxyldqm: null,
        ejxyldqmrq: null,
        xsqmyj: null,
        xsqm: null,
        xsqmrq: null,
        createId: 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.$router.push({
        path: '/hard/pks/poverty/edit',
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row)
      this.reset()
      const id = row.id || this.ids
      this.$router.push({
        path: '/hard/pks/poverty/edit',
        query: {
          id: id,
          she: 0,
          action: 3,
        },
      })
      // getApply(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) {
            updateApply(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addApply(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 delApply(ids)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {})
    },

    handleRevoke(row) {
      this.$modal
        .confirm('是否确认撤回该记录?')
        .then(function () {
          return revoke(row)
        })
        .then((res) => {
          this.getList()
        })
        .catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'knrApproval/srsKnrdapprovalrecord/xw/export',
        {
          ...this.queryParams,
        },
        `apply_${new Date().getTime()}.xlsx`
      )
    },
  },
}
</script>
<style scoped>
.statistics{
  font-size: 18px;


}
.detail,.detail>div{
  display: flex;
  
}
.detail{
  gap: 20px;
}
.detail>div{
  gap: 10px;
}
</style>