<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="exportAll">
          <!-- <span class="d-in-block v-mid el-icon-plus font-size-16"></span> -->
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button>
        <!-- <el-button type="primary" size="medium" :disabled="selectList.length == 0" @click="batchAudit">
          <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="jsxw_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="jsxw_xl">
          <el-select class="mr10" v-model="jsxw_xl" placeholder="全部学历" @change="getListData">
            <el-option value="" label="选择学历">全部学历</el-option>
            <el-option
                v-for="item in selectList"
                :label="item.n"
                :key="item.v"
                :value="item.v">
            </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="标题" show-overflow-tooltip width="auto">
        <template v-slot="scope"> {{ scope.row.wr_xm }}-入职流程 </template>
      </el-table-column> -->
      <el-table-column label="学校名称" width="200" prop="jsxw_uo_name"></el-table-column>
      <el-table-column label="姓名" width="100" prop="jsxw_xm"></el-table-column>
      <el-table-column label="性别" width="100" prop="jsxw_xb"></el-table-column>
      <el-table-column label="出生年月" width="100" prop="jsxw_csny"></el-table-column>
      <el-table-column label="学历" width="120" prop="jsxw_xl"></el-table-column>
      <el-table-column label="专业" width="120" prop="jsxw_zy"></el-table-column>
      <el-table-column label="工作岗位" width="120" prop="jsxw_gzgw"></el-table-column>
      <el-table-column label="参加工作时间" width="150" prop="jsxw_cygzsj"></el-table-column>
      <el-table-column label="备注" width="120" prop="jsxw_bz"></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="editData(scope.row)">编辑</el-button>
          <el-button type="text" @click="delData(scope.row.jsxw_id)">删除</el-button>
          <el-button type="text" @click="toDetail(scope.row.jsxw_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>
    <el-dialog title="编辑" :visible.sync="dialogFormVisible" width="700px">

      <el-form :inline="true" :model="dialogForm" :rules="rules" ref="dialogForm" label-width="120px">
        <el-form-item label="学校名称" prop="jsxw_uo_name">
          <el-input v-model="dialogForm.jsxw_uo_name"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="jsxw_xm">
          <el-input v-model="dialogForm.jsxw_xm"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="jsxw_xb">
          <el-select v-model="dialogForm.jsxw_xb" placeholder="选择性别">
            <el-option
                v-for="item in xbList"
                :label="item.n"
                :key="item.v"
                :value="item.v">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生年月" prop="jsxw_csny">
          <el-date-picker style="width: 160px;"
              v-model="dialogForm.jsxw_csny"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学历" prop="jsxw_xl">
          <el-select v-model="dialogForm.jsxw_xl" placeholder="全部学历" @change="getListData">
            <el-option
                v-for="item in selectList"
                :label="item.n"
                :key="item.v"
                :value="item.v">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="专业" prop="jsxw_zy">
          <el-input v-model="dialogForm.jsxw_zy"></el-input>
        </el-form-item>
        <el-form-item label="工作岗位" prop="jsxw_gzgw">
          <el-input v-model="dialogForm.jsxw_gzgw"></el-input>
        </el-form-item>
        <el-form-item label="参加工作时间" prop="jsxw_cygzsj">
          <el-date-picker style="width: 160px;"
                          v-model="dialogForm.jsxw_cygzsj"
                          value-format="yyyy-MM-dd"
                          type="date"
                          placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="身份证" prop="jsxw_sfz">
          <el-input v-model="dialogForm.jsxw_sfz"></el-input>
        </el-form-item>
        <el-form-item label="家庭住址" prop="jsxw_address">
          <el-input v-model="dialogForm.jsxw_address"></el-input>
        </el-form-item>
        <el-form-item label="手机" prop="jsxw_phone">
          <el-input v-model="dialogForm.jsxw_phone"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="dialogForm.jsxw_bz"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="formSubmit('dialogForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

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

const {token} = useUserStore();
import {xxbwry_list, xxb_edit, xxbwry_del, org_list} from "./api";

export default {
  name: "index",
  data() {
    return {
      state_value: "",
      state_list: [
        {
          label: "全部",
          value: "0",
        },
        {
          label: "通过",
          value: "1",
        },
        {
          label: "未通过",
          value: "2",
        },
      ],
      time: "",
      keyword: "",
      tableData: [],
      limit: 10,
      total: 0,
      cur_page: 1,
      dialogFormVisible: false,
      dialogForm: {
        jsxw_id:'',
        jsxw_uo_name: '',
        jsxw_xm:'',
        jsxw_xb:'',
        jsxw_csny:'',
        jsxw_xl:'',
        jsxw_zy:'',
        jsxw_gzgw:'',
        jsxw_cygzsj:'',
        jsxw_sfz:'',
        jsxw_address:'',
        jsxw_phone:'',
        jsxw_bz:''
      },
      createDialogVisible: false,
      createForm: {
        wr_title: "",
        wr_bmmc: "",
        wr_date: "",
      },
      rules:{
        jsxw_uo_name: [
          { required: true, message: '请输入学校名称', trigger: 'blur' }
        ],
        jsxw_xm: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        jsxw_xb: [
          { required: true, message: '请选择性别', trigger: 'change' }
        ],
        jsxw_csny: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
        jsxw_xl: [
          { required: true, message: '请选择学历', trigger: 'change' }
        ],
        jsxw_zy: [
          { required: true, message: '请输入专业', trigger: 'blur' }
        ],
        jsxw_gzgw: [
          { required: true, message: '请输入工作岗位', trigger: 'blur' }
        ],
        jsxw_cygzsj: [
          { required: true, message: '请选择日期', trigger: 'change' }
        ],
        jsxw_sfz: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ],
        jsxw_address: [
          { required: true, message: '请输入家庭住址', trigger: 'blur' }
        ],
        jsxw_phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
      },
      xbList:[
        {
          "v": "1",
          "n": "男"
        },
        {
          "v": "2",
          "n": "女"
        },
        {
          "v": "3",
          "n": "保密"
        }
      ],
      selectList: [{
        "v": "1",
        "n": "博士研究生毕业"
      }, {
          "v": "2",
          "n": "博士研究生结业"
        },
        {
          "v": "3",
          "n": "硕士研究生毕业"
        },
        {
          "v": "4",
          "n": "硕士研究生结业"
        },
        {
          "v": "5",
          "n": "研究生班毕业"
        },
        {
          "v": "6",
          "n": "研究生班结业"
        },
        {
          "v": "7",
          "n": "大学本科毕业"
        },
        {
          "v": "8",
          "n": "大学本科结业"
        },
        {
          "v": "9",
          "n": "大学普通班毕业"
        },
        {
          "v": "10",
          "n": "大学专科毕业"
        },
        {
          "v": "11",
          "n": "大学专科结业"
        },
        {
          "v": "12",
          "n": "高等职院毕业"
        },
        {
          "v": "13",
          "n": "高等技师毕业"
        },
        {
          "v": "14",
          "n": "中等专科毕业"
        },
        {
          "v": "15",
          "n": "中等专科结业"
        },
        {
          "v": "16",
          "n": "职业高中毕业"
        },
        {
          "v": "17",
          "n": "职业高中结业"
        },
        {
          "v": "18",
          "n": "技工学校毕业"
        },
        {
          "v": "19",
          "n": "技工学校结业"
        },
        {
          "v": "20",
          "n": "普通高中毕业"
        },
        {
          "v": "21",
          "n": "普通高中结业"
        },
        {
          "v": "22",
          "n": "初中毕业"
        },
        {
          "v": "23",
          "n": "小学毕业"
        },
        {
          "v": "24",
          "n": "中等师范学校（幼儿师范学校）毕业"
        },
        {
          "v": "25",
          "n": "中等师范学校（幼儿师范学校）结业"
        },
        {
          "v": "26",
          "n": "其他"
        }
      ],
      jsxw_uo_name: '',
      orgList: [],
      jsxw_xl:'',
      multipleSelection: []
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = [];
      val.forEach(item=>{
        this.multipleSelection.push(item.jsxw_id)
      })
    },
    getListData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        jsxw_uo_name: this.jsxw_uo_name,
        jsxw_xl:this.jsxw_xl
      };
      xxbwry_list(data).then((res) => {
        this.tableData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    getOrgList() {
      let data = {};
      org_list(data).then((res) => {
        if (res.code == 1) {
          this.orgList = res.data.page_data;
        }
      })
    },
    editData(item) {
      this.dialogFormVisible = true;
      this.dialogForm = {
        jsxw_id:item.jsxw_id,
        jsxw_uo_name:item.jsxw_uo_name,
        jsxw_xm:item.jsxw_xm,
        jsxw_xb:item.jsxw_xb_option_k,
        jsxw_csny:item.jsxw_csny,
        jsxw_xl:item.jsxw_xl_option_k,
        jsxw_zy:item.jsxw_zy,
        jsxw_gzgw:item.jsxw_gzgw,
        jsxw_cygzsj:item.jsxw_cygzsj,
        jsxw_sfz:item.jsxw_sfz,
        jsxw_address:item.jsxw_address,
        jsxw_phone:item.jsxw_phone,
        jsxw_bz:item.jsxw_bz
      }
    },
    formSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid) {
          let data = {
            jsxw_id:this.dialogForm.jsxw_id,
            jsxw_uo_name: this.dialogForm.jsxw_uo_name,
            jsxw_xm:this.dialogForm.jsxw_xm,
            jsxw_xb:this.dialogForm.jsxw_xb,
            jsxw_csny:this.dialogForm.jsxw_csny,
            jsxw_xl:this.dialogForm.jsxw_xl,
            jsxw_zy:this.dialogForm.jsxw_zy,
            jsxw_gzgw:this.dialogForm.jsxw_gzgw,
            jsxw_cygzsj:this.dialogForm.jsxw_cygzsj,
            jsxw_sfz:this.dialogForm.jsxw_sfz,
            jsxw_address:this.dialogForm.jsxw_address,
            jsxw_phone:this.dialogForm.jsxw_phone,
            jsxw_bz:this.dialogForm.jsxw_bz
          };
          xxb_edit(data).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: "数据编辑成功！",
                type: "success",
              });
              this.dialogFormVisible = false;
              this.getListData();
            }
          });
        }
      })

    },
    toDetail(id) {
      this.$router.push({name: "jsld_xxbwrygl_detail", params: {id: id}});
    },
    delData(id) {
      let data = {
        jsxw_id: id,
      };
      this.$confirm("确认删除这条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            xxbwry_del(data).then((res) => {
              if (res.code == 1) {
                this.$message({
                  message: "删除成功！",
                  type: "success",
                });
                this.getListData();
              } else {
                this.$message({
                  message: res.msg,
                  type: "error",
                });
              }
            });
          })
          .catch(() => {
          });
    },
    exportAll() {
      let link =
          window.globalVariables.api +
          "/jdbg/jsldgl_xxbwrygl/index?api=xls&page=1&limit=10000&token=" +
          token+'&jsxw_id='+ this.multipleSelection.join(',');
      window.open(link, "_blank");
    },
    // verify(type, item) {
    //   let data = {
    //     wr_zt: type,
    //     wr_id: item.wr_id,
    //   };
    //   rzlc_edit(data).then((res) => {
    //     if (res.code == 1) {
    //       this.$message({
    //         message: "审核成功！",
    //         type: "success",
    //       });
    //       this.getListData();
    //     }
    //   });
    // },
    // handleSelectionChange(val) {
    //   this.selectList = val;
    // },
    // batchAudit() {
    //   this.dialogFormVisible = true;
    // },
    // batchSubmit() {
    //   let wr_ids = [];
    //   for (let i in this.selectList) {
    //     wr_ids.push(this.selectList[i].wr_id);
    //   }
    //   let data = {
    //     wr_zt: this.dialogForm.operate,
    //     wr_id: wr_ids.join(","),
    //   };
    //   rzlc_edit(data).then((res) => {
    //     if (res.code == 1) {
    //       this.$message({
    //         message: "批量审核成功！",
    //         type: "success",
    //       });
    //       this.dialogFormVisible = false;
    //       this.getListData();
    //     }
    //   });
    // },

  },
  mounted() {
    this.getOrgList();
    this.getListData();

  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-input__inner {
  width: 160px;
}

::v-deep .el-textarea__inner {
  width: 430px;
}
</style>