<template>
  <section class="workflowLogs">
    <ai-list>
      <ai-title slot="title" title="流程台账" isShowBottomBorder isShowBack @back="back"/>
      <template #content>
        <ai-search-bar>
          <template #right>
            <el-input size="small" placeholder="搜索" v-model="search.name" clearable
                      @change="page.current=1,getTableData()"/>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
                  @getList="getTableData" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作" fixed="right" align="center" width="300">
            <template slot-scope="{row}">
              <el-button type="text" @click="showProcess(row.workflowConfig)">查看进度</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
    <ai-dialog :visible.sync="dialog" title="查看进度" @closed="process=null" customFooter>
      <ai-workflow v-model="process" readonly/>
      <template #footer>
        <el-button @click="dialog=false">关闭</el-button>
      </template>
    </ai-dialog>
  </section>
</template>

<script>
import AiWorkflow from "./AiWorkflow";

export default {
  name: "workflowLogs",
  components: {AiWorkflow},
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      search: {name: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        {prop: "pid", label: "流程ID"},
        {prop: "bid", label: "业务ID"},
        {prop: "createUserName", label: "创建者"},
      ],
      dialog: false,
      process: null
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/app/appworkflowlog/list", null, {
        params: {...this.page, ...this.search}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data.records
          this.page.total = res.data.total
        }
      })
    },
    back() {
      this.$router.push({})
    },
    showProcess(process) {
      this.process = JSON.parse(process)
      this.dialog = true
    }
  },
  created() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.workflowLogs {
  height: 100%;
}
</style>
