<template>
  <ele-modal
    :visible.sync="visible"
    title="选择工艺路线s"
    width="75vw"
    append-to-body
  >
    <el-table
      :data="tableData"
      border
      ref="tableData"
      @row-click="single"
      highlight-current-row
    >
      <el-table-column
        label="生产版本"
        align="center"
        prop="produceVersionName"
      >
      </el-table-column>
      <el-table-column
        label="未完成工单数量"
        align="center"
        prop="incompleteOrderNum"
      >
      </el-table-column>
      <el-table-column
        label="未生产数量"
        align="center"
        prop="incompleteFormingNum"
      >
      </el-table-column>

      <el-table-column label="标准产能" align="center" prop="model">
        <template slot-scope="{ row }">
          {{ row.capacityNum }}{{ row.capacityUnit }}/{{ row.capacityTime }}
        </template>
      </el-table-column>
      <el-table-column label="原料库存" align="center" prop="materialInventory">
      </el-table-column>
      <el-table-column label="改型仓" align="center" prop="model">
      </el-table-column>
      <el-table-column label="选择" align="center">
        <template slot-scope="scope">
          <el-radio
            class="radio"
            v-model="radio"
            :label="scope.row.produceVersionId"
            ><i></i
          ></el-radio>
        </template>
      </el-table-column>
    </el-table>
    <template v-slot:footer>
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="save" :loading="loading">
        确定
      </el-button>
    </template>
  </ele-modal>
</template>

<script>
  import { getProductVersion, getPlanProductVersion } from '@/api/saleOrder';
  export default {
    props: {
      productCode: String,
      produceVersionId: String
    },
    data() {
      return {
        visible: false,
        tableData: [],
        loading: false,
        radio: '',
        current: null
      };
    },
    computed: {},
    created() {},
    methods: {
      open(from) {
        this.visible = true;
        this.radio = this.produceVersionId;
        this.getPageList(from);
      },
      getPageList(from) {
        const getFn = from ? getPlanProductVersion : getProductVersion;
        getFn(this.productCode).then((res) => {
          this.tableData = res;
        });
      },
      cancel() {
        this.visible = false;
        this.radio = '';
        this.current = null;
      },
      // 单击获取id
      single(row) {
        this.current = row;
        this.radio = row.produceVersionId;
      },
      /* 保存编辑 */
      save() {
        this.visible = false;
        this.$emit('confirm', this.current);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .basic-details-title {
    margin: 10px 0;
  }
  .add-product {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 30px;
    color: #1890ff;
    margin: 10px 0;
    cursor: pointer;
  }
</style>
