<template>
  <div>
    <el-dialog
      title="选择受托收货单"
      :visible.sync="dialogVisible"
      width="60%"
      :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: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 { getSaleentrustedreceiveList } from '@/api/mes';
  export default {
    data() {
      return {
        reviewStatusEnum: [
          { value: 0, label: '未提交' },
          { value: 1, label: '审核中' },
          { value: 2, label: '已审核' },
          { value: 3, label: '审核未通过' }
        ],
        dataSource: {},
        dialogVisible: false,
        pages: {
          pageNum: 1,
          size: 10
        },
        total: 0,
        tableData: [],
        current: {},
        radio: null,
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '发货单编码',
            align: 'center',
            slot: 'code',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'orderNo',
            label: '采购订单编码',
            align: 'center',
            slot: 'orderNo',
            showOverflowTooltip: true,
            minWidth: 200
          },
          {
            prop: 'supplierName',
            label: '外协单位',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 180
          },
          {
            prop: 'reviewStatus',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120,
            formatter: (_row, _column, cellValue) => {
              return this.reviewStatusEnum[_row.reviewStatus].label;
            }
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 170
          },
          {
            columnKey: 'action',
            slot: 'action',
            align: 'center',
            fixed: 'right',
            width: 50
          }
        ]
      };
    },
    methods: {
      async handleMine() {
        if (this.current == null) {
          this.$message.warning('请先选择委外收货单！');
          return;
        }
        this.$emit('success', this.current);
        this.dialogVisible = false;
      },
      datasource({ page, limit }) {
        const data = getSaleentrustedreceiveList({
          pageNum: page,
          size: limit
        });
        this.dataSource = data;
        return data;
      },
      async open() {
        this.current = {};
        this.radio = null;
        this.dialogVisible = true;
        this.$nextTick(() => {
          this.$refs.table.reload({
            pageNum: 1,
            size: 10
          });
        });
      },
      chooseRow(row) {
        this.current = row;
        this.radio = row.id;
      },
      handleClose() {
        this.dialogVisible = false;
      }
    }
  };
</script>
