<!--
 * @Author: zwq
 * @Date: 2020-12-29 15:41:11
 * @LastEditors: zwq
 * @LastEditTime: 2022-01-17 15:26:35
 * @Description:
-->
<template>
  <div class="app-container">
    <head-form
      :placeholder-name="placeholderName"
      :key-name="keyName"
      :show-add="false"
      @getDataList="getList"
      @add="addNew"
    />
    <base-table
      :page="listQuery.current"
      :limit="listQuery.size"
      :table-config="tableProps"
      :table-data="list"
      :is-loading="listLoading"
    >
      <method-btn
        slot="handleBtn"
        :width="trueWidth"
        :method-list="tableBtn"
        @clickBtn="handleClick"
      />
    </base-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList()"
    />
    <Factory-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getList" />
  </div>
</template>

<script>
import { ExecutionInfoList } from '@/api/orderManage/00A'
import FactoryAdd from './components/ExecutionInfoDetail.vue'
import HeadForm from '@/components/basicData/HeadForm'
import BaseTable from '@/components/BaseTable'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import MethodBtn from '@/components/BaseTable/subcomponents/MethodBtn'
import { timeFormatter } from '@/filters'
import basicData from '@/filters/basicData'
import i18n from '@/lang'
/**
 * 表格表头配置项 TypeScript接口注释
 * tableConfig<ConfigItem> = []
 *
 * Interface ConfigItem = {
 *  prop: string,
 *  label: string,
 *  width: string,
 *  align: string,
 *  subcomponent: function,
 *  filter: function
 * }
 *
 *
 */

const tableBtn = [
  {
    type: 'see',
    btnName: 'btn.see'
  }
]
const tableProps = [
  {
    prop: 'name',
    label: i18n.t('module.basicData.Warehouse.OrderName'),
    align: 'center'
  },
  {
    prop: 'createTime',
    label: i18n.t('module.basicData.Warehouse.IssueOrderTime'),
    filter: timeFormatter,
    align: 'center'
  },
  {
    prop: 'craftName',
    label: i18n.t('module.basicData.Warehouse.TotalProcessName'),
    align: 'center'
  },
  {
    prop: 'priority',
    label: i18n.t('module.basicData.Warehouse.Priority'),
    filter: basicData('priority'),
    align: 'center'
  },
  {
    prop: 'status',
    label: i18n.t('module.basicData.Warehouse.OrderStatus'),
    filter: basicData('workOrderStatus'),
    align: 'center'
  }
]

export default {
  name: 'ExecutionInfo',
  components: { Pagination, BaseTable, MethodBtn, HeadForm, FactoryAdd },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      keyName: i18n.t('module.basicData.Warehouse.OrderName'),
      placeholderName: this.$t('module.basicData.Warehouse.OrderName'),
      addOrUpdateVisible: false,
      tableBtn,
      trueWidth: 200,
      tableProps,
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        current: 1,
        size: 10,
        name: '',
        code: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleClick(raw) {
      this.addNew(raw.data.id)
    },
    getList(key) {
      this.listLoading = true
      this.listQuery.code = key
      ExecutionInfoList(this.listQuery).then(response => {
        if (response.data.records) {
          this.list = response.data.records
        } else {
          this.list.splice(0, this.list.length)
        }
        this.total = response.data.total
        this.listLoading = false
      })
    },
    // 新增 / 修改
    addNew(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
