<template>
  <div id="tableWrap">
    <FilterTable
      ref="table"
      :columns="columns"
      :dataSource="logDataSource"
      :isSelected="isSelected"
      :total="total"/>
    <div class="btn-list">
      <a-button type="stop" style="margin-right: 20px;" @click="handleOk">
        取消
      </a-button>
      <a-button type="add" @click="handleOk">
        确定
      </a-button>
    </div>
  </div>
</template>

<script>
import FilterTable from '@/components/filterTable'

import { getApproveLogList } from '@/api/auditMasterData/approve'

export default {

  beforeRouteLeave(to, from, next) {
    this.$destroy(true)
    next()
  },
  data() {
    return {
      total: 0,
      isSelected: false,
      logDataSource: []
    }
  },
  props: {
    columns: {
      type: Array,
      required: true
    },
    params: {
      type: Object,
      required: true
    }
  },
  components: {
    FilterTable
  },
  mounted() {
    this.getApproveLogList()
  },

  methods: {
    getApproveLogList() {
      getApproveLogList(this.params).then((res) => {
        if (res.rows !== undefined) {
          res.rows.forEach((item, index) => {
            item.key = index + 1
            switch (item.processStatus) {
              case '2':
                item.processStatus = '审核中'
                break
              case '3':
                item.processStatus = '通过'
                break
              case '4':
                item.processStatus = '驳回'
                break
            }
            const logJson = JSON.parse(item.logJson)
            Object.assign(item, logJson)

            item.operationType = this.operationTypeFun(item.operationType)
          })
          this.logDataSource = res.rows
          this.total = res.total
          // console.log('审批日志res.rows:', res.rows)
        }
      })
    },
    operationTypeFun(operationType) {
      switch (operationType) {
        case '0':
          operationType = '新增'
          break
        case '1':
          operationType = '变更'
          break
        case '2':
          operationType = '启用'
          break
        case '3':
          operationType = '停用'
          break
        case '4':
          operationType = '删除'
          break
      }
      return operationType
    },
    onPageChange(e) {
      console.log(`e`, e)
    },
    handleOk() {
      this.$emit('handleOk')
    }

  }
}
</script>

<style  lang="less" scoped>
#tableWrap{
  .btn-list{
    text-align: center;
    margin-top: 30px;
  }

}
</style>
