<template>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" ref="crud">
      <template #menu-left>
        <el-input
          v-model="cardNo"
          style="width: 240px; margin-right: 24px"
          @keyup.enter.native="changeCode"
          placeholder="请扫描流程单号"
        />
      </template>
      <template #menu-right>
        <el-button type="primary" @click="receiveBatch()">批量接收 </el-button>
      </template>
      <template #menu="scope">
        <el-button type="text" @click="delFn(scope.row,scope.$index)">删除</el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { loadNotReceived,workPlanReceive } from '@/api/taskCope/index';
export default {
  components: {},
  data() {
    return {
      cardNo: '', //扫描的流程卡号
      form: {},
      selectionList: [],
      query: {},
      loading: false,
      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',
        header: true,
        column: [
          {
            label: '车间订单号',
            prop: 'woCode',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '产品号',
            prop: 'partCode',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '流程卡号',
            prop: 'nextRoam',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '产品型号',
            prop: 'productType',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '批次',
            prop: 'batchNo',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '产品名称',
            prop: 'partName',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '当前工序',
            prop: 'currentWpTitle',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '上序',
            prop: 'partName',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '下序',
            prop: 'partName',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '镀种信息',
            prop: 'plate',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '生产标识',
            prop: 'prodIdent',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '订单优先级',
            prop: 'priorityTitle',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '需求部门',
            prop: 'useDept',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '生产数量',
            prop: 'makeQty',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '面积(d㎡)',
            prop: 'poArea',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '交期',
            prop: 'demandDate',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '计划员',
            prop: 'planUser',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '计划下达时间',
            prop: 'releaseDate',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '计划完工时间',
            prop: 'planEndTime',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '已入库数量',
            prop: 'inventoryQty',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '未入库数量',
            prop: 'notInQty',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '加工班组',
            prop: 'currentMakeTeam',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '上一班组',
            prop: 'partName',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '下一班组',
            prop: 'partName',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '领料状态',
            prop: 'pickingStatusTitle',
            search: false,
            sortable: false,
            width: '120',
          },
          {
            label: '运行状态',
            prop: 'runStatusTitle',
            search: false,
            sortable: false,
            width: '120',
          },
        ],
      },

      data: [],
    };
  },
  methods: {
    delFn(row, index) {
      this.$confirm('确定要删除该条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          // 从 data 数组中删除指定索引的行
          this.data.splice(index, 1);
          this.$message.success('删除成功');
        })
        .catch(() => {});
    },
    // 根据流程卡号查询订单数据
    changeCode() {
      this.loading = true;
      loadNotReceived({ cardNo: this.cardNo })
        .then(res => {
          this.cardNo = '';
          this.data.push(res.data.data);
          this.loading = false;
          console.log(res.data.data, 'resres');
        })
        .catch(err => {
          this.cardNo = '';
          this.loading = false;
        });
    },
    // 批量接收
    receiveBatch() {
      this.$confirm('确定要批量处理吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.loading = true;
        let ids = this.data.map(item => item.wpId);
        workPlanReceive({ wpIds:ids.join(',') }).then(res => {
          this.loading = false;
           this.data=[]
          this.$message.success('处理成功');
        }).catach(err => {
          this.loading = false;
        });
      });
    },
  },
  mounted() {},
};
</script>
d