<template>
  <div>
    <div class="flex-row">
      <h3 class="font-size-16">报表详情</h3>
      <div>
        <el-button type="primary" @click="editData()">编辑</el-button>
        <el-button type="primary">导出</el-button>
      </div>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" style="width: 100%">
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column label="序号" align="center" type="index" width="55">
      </el-table-column>
      <el-table-column label="创建人" width="200" prop="cjr"></el-table-column>
      <el-table-column
        label="流程类型"
        width="150"
        prop="lclx"
      ></el-table-column>
      <el-table-column label="审核人" prop="shr"></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="title" :visible.sync="dialogFormVisible" width="580px">
      <el-form :model="dialogForm" label-width="80px">
        <el-form-item label="流程类型" prop="lclx">
          <el-select
            v-model="dialogForm.lclx"
            style="width: 100%"
            placeholder="请选择流程类型"
          >
            <el-option
              v-for="item in type_list"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="审核人员" prop="shr">
          <el-input
            v-model="dialogForm.shry"
            placeholder="请输入审核人员"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="formCancel">取 消</el-button>
        <el-button type="primary" @click="formSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { useUserStore } from "@/stores/user";
const { real_name } = useUserStore();
import { bbtjxq_list, bbtjxq_edit } from "./api";
export default {
  name: "index",
  data() {
    return {
      tableData: [],
      limit: 10,
      total: 12,
      cur_page: 1,
      title: "",
      dialogFormVisible: false,
      id: "",
      loading: false,
      dialogForm: {
        cjr: "",
        lclx: "",
        shr: "",
      },
      type_list: [
        {
          label: "入职流程",
          value: "1",
        },
        {
          label: "流动流程",
          value: "2",
        },
        {
          label: "退休流程",
          value: "3",
        },
        {
          label: "离职流程",
          value: "4",
        },
      ],
    };
  },
  methods: {
    getListData() {
      this.loading = true;
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
      };

      bbtjxq_list(data).then((res) => {
        this.loading = false;
        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();
    },

    editData(item) {
      this.title = "编辑报表详情";
      this.isEdit = true;
      this.dialogFormVisible = true;
      this.id = item.id;
      this.dialogForm.cjr = item.cjr;
      this.dialogForm.lclx = item.lclx;
      this.dialogForm.shr = item.shr;
    },
    formSubmit() {
      let data = {
        cjr: real_name,
        lclx: this.dialogForm.lclx,
        shr: this.dialogForm.shr,
      };
      data.id = this.id;
      bbtjxq_edit(data).then((res) => {
        if (res.code == 1) {
          this.$message({
            message: "报表详情编辑成功！",
            type: "success",
          });

          this.dialogFormVisible = false;
          this.getListData();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    formCancel() {
      this.dialogFormVisible = false;
    },
  },
  mounted() {
    this.getListData();
  },
};
</script>

<style scoped>
</style>