<template>
  <div class="pa-3 white">
    <m-filter :option="filter" @search="handleSearch" />
    <m-table
      :loading="loading"
      :headers="headers"
      :items="items"
      :total="total"
      :page-info="pageInfo"
      :is-tools="false"
      :show-select="false"
      :disable-sort="true"
      @pageHandleChange="pageHandleChange"
    >
      <template #runResult="{ item }">
        <span :class="item.runResult === '1' ? 'green--text' : 'red--text'">
          {{ item.runResult === '1' ? '成功' : '失败' }}
        </span>
      </template>
      <template #actions="{ item }">
        <v-btn text color="primary" @click="handleClickDetails(item)">查看详情</v-btn>
      </template>
    </m-table>
    <m-log v-model="drawer" :data="drawerData"></m-log>
  </div>
</template>

<script>
import MFilter from '@/components/Filter'
import MTable from '@/components/List/table.vue'
import MLog from '../components/logPage.vue'
import { productionLineLogPage, productionLineLogDetail } from '@/api/dataFactory'
export default {
  name: 'production-log-manage',
  components: { MFilter, MTable, MLog },
  data () {
    return {
      drawerData: {},
      drawer: false,
      loading: false,
      filter: {
        list: [
          { type: 'textField', value: '', label: '名称', key: 'name' }
        ]
      },
      queryData: {
        name: null
      },
      headers: [
        { text: '名称', align: 'start', value: 'name' },
        { text: '运行状态', align: 'center', value: 'runResult' },
        { text: '运行时间', align: 'start', value: 'runTime' },
        { text: '更新时间', align: 'start', value: 'updateTime' },
        { text: '创建时间', align: 'start', value: 'createTime' },
        { text: '操作', align: 'start', value: 'actions' }
      ],
      items: [],
      orders: [],
      pageInfo: {
        size: 10,
        current: 1
      },
      total: 0
    }
  },

  created () {
    this.init()
  },
  methods: {
    async init () {
      try {
        const { data } = await productionLineLogPage({ ...this.queryData, ...this.pageInfo })
        this.items = data.records
        this.total = data.total
      } catch (error) {
        this.$snackbar.error(error)
      }
    },
    handleSearch (val) {
      Object.assign(this.queryData, val)
      this.pageInfo.current = 1
      this.init()
    },
    pageHandleChange (index) {
      this.pageInfo.current = index
      this.init()
    },
    async handleClickDetails (item) {
      try {
        const { data } = await productionLineLogDetail({ id: item.id })
        this.drawerData = data
        this.drawer = true
      } catch (error) {
        this.$snackbar.error(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
