<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>
        <!-- <el-link type="primary" :underline="false" @click="openPrint(row)">
          打印
        </el-link> -->
      </template>
      <template v-slot:code="{ row }">
        <el-link type="primary" @click="goToDetail(row)">{{
          row.code
        }}</el-link>
      </template>
    </ele-pro-table>

    <editModal ref="editModalRef"></editModal>

    <batchPecordPrint ref="batchPecordPrintRef"></batchPecordPrint>
  </div>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  import { producetaskrulerecordPage } from '@/api/producetaskrulerecord/index';
  import editModal from '../editModal.vue';
  import batchPecordPrint from './batchPecordPrint.vue';

  export default {
    mixins: [dictMixins, tableColumnsMixin],
    components: { editModal, batchPecordPrint },
    props: {
      tableQuery: {
        type: Object,
        default: () => {
          return {};
        }
      }
    },
    data() {
      return {
        columns: [
          {
            width: 50,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            label: '序号'
          },
          {
            prop: 'code',
            label: '记录编码',
            align: 'center',
            minWidth: 110,
            showOverflowTooltip: true,
            slot: 'code'
          },
          {
            prop: 'ruleName',
            label: '事项名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'workOrderCode',
            label: '关联生产工单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            prop: 'createUserName',
            label: '来源列表',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            label: '状态',
            minWidth: 180,
            prop: 'executeStatus',
            formatter: (row) => {
              switch (row.executeStatus) {
                case 0:
                  return '未执行';
                case 1:
                  return '执行中';
                default:
                  return '已执行';
              }
            }
          },
          {
            label: '审核状态',
            prop: 'approvalStatus',
            minWidth: 180,
            formatter: (row) => {
              switch (row.approvalStatus) {
                case 0:
                  return '未提交';
                case 1:
                  return '审核中';
                case 2:
                  return '审核通过';
                case 3:
                  return '审核不通过';
                case 4:
                  return '终止审核中';
                case 5:
                  return '终止审核通过';
                case 7:
                  return '流程废止';
                default:
                  return '';
              }
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150
          },
          {
            label: '操作',
            columnKey: 'action',
            slot: 'action',
            showOverflowTooltip: true,
            minWidth: 110,
            align: 'center',
            fixed: 'right'
          }
        ],
        cacheKeyUrl: 'mes-259231507-batchRecord-table'
      };
    },
    computed: {
      seekList() {
        return [
          {
            label: '工单编码：',
            value: 'workOrderCode',
            type: 'input',
            placeholder: '请输入'
          },
          {
            label: '记录编码:',
            value: 'code',
            type: 'input',
            placeholder: '请输入'
          },
          // {
          //   label: '产品名称:',
          //   value: 'productName',
          //   type: 'input',
          //   placeholder: '请输入'
          // },
          {
            label: '状态:',
            value: 'executeStatus',
            type: 'select',
            placeholder: '请选择',
            planList: [
              {
                label: '未执行',
                value: 0
              },
              {
                label: '执行中',
                value: 1
              },
              {
                label: '已执行',
                value: 2
              }
            ]
          }
        ];
      }
    },
    methods: {
      // 刷新表格
      reload(where = {}) {
        this.$refs.table.reload({
          where,
          ...this.tableQuery
        });
      },
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        // 参数
        const body = {
          ...where,
          ...order,
          pageNum: page,
          size: limit,
          // 查询生产记录
          itemType: '2',
          ...this.tableQuery
        };
        return producetaskrulerecordPage(body);
      },
      search(where) {
        this.reload(where);
      },
      goToDetail(row) {
        this.$refs.editModalRef.open('detail', row);
      },
      openPrint(row) {
        this.$refs.batchPecordPrintRef.open(row);
      }
    }
  };
</script>

<style></style>
