<template>
  <div>
    <seek-page :seekList="seekList" @search="search"></seek-page>
    <ele-pro-table
      ref="table"
      row-key="id"
      :columns="columns"
      :datasource="datasource"
      :cache-key="cacheKeyUrl"
      autoAmendPage
      height="calc(86vh - 230px)"
    >
      <template v-slot:action="{ row }">
        <el-link type="primary" :underline="false" @click="goToDetail(row)">
          详情
        </el-link>
      </template>
    </ele-pro-table>

    <!-- //工单列表 -->
    <routings
      v-if="routingShow"
      :routeObj="routeObj"
      @closeRoute="routingShow = false"
    ></routings>
  </div>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  import { batchRecordPage } from '@/api/workReport/index';
  import { getById } from '@/api/produceOrder';
  import routings from '@/views/produce/components/routings.vue';

  export default {
    mixins: [dictMixins, tableColumnsMixin],
    components: { routings },
    props: {
      tableQuery: {
        type: Object,
        default: () => {
          return {};
        }
      }
    },
    data() {
      return {
        columns: [
          {
            width: 50,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            label: '序号'
          },
          {
            prop: 'taskName',
            label: '报工工序名称',
            align: 'center',
            minWidth: 110,
            showOverflowTooltip: true
          },
          {
            prop: 'workOrderCode',
            label: '生产工单编号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'createTime',
            label: '报工时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'executorName',
            label: '执行人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'formedNum',
            label: '合格品数量',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'formedWeight',
            label: '合格品重量',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'reportStatus',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
            formatter: (row) => {
              switch (row.reportStatus) {
                case 0:
                  return '未报工';
                case 1:
                  return '已报工';
                default:
                  return '';
              }
            }
          },
          {
            label: '操作',
            columnKey: 'action',
            slot: 'action',
            showOverflowTooltip: true,
            minWidth: 110,
            align: 'center',
            fixed: 'right'
          }
        ],
        cacheKeyUrl: 'mes-259231101-workreport-table',
        routingShow: false,
        routeObj: {}
      };
    },
    computed: {
      seekList() {
        return [
          {
            label: '工单编码：',
            value: 'workOrderCode',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '工序名称',
            value: 'taskName',
            type: 'input',
            placeholder: '请输入'
          }
        ];
      }
    },
    methods: {
      // 刷新表格
      reload(where = {}) {
        this.$refs.table.reload({
          where,
          ...this.tableQuery
        });
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        // 参数
        const body = {
          ...where,
          ...order,
          pageNum: page,
          size: limit,
          ...this.tableQuery
        };
        return batchRecordPage(body);
      },
      search(where) {
        this.reload(where);
      },
      async goToDetail(row) {
        const data = await getById(row.workOrderId);
        this.routeObj = row;
        this.routingShow = true;
      }
    }
  };
</script>

<style></style>
