<template>
  <a-table
    :columns="columns"
    rowKey="id"
    :dataSource="data"
    bordered
    :loading="loading"
    size="small"
    :title="title"
  >
  </a-table>
</template>

<script>

import {getAction} from '../../../utils/manage';
import YchConstant from "../../../utils/YchConstant";
import locleUtil from "../../../utils/LocleUtil";

  export default {
    name: "BpmIdeaPassRound",
    props: {
      processInstanceId: {
        type: String,
        default: null
      },
      refreshFlg: {
        type: Number,
        default: 0
      },
    },
    components: {},
    data() {
      return {
        url: {
          getData: YchConstant.PREFIX_BPM + "/bpm-front/displayRest/getIdeaPassRoundListByInstanceId/v1"
        },
        data: [],
        loading: false,
        columns: [{
          title:this.$locale('m.common.label.number'),
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        }, {
          title: this.$locale('m.bpm.entity.passName'),
          dataIndex: 'userName',
          width: 180,
          align: "center",
          customRender: function (value, row, index) {
            if (row.deptName) {
              return value + "/" + row.deptName;
            }
            return value;
          }
        }, {
          title:this.$locale('m.bpm.entity.passType'),
          dataIndex: 'operationTypeString',
          width: 80,
          align: "center"
        }, {
          title: this.$locale('m.bpm.entity.passTime'),
          dataIndex: 'endTime',
          width: 130,
          align: "center"
        }, {
          title: this.$locale('m.bpm.entity.passMessage'),
          width: 200,
          dataIndex: 'message'
        }],
        title: function () {
          return this.$locale("m.bpm.design.idea_pass_round_title")
        }
      }
    },
    mounted() {
      this.refresh();
    },
    methods: {
      $locale(params){
        return locleUtil.getLocale(params)
      },
      refresh() {
        if (!this.processInstanceId) {
          return;
        }
        const that = this;
        that.loading = true;
        getAction(this.url.getData, {processInstanceId: this.processInstanceId}).then((res) => {
          if (res.success) {
            that.data = res.result;
          } else {
            that.messageUtil.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
        });
      }
    },
    watch: {
      refreshFlg(value) {
        if (value > 1) {
          this.refresh();
        }
      }
    }
  }
</script>
