<template>
  <div>
    <seek-page :seekList="seekList" @search="search"></seek-page>
    <ele-pro-table
      ref="table"
      :columns="columns"
      :datasource="datasource"
      :cache-key="cacheKeyUrl"
      :needPage="false"
      height="calc(86vh - 230px)"
    >
      <template v-slot:selfCheck="{ row }">
        <el-button
          type="primary"
          v-if="row.status == 2 || row.status == 3"
          @click="reportClick(row, 1, 'detail')"
          >详情</el-button
        >
      </template>

      <template v-slot:specialInspection="{ row }">
        <el-button
          type="primary"
          v-if="row.status == 3"
          @click="reportClick(row, 2, 'detail')"
          >详情</el-button
        >
      </template>

      <template v-slot:status="{ row }">
        <el-tag v-if="row.status == 0">待自检</el-tag>
        <el-tag v-if="row.status == 2">待专检</el-tag>
        <el-tag v-if="row.status == 3">已完成</el-tag>
      </template>
    </ele-pro-table>

    <self-inspection-reporting
      ref="selfReportingRef"
      @refreshData="reload"
    ></self-inspection-reporting>
  </div>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  import selfInspectionReporting from '@/views/produce/components/qualityInspection/components/selfInspectionReporting.vue';
  import { getBatchRecordList } from '@/api/produce/qualityInspection';
  import { produceTask } from '@/api/InTheSystem/index';
  export default {
    mixins: [dictMixins, tableColumnsMixin],

    components: {
      selfInspectionReporting
    },

    props: {
      tableQuery: {
        type: Object,
        default: () => {
          return {};
        }
      }
    },
    data() {
      return {
        columns: [
          {
            width: 50,
            type: 'index',
            columnKey: 'index',
            label: '序号',
            align: 'center'
          },
          {
            prop: 'name',
            label: '名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'workstationName',
            label: '工位名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },

          {
            prop: 'deviceName',
            label: '设备名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },

          {
            prop: 'produceTaskName',
            label: '工序名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },

          {
            prop: 'selfCheckUserName',
            label: '自检报工人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'selfCheckTime',
            label: '自检时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },

          {
            prop: 'specialCheckUserName',
            label: '专检报工人',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },

          {
            prop: 'specialCheckTime',
            label: '专检时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120
          },

          {
            prop: 'status',
            slot: 'status',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 100
          },
          {
            label: '自检报工',
            align: 'center',
            width: 150,
            fixed: 'right',
            slot: 'selfCheck'
          },
          {
            label: '专检报工',
            align: 'center',
            width: 150,
            fixed: 'right',
            slot: 'specialInspection'
          }
        ],
        cacheKeyUrl: 'batchRecord-qualityInspection-2025-12-17',
        routList: []
      };
    },

    computed: {
      seekList() {
        return [
          {
            label: '工序:',
            value: 'produceTaskId',
            type: 'select',
            placeholder: '请选择',
            planList: this.routList
          }
        ];
      }
    },

    created() {
      this.getTaskList();
    },

    methods: {
      reload(where = {}) {
        this.$refs.table.reload({
          where,
          ...this.tableQuery
        });
      },

      async getTaskList() {
        let params = {
          pageNum: 1,
          size: -1
        };
        await produceTask(params).then((res) => {
          this.routList = res.list.map((item) => {
            return {
              label: item.name,
              value: item.id
            };
          });
        });
      },

      search(where) {
        this.reload(where);
      },

      datasource({ page, limit, where, order }) {
        // 参数
        const body = {
          ...where,
          ...order,
          pageNum: page,
          size: limit,
          ...this.tableQuery
        };
        return getBatchRecordList(body);
      },

      reportClick(row, type, mode) {
        this.$refs.selfReportingRef.open(row, type, mode);
      }
    }
  };
</script>

<style></style>
