<template>
  <div>
    <el-table v-loading="loading" :data="borrowList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="借款类型" align="center" prop="borrowUsage">
        <template slot-scope="scope">
          <el-tag :type="setTagType(scope.row.borrowUsage)">
            {{ setBorrowUsage(scope.row.borrowUsage) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="借款事由" align="center" prop="applyReason" :formatter="setReasonByUsage" />
      <el-table-column label="申请金额" align="center" prop="applyAmount" />
      <el-table-column label="核准金额" align="center" prop="managerAmount" />
      <el-table-column label="借款人" align="center" prop="applier">
        <template slot-scope="scope">
          {{ getUserName(scope.row.applier) }}
        </template>
      </el-table-column>
      <el-table-column label="借款人说明" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="借款日期" align="center" prop="applyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借款支付时间" align="center" prop="lendTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lendTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listBorrow, getBorrow, delBorrow, addBorrow, updateBorrow } from "@/api/oa/borrow/borrow";
import { listProject } from '@/api/oa/project/project';
import BorrowForm from '../../flowable/form/finance/borrowForm.vue';
import { mapGetters } from 'vuex'
export default {
  props: {
    borrowUsage: {
      type: String
    },
  },
  computed: {
    ...mapGetters(['roles', 'deptId']),
  },
  data() {
    return {
      borrowList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        borrowType: null,
        applyReason: null,
        applier: null,
        applyDate: null,
        applyAmount: null,
        managerAmount: null,
        deptComment: null,
        deptUserId: null,
        xmUserId: null,
        xmComment: null,
        managerComment: null,
        managerUserId: null,
        zjlUserId: null,
        zjlComment: null,
        cwUserId: null,
        cwComment: null,
        deptTime: null,
        xmTime: null,
        managerTime: null,
        zjlTime: null,
        lendTime: null,
        applyDept: null
      },
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.queryParams.borrowUsage = this.borrowUsage;
      if (this.roles.some(element => element === "dept")) {
        this.queryParams.applyDept = this.deptId;
        // this.queryParams.undertakingDept = this.deptId;
      }
      listBorrow(this.queryParams).then(response => {
        this.borrowList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleView(row) {
      this.$emit('clickView', row)
    },
    setBorrowUsage(row) {
      if (row == '0') {
        return '项目借款'
      } else if (row == '1') {
        return '非项目借款'
      } else if (row == '2') {
        return '工会借款'
      } else if (row == '3') {
        return '党委借款'
      } else if (row == '4') {
        return '团委借款'
      }
    },
    setTagType(row) {
      if (row == '0') {
        return 'success'
      } else if (row == '1') {
        return 'warning'
      } else if (row == '2') {
        return ''
      } else if (row == '3') {
        return ''
      } else if (row == '14') {
        return ''
      }
    },
    setReasonByUsage(row) {
      if (row.projectId) {
        return row.project.projectNumber + '-' + row.project.projectName
      } else {
        return row.applyReason
      }
    },
  },
}
</script>

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