<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
      <base-table
        :table-props="tableProps"
        :page="listQuery.page"
        :limit="listQuery.limit"
        :table-data="tableData"
      >
        <method-btn
          v-if="tableBtn.length"
          slot="handleBtn"
          :width="220"
          label="操作"
          :method-list="tableBtn"
          @clickBtn="handleClick"
        />
      </base-table>
      <pagination
        :limit.sync="listQuery.limit"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getDataList"
      />
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog
        :dialogTitle="addOrEditTitle"
        :dialogVisible="addOrUpdateVisible"
        @cancel="handleCancel"
        @confirm="handleConfirm"
        :before-close="handleCancel"
      >
        <add-or-update ref="addOrUpdate" @successSubmit="successSubmit"></add-or-update>
      </base-dialog>
    <bind-machine
      v-if="bindMachineVisible"
      ref="bindMachineRef"
      @successSubmit="successSubmit"
    ></bind-machine>
    </div>
  </el-card>
</template>

<script>
import AddOrUpdate from './components/processDefine-add'
import BindMachine from './components/processDefine-machine'
import basicPage from '@/mixins/basic-page'
import basicFilter from "@/filters/basic-filter";

const tableProps = [
  {
    prop: "name",
    label: "名称",
  },
  {
    prop: "code",
    label: "编码",
  },
  {
    prop: "workingProcedureTypeName",
    label: "类型",
  },
  {
    prop: "machineName",
    label: "机台",
  },
  {
    prop: "status",
    label: "状态",
    filter: basicFilter("status"),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
  {
    type: "change",
    btnName: "改变状态",
  },
  {
    type: "Machine",
    btnName: "绑定机台",
  },
];

export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: '/basic/workingProcedure/page',
        deleteURL: '/basic/workingProcedure',
        statusUrl: '/basic/workingProcedure/status',
        exportUrl: '/basic/workingProcedure/export'
      },
      bindMachineVisible: false,
      tableProps,
      tableBtn,
      tableData: [],
      formConfig: [
        {
          type: "input",
          label: "名称",
          placeholder: "请输入名称",
          param: "name",
        },
        {
          type: "input",
          label: "编码",
          placeholder: "请输入编码",
          param: "code",
        },
        {
          type: "button",
          btnName: "查询",
          name: "search",
          color: "primary",
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: "primary",
          plain: true,
        },
        {
          type: "button",
          btnName: "导出",
          name: "export",
          color: "primary",
          plain: true,
        },
      ],
    }
  },
  components: {
    AddOrUpdate,
    BindMachine
  },
  methods: {
    //search-bar点击
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          this.listQuery.name = val.name;
          this.listQuery.code = val.code;
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        case "export":
          this.exportHandle('工序定义')
          break;
        default:
          console.log(val)
       }
    },
    otherMethods(val){
      this.bindMachine(val.data.id)
    },
    bindMachine (id) {
      this.bindMachineVisible = true
      this.$nextTick(() => {
        this.$refs.bindMachineRef.init(id)
      })
    },
  }
}
</script>
