<template>
  <div>
    <el-dialog
      title="选择采购订单"
      :visible.sync="dialogVisible"
      width="80%"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="main">
        <ele-pro-table
          ref="table"
          :initLoad="false"
          :columns="columns"
          :current.sync="current"
          highlight-current-row
          :datasource="datasource"
          tool-class="ele-toolbar-form"
          cache-key="systemOrgUserTable"
          @row-click="chooseRow"
        >
          <template v-slot:bizType="{ row }">
            {{ handleBizType(row.bizType) }}
          </template>
          <template v-slot:verifyStatus="{ row }">
            <span :class="status[row.verifyStatus].class">
              {{ status[row.verifyStatus].label }}
            </span>
          </template>
          <template v-slot:action="{ row }">
            <el-radio class="radio" v-model="radio" :label="row.id"
              ><i></i
            ></el-radio>
          </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>
  </div>
</template>

<script>
  import { outputSceneState } from '@/utils/dict/index';
  import outin from '@/api/warehouseManagement/outin';
  import { purchaseorderreceive } from '@/api/mes';
  export default {
    data() {
      return {
        status: [
          { label: '未审核', class: 'ele-text-info' },
          { label: '审核中', class: 'ele-text-primary' },
          { label: '审核通过', class: 'ele-text-success' },
          { label: '驳回', class: 'ele-text-danger' }
        ],
        outputSceneState,
        dataSource: {},
        dialogVisible: false,
        pages: {
          pageNum: 1,
          size: 10
        },
        total: 0,
        tableData: [],
        current: {},
        radio: null,
        columns: [
          {
            type: 'index',
            label: '序号',
            width: 50,
            align: 'center'
          },

          {
            prop: 'bizNo',
            label: '单号',
            align: 'center',
            slot: 'bizNo',
            showOverflowTooltip: true,
            width: 160
          },
          {
            prop: 'bizType',
            slot: 'bizType',
            label: '出库场景',
            align: 'center',
            showOverflowTooltip: true,
            width: 150
          },
          {
            prop: 'sourceBizNo',
            label: '来源单据',
            align: 'center',
            showOverflowTooltip: true
          },

          {
            prop: 'createUserName',
            label: '领料人',
            align: 'center',
            slot: 'createUserName',
            showOverflowTooltip: true,
            width: 200
          },
          {
            prop: 'createTime',
            label: '出库时间',
            align: 'center',
            showOverflowTooltip: true,
            width: 200
          },
          {
            prop: 'verifyStatus',
            slot: 'verifyStatus',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            width: 120
          },
          {
            prop: 'verifyName',
            slot: 'verifyName',
            label: '审核人',
            align: 'center',
            showOverflowTooltip: true,
            width: 120
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 300,
            align: 'center',
            slot: 'action',
            showOverflowTooltip: true
          }
        ]
      };
    },
    methods: {
      handleBizType(code) {
        for (const key in this.outputSceneState) {
          if (this.outputSceneState[key].code == code) {
            return this.outputSceneState[key].label;
          }
        }
      },
      async handleMine() {
        if (!this.current) {
          this.$message.error('请选择出库单');
        }
        this.$emit('success', this.current);
        this.dialogVisible = false;
      },
      datasource({ page, limit, where }) {
        const data = outin.list({
          pageNum: page,
          size: limit,
          bizStatus: 2,
          type: 2,
          ...where
        });
        this.dataSource = data;
        return data;
      },
      async open() {
        this.dialogVisible = true;
        this.$nextTick(() => {
          this.$refs.table.reload({
            pageNum: 1,
            size: 10,
            where: {}
          });
        });
      },
      chooseRow(row) {
        console.log(row);
        this.current = row;
        this.radio = row.id;
      },
      handleClose(done) {
        this.dialogVisible = false;
      }
    }
  };
</script>
