<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model:page="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @row-del="rowDel"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <!-- 自定义档案状态显示 -->
      <template #auditStatus="{ row }">
        {{
          getStatusText(row.auditStatus)
        }}
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  delTransferApplyApi,
  getTransferApplyListApi,
} from '@/api/filesTransfer/apply';
import { mapGetters } from 'vuex';
import website from '@/config/website';

export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 32,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: false,
        selection: false,
        addBtn: true,
        editBtn: false,
        delBtn: false,
        dialogClickModal: false,
        column: [

          {
            label: '项目名称',
            prop: 'proName',
          },

          {
            label: '单项工程名称',
            prop: 'singleProName',
            search: true,
          },
          {
            label: '申请人',
            prop: 'createUserName',
          },
          {
            label: '申请时间',
            prop: 'createTime',
          },
          {
            label: '审批状态',
            prop: 'auditStatus',
            slot: true, // 启用插槽
          },

        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        addBtn: this.validData(this.permission.post_add, false),
        viewBtn: this.validData(this.permission.post_view, false),
        delBtn: this.validData(this.permission.post_delete, false),
        editBtn: this.validData(this.permission.post_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },
  },
  methods: {
    beforeOpen(done, type, row) {
      done(); // 必须调用 done()
    },
    getStatusText(status) {
      switch (status) {
        case '0':
          return '待审批'
        case '1':
          return '审批通过'
        case '2':
          return '审批驳回'
        default:
          return '未知状态'
      }
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return delTransferApplyApi(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    onLoad(page, params = {}) {
      this.loading = true;
      let data = {
        ...params,
        pageNum:page.currentPage,
        pageSize:page.pageSize
      };
      getTransferApplyListApi(data).then(res => {
        const data = res.data;
        this.page.total = data.total;
        this.data = data.rows;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>

<style></style>
