<template>
  <el-dialog
    title="选择委外发货单"
    custom-class="ele-dialog-form long-dialog-form"
    :visible.sync="outSourceSendDialogFlag"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
  >
    <el-card shadow="never">
      <searchTable @search="reload"></searchTable>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        height="calc(100vh - 500px)"
        class="dict-table"
        @cell-click="cellClick"
      >
        <!-- 表头工具栏 -->
        <template v-slot:action="{ row }">
          <el-radio class="radio" v-model="radio" :label="row.id"
          ><i></i
          ></el-radio>
        </template>
      </ele-pro-table>
    </el-card>

    <div class="btns" slot="footer">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import searchTable from '@/views/purchasingManage/purchaseOrder/invoice/components/outSourceSearchTable.vue';
import {getPurchaseOutSourceSendPageAPI} from "@/api/purchasingManage/outSourceSend";

export default {
  components: {
    searchTable
  },
  props: {
    searchParams: {
      type: Object,
      default: () => {
      }
    },
    outSourceSendDialogFlag: Boolean
  },

  data() {
    return {
      currentIndex: null,
      columns: [
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          width: 60,
          type: 'action',
          slot: 'action',
          label: '选择',
          columnKey: 'action',
          align: 'center'
        },
        {
          prop: 'code',
          label: '发货单编码',
          align: 'center',
          slot: 'code',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'orderNo',
          label: '订单编码',
          align: 'center',
          slot: 'orderNo',
          showOverflowTooltip: true,
          minWidth: 200
        },
        {
          prop: 'sourceTypeName',
          label: '订单类型',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 140
        },
        {
          prop: 'supplierName',
          label: '供应商名称',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'linkName',
          label: '供应商联系人',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'linkPhone',
          label: '供应商联系电话',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 130
        }
      ],

      radio: null
    };
  },

  methods: {
    init() {},
    /* 表格数据源 */
    datasource({page, limit, where}) {
      return getPurchaseOutSourceSendPageAPI({
        pageNum: page,
        size: limit,
        ...where,
        reviewStatus: 2,
        ...this.searchParams
      });
    },

    /* 刷新表格 */
    reload(where) {
      where = {
        ...where,
        ...this.searchParams
      }
      this.$refs.table.reload({pageNum: 1, where: where});
    },


    // 单击获取id
    cellClick(row) {
      this.current = row;
      this.radio = row.id;
    },
    handleClose() {
      this.$emit('update:outSourceSendDialogFlag', false)
    },

    selected() {
      if (!this.current) {
        return this.$message.warning('请至少选择一条数据');
      }
      this.$emit('changeParent', this.current, this.currentIndex);
      this.handleClose();
    }
  }
};
</script>

<style lang="scss" scoped>
.tree_col {
  border: 1px solid #eee;
  padding: 10px 0;
  box-sizing: border-box;
  height: 500px;
  overflow: auto;
}

.table_col {
  padding-left: 10px;

  ::v-deep .el-table th.el-table__cell {
    background: #f2f2f2;
  }
}

.pagination {
  text-align: right;
  padding: 10px 0;
}

.btns {
  text-align: center;
  padding: 10px 0;
}

.topsearch {
  margin-bottom: 15px;
}
</style>
