<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"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left> </template>

      <template #menu-right="{ size }"> </template>
      <template #menu="scope"> </template>
    </avue-crud>
  </basic-container>
</template>
<script>
import { getList } from '@/api/productionManagement/sameFurnaceQuery';

export default {
  components: {},
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      selectionList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        columnSort: true,
        tip: false,
        height: 'auto',
        calcHeight: 32,
        simplePage: false,
        searchShow: true,
        searchMenuSpan: 6,
        dialogWidth: '60%',
        border: true,
        selection: false,
        index: true,
        menuWidth: 240,
        dialogClickModal: false,
        excelBtn: true,
        viewBtn: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        editBtnText: '编辑',
        refreshBtn: false,
        searchShowBtn: false,
        gridBtn: false,
        searchIndex: 3,
        searchIcon: true,
        menu: false,
        searchLabelPosition: 'left',
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: 'left',
        gridBtn: false,
        searchMenuPosition: 'right',
        addBtnIcon: ' ',
        viewBtnIcon: ' ',
        delBtnIcon: ' ',
        editBtnIcon: ' ',
        align: 'center',
        column: [
          {
            label: '绑定编号',
            prop: 'mtnCode',
            search: true,
            sortable: true,
            overHidden: true,
          },
          {
            label: '车间订单号',
            prop: 'prWorkPlan.prWorkOrder.woCode',
            search: true,
            sortable: true,
            overHidden: true,
            searchLabelWidth: 120,
          },
          {
            label: '物料号',
            prop: 'prWorkPlan.prWorkOrder.pjYieldOrder.partCode',
            search: true,
            sortable: true,
            overHidden: true,
          },
          {
            label: '批次号',
            prop: 'prWorkPlan.prWorkOrder.batchNo',
            search: true,
            sortable: true,
            overHidden: true,
          },
          {
            label: '数量',
            prop: 'prWorkPlan.workQty',
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: '设备编码',
            prop: 'equipmentCard.deviceCode',
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: '挂具编号',
            prop: 'bsRackSet.rsCode',
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: '飞靶编号',
            prop: 'bsFeiBaSet.fsCode',
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: '绑定时间',
            prop: 'createTime',
            search: true,
            sortable: true,
            overHidden: true,
          },
          {
            label: '绑定人员',
            prop: 'createMan.userName',
            search: false,
            sortable: true,
            overHidden: true,
          },
        ],
      },
      data: [],
    };
  },

  methods: {
    // 重置
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    // 搜索
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    // 选中表格数据
    selectionChange(list) {
      this.selectionList = list;
    },
    //
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    // 切换 页码
    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;
        this.loading = false;
        this.page.total = this.data.length;
      });
    },
  },
};
</script>
