<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-input
          v-model="cardNo"
          placeholder="请扫描流程卡号"
          @keyup.enter.native="queryOrder"
        ></el-input>
      </template>
      <template #menu-right> </template>
      <template #menu="{ row }"> </template>

      <template #heatTreat="scope">
        <el-tag v-if="scope.row.afterPlating" type="success">是</el-tag>
        <el-tag v-else type="warning">否</el-tag>
      </template>
    </avue-crud>

    <!-- 扣数维护填写 -->
    <editDialog
      v-if="editOpen"
      :showDialog="editOpen"
      :cardNo="cardNo"
      @closeDialog="closeDialog"
    ></editDialog>
  </basic-container>
</template>

<script>
import editDialog from './editDialog.vue';
import { getList } from '@/api/productionManagement/deductionPreserve';

export default {
  components: {
    editDialog,
  },
  data() {
    return {
      cardNo: '', //流程卡号
      editOpen: false,
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        columnSort: true,
        tip: false,
        height: 'auto',
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        editBtnText: '修改',
        labelWidth: 120,
        menuWidth: 80,
        dialogWidth: 900,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        excelBtn: true,
        showOverflowTooltip: true,
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        gridBtn: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        align: 'center',
        menu: false,
        column: [
          {
            label: '订单号',
            prop: 'woCode',
            search: true,
            sortable: true,
            span: 12,
            width: 190,
          },
          {
            label: '零件号',
            prop: 'partCode',
            search: true,
            sortable: true,
            span: 12,
            width: 210,
          },

          {
            label: '批次号',
            prop: 'batchNo',
            search: true,
            sortable: true,
            span: 12,
            display: false,
            width: 160,
          },
          {
            label: '当前工序',
            prop: 'ppsName',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '数量',
            prop: 'qty',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '实验数量',
            prop: 'testQty',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '报废数量',
            prop: 'scrapQty',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '消耗数量',
            prop: 'lossQty',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '维护人',
            prop: 'maintenanceName',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
          {
            label: '维护时间',
            prop: 'maintenanceTime',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 180,
          },
          {
            label: '备注',
            prop: 'memo',
            search: false,
            sortable: true,
            span: 12,
            display: false,
            width: 150,
          },
        ],
      },

      data: [],
    };
  },
  methods: {
    // 扫描流程卡号
    queryOrder() {
      this.editOpen = true;
    },

    closeDialog(type) {
      this.isRushOpen = false;
      this.isBatchOpen = false;
      this.editOpen = false;
      if(type){
        this.onLoad(this.page, this.query); 
      }
    },

    searchReset() {
      this.query = {};
      this.onLoad(this.page, this.query);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page, this.query);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page, this.query);
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        this.data = res.data.data.records;
        this.loading = false;
        this.page.total = res.data.data.total;
      });
    },
  },
};
</script>
