<template>
  <div>
    <el-dialog
      title="选择领料单"
      :visible.sync="dialogVisible"
      width="40%"
      :before-close="handleClose"
    >
      <div class="main">
        <ele-pro-table
          ref="table"
          :initLoad="false"
          :columns="columns"
          :current.sync="current"
          highlight-current-row
          :datasource="tableData"
          tool-class="ele-toolbar-form"
          cache-key="systemOrgUserTable"
          @row-click="chooseRow"
        >
          <!-- 表头工具栏 -->
          <template v-slot:code="{ row }">
            <!-- @click="details(row)" -->
            <el-link
              type="primary"
              @click="pickOrderEdit(row)"
              :underline="false"
            >
              {{ row.code }}
            </el-link>
          </template>
          <template v-slot:action="{ row }">
            <el-radio class="radio" v-model="radio" :label="row.id"
              ><i></i
            ></el-radio>
          </template>
          <template v-slot:status="{ row }">
            <span v-if="row.status == 0">未领料</span>
            <span v-else>已领料</span>
          </template>
        </ele-pro-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleMine">确 定</el-button>
      </span>
    </el-dialog>

    <pickOrderEdit ref="pickOrderEditRef" />
  </div>
</template>

<script>
  import { pickOrderPage } from '@/api/mes';
  import pickOrderEdit from './pickOrderEdit.vue';
  export default {
    components: { pickOrderEdit },
    data() {
      return {
        dialogVisible: false,
        pages: {
          pageNum: 1,
          size: 10
        },
        total: 0,
        tableData: [],
        current: {},
        radio: null,
        columns: [
          {
            columnKey: 'index',
            type: 'index',
            width: 80,
            label: '序号',
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '领料单号',
            showOverflowTooltip: true,
            slot: 'code'
          },
          {
            prop: 'executorName',
            label: '执行人名称',
            showOverflowTooltip: true
          },
          {
            prop: 'executorTime',
            label: '执行日期',
            showOverflowTooltip: true
          },
          {
            prop: 'status',
            label: '领料状态',
            showOverflowTooltip: true,
            slot: 'status'
          },
          {
            columnKey: 'action',
            slot: 'action',
            align: 'center',
            fixed: 'right',
            width: 50
          }
        ]
      };
    },
    methods: {
      pickOrderEdit(row) {
        this.$refs.pickOrderEditRef.open(row);
      },
      handleMine() {
        const current = this.current.orderInfoList;
        for (const key in current) {
          if (
            current[key].bomDetailDTOS.length == 0 &&
            current[key].instanceList.length == 0
          ) {
            this.$message.warning('当前领料单数据为空');
            return;
          }
        }
        this.$emit('success', this.current);
        this.dialogVisible = false;
      },
      async open() {
        this.dialogVisible = true;
        const res = await pickOrderPage(this.pages);
        console.log(res);
        this.tableData = res.data.list;
        this.total = res.data.count;
      },
      chooseRow(row) {
        this.current = row;
        this.radio = row.id;
      },
      handleClose(done) {}
    }
  };
</script>
