<template>
    <el-dialog title="外协单号选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="80%"
  >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="供应商" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外协单号" prop="assistProcessCode">
        <el-input
          v-model="queryParams.assistProcessCode"
          placeholder="请输入外协单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产工单" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入生产工单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 供应商，外协单号，生产工单， 外协数量，已缴回数量，计划时间 -->
    <el-table v-loading="loading" :data="workorderList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
        <el-table-column width="55" align="center" >
            <template v-slot="scope">
                <el-radio v-model="selectedWorkorderId" :label="scope.row.assistProcessCode" @change="handleRowChange(scope.row)">{{""}}</el-radio>
            </template>
        </el-table-column>
        <el-table-column label="供应商" prop="supplierName" />
        <el-table-column label="外协单号" align="center" prop="assistProcessCode" />
        <el-table-column label="生产工单" align="center" prop="workorderCode" :show-overflow-tooltip="true"/>
        <el-table-column label="外协数量" align="center" prop="quantity"/>
        <el-table-column label="已缴回数量" align="center" prop="quantityFeedback"/>
        <el-table-column label="计划时间" align="center" prop="scheduleEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scheduleEndDate) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>

</template>
<script>
    import { getAssistProcessList} from "@/api/mes/pro/feedback";
    export default {
        name: 'assistProcessSelect',
        components: {},
        dicts: ['mes_order_status','mes_workorder_sourcetype'],
        props:{

        },
        data() {
            return {
                showFlag: false,
                // 遮罩层
                loading: true,
                // 选中数组
                selectedWorkorderId: undefined,
                selectedRows: [],
                 // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                 // 生产工单表格数据
                workorderList: [],
                 // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                  pageNum: 1,
                  pageSize: 10,
                  supplierName: '',
                  assistProcessCode: '',
                  workorderCode: ''
                },
            }
        },
        created() {
            this.getList();
        },
        methods:{
            /** 查询生产工单列表 */
            getList() {
                this.loading = true;
                getAssistProcessList(this.queryParams).then(response => {
                    this.workorderList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            handleCurrent(row){
                if(row){
                    this.selectedRows = row;
                }
            },
            // 单选选中数据
            handleRowChange(row) {
                if(row){
                    this.selectedRows = row;
                }
            },
            //双击选中
            handleRowDbClick(row){
                if(row){
                    this.selectedRows = row;
                    this.$emit('onSelected',this.selectedRows);
                    this.showFlag = false;
                }
            },
            //确定选中
            confirmSelect(){
                if(!this.selectedWorkorderId){
                    this.$notify({
                        title:'提示',
                        type:'warning',
                        message: '请至少选择一条数据!'
                    });
                    return;
                }
                this.$emit('onSelected',this.selectedRows);
                this.showFlag = false;
            }
        }
    }
</script>
