<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="exportAll">
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button>
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="jsxw_uo_name">
          <el-select class="mr10" v-model="jjmk_uo_name" placeholder="全部学校" @change="getListData">
            <el-option value="" label="选择学校">全部学校</el-option>
            <el-option
                v-for="bm in orgList"
                :label="bm.uo_name"
                :key="bm.uo_id"
                :value="bm.uo_name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="keyword" clearable @clear="getListData">
          </el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索</el-button>
      </el-form>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column label="学校（单位）" prop="jjmk_uo_name">
      </el-table-column>
      <el-table-column label="姓名" prop="jjmk_xm"></el-table-column>
      <el-table-column label="考核类别" prop="jjmkl_jjmkl_name_1"></el-table-column>
      <el-table-column label="名师类别" prop="jjmkl_jjmkl_name_2"></el-table-column>
      <el-table-column label="教学类别" prop="jjmkl_jjmkl_name_3"></el-table-column>
      <el-table-column label="校端审核情况" prop="jjmkl_xdshqk"></el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
<!--          <el-button type="text" v-if="scope.row.jjmkl_jdshqk_option_k == 2" @click="handleCheck(scope.row)">审核-->
<!--          </el-button>-->
<!--          <el-button type="text" v-else disabled>已审核</el-button>-->
          <el-button type="text" @click="toDetail(scope.row.jjmk_id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total"
                     :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>
    <!-- dialog弹出 -->
    <el-dialog title="审核" :visible.sync="dialogFormVisible" width="600px">
      <el-form :model="dialogForm" ref="addForm" :rules="rules" label-width="120px" label-position="left">
        <div v-if="jjmkl_jjmkl_id_1 == 10">
          <el-form-item label="审核结果" prop="jjmkl_xdshqk">
            <el-radio-group v-model="dialogForm.jjmkl_xdshqk">
              <el-radio v-for="item in xdsh" :label="item.v">{{item.n}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="处理意见" prop="jjmkl_xdshqk_clyj">
            <el-input type="textarea" v-model="dialogForm.jjmkl_xdshqk_clyj" placeholder="请输入处理意见"></el-input>
          </el-form-item>
        </div>
        <div v-else-if="jjmkl_jjmkl_id_1 == 1">
          <el-form-item label="审核结果" prop="jjmkl_jdshqk">
            <el-radio-group v-model="dialogForm.jjmkl_jdshqk">
              <el-radio v-for="item in jdsh" :label="item.v">{{item.n}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="处理意见" prop="jjmkl_jdshqk_clyj">
            <el-input type="textarea" v-model="dialogForm.jjmkl_jdshqk_clyj" placeholder="请输入处理意见"></el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogFormVisible= false">取 消</el-button>
        <el-button type="primary" @click="addFormSubmit('addForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {useUserStore} from "@/stores/user";

const {token} = useUserStore();
import {org_list, khhz_list,khhz_edit} from "./api";

export default {
  name: "index",
  data() {
    return {
      time: "",
      keyword: "",
      tableData: [],
      limit: 10,
      total: 0,
      cur_page: 1,
      dialogFormVisible: false,
      dialogForm: {
        jjmk_id:'',
        jjmkl_xdshqk:'',
        jjmkl_xdshqk_clyj:'',
        jjmkl_jdshqk:'',
        jjmkl_jdshqk_clyj:''
      },
      id: "",
      title: "",
      loading: false,
      jjmk_uo_name: '',
      orgList: [],
      rules: {
        jjmkl_xdshqk: [
          {required: true, message: '请选择审核结果', trigger: 'change'}
        ],
        jjmkl_jdshqk: [
          {required: true, message: '请选择审核结果', trigger: 'change'}
        ],
        jjmkl_xdshqk_clyj: [
          {required: true, message: '请输入处理意见', trigger: 'blur'}
        ],
        jjmkl_jdshqk_clyj: [
          {required: true, message: '请输入处理意见', trigger: 'blur'}
        ],
      },
      xdsh: [{
        "v": "1",
        "n": "优秀"
      }, {
        "v": "3",
        "n": "良好"
      }, {
        "v": "4",
        "n": "合格"
      }, {
        "v": "5",
        "n": "不合格"
      }],
      jdsh: [{
        "v": "6",
        "n": "符合"
      }, {
        "v": "7",
        "n": "不符合"
      }],
      jjmkl_jjmkl_id_1:'',
      multipleSelection: []
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = [];
      val.forEach(item=>{
        this.multipleSelection.push(item.jjmk_id)
      })
    },
    getListData() {
      this.loading = true;
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        jjmk_uo_name: this.jjmk_uo_name
      };
      khhz_list(data).then((res) => {
        this.loading = false;
        this.tableData = res.data.page_data;
        res.data.page_data.forEach(item => {
            if(item.jjmkl_jjmkl_id_1=='10'){
              item.jjmkl_zbdffj_json = JSON.parse(item.jjmkl_zbdffj_json)
              item.jjmkl_jjmkl_name_3 = item.jjmkl_zbdffj_json[0].cate1
            }
          })
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    getOrgList() {
      let data = {};
      org_list(data).then((res) => {
        if (res.code == 1) {
          this.orgList = res.data.page_data;
        }
      })
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    toDetail(id) {
      this.$router.push({name: "jsld_myjsjxkh_wshd_detail", params: {id: id}});
    },
    exportAll() {
      let link =
          window.globalVariables.api +
          "/jdbg/jsldgl_myjsjxkh_khhz/index?api=xls&page=1&limit=10000&jjmkl_jdshqk=2&token=" +
          token + '&jjmk_id='+ this.multipleSelection.join(',');
      window.open(link, "_blank");
    },
    handleCheck(item) {
      this.dialogFormVisible = true;
      this.jjmkl_jjmkl_id_1 = item.jjmkl_jjmkl_id_1;
      this.dialogForm.jjmk_id = item.jjmk_id;
      this.dialogForm.jjmkl_xdshqk = '';
      this.dialogForm.jjmkl_xdshqk_clyj = '';
      this.dialogForm.jjmkl_jdshqk = '';
      this.dialogForm.jjmkl_jdshqk_clyj = '';
    },
    //审核提交
    addFormSubmit(formName) {
      this.$refs[formName].validate((valid) => {

        if (valid) {
          let transObj = {};
          if(this.jjmkl_jjmkl_id_1 == 10) {
            transObj = {
              jjmk_id: this.dialogForm.jjmk_id,
              jjmkl_xdshqk: this.dialogForm.jjmkl_xdshqk,
              jjmkl_xdshqk_clyj: this.dialogForm.jjmkl_xdshqk_clyj,
            };
          } else if(this.jjmkl_jjmkl_id_1 = 1) {
            transObj = {
              jjmk_id: this.dialogForm.jjmk_id,
              jjmkl_jdshqk: this.dialogForm.jjmkl_jdshqk,
              jjmkl_jdshqk_clyj: this.dialogForm.jjmkl_jdshqk_clyj
            };
          }

          khhz_edit(transObj).then(res => {
            if (res.code == 1) {
              this.$message({
                message: "审核成功！",
                type: "success"
              });
              this.dialogFormVisible = false;
              this.getListData();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          })
        }
      })
    },
  },

  mounted() {
    this.getOrgList();
    this.getListData();
  },
};
</script>

<style lang="scss" scoped>
</style>