<template>
  <el-dialog title="新增" append-to-body :modelValue="showDialog" width="80%" @close="closeDialog" @open="open">
    <el-form :inline="true" v-model="submitForm">
        <el-form-item label="银钾系数" prop="coefficient">
            <el-input placeholder="请输入银钾系数" v-model="submitForm.coefficient"></el-input>
        </el-form-item>
        <el-form-item :label="labelValue + '需求量'" prop="">
            <el-input placeholder="请输入需求量" disabled v-model="submitForm.goodsQuantity"></el-input>
        </el-form-item>
        <el-form-item label="银板需求量" prop="saveBoardVal" v-if="searchForm.goodsType == 6">
            <el-input placeholder="请输入银板需求量" v-model="submitForm.saveBoardVal" disabled></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">提 交</el-button>
        </el-form-item>
    </el-form>
    <div style="border: 1px solid #ccc; padding: 20px 0px;">
        <div>
            <el-form :inline="true" v-model="searchForm" label-width="90px">
                <el-form-item label="作业中心" prop="workCenter">
                    <el-select style="width: 182px;" v-model="searchForm.workCenter" placeholder="请选择作业中心">
                        <el-option label="作业中心一" value="1"></el-option>
                        <el-option label="作业中心二" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="物料类型" prop="goodsType">
                    <el-radio-group v-model="searchForm.goodsType" @input="changeType">
                        <el-radio :label="3">金钾</el-radio>
                        <el-radio :label="6">银钾</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item>
                    <el-checkbox v-model="searchForm.checked">允许使用半月以上的数据</el-checkbox>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSearch">查 询</el-button>
                </el-form-item> 
            </el-form>
            <el-table :data="tableData" @selection-change="handleSelectionChange">
                <el-table-column type="selection"></el-table-column>
                <el-table-column label="计划单号" prop="pjYieldOrder.poCode" align="center"></el-table-column>
                <el-table-column label="车间订单号" prop="orderWoCode" align="center"></el-table-column>
                <el-table-column label="零件号" prop="pjYieldOrder.partCode" align="center"></el-table-column>
                <el-table-column label="零件名称" prop="pjYieldOrder.partName" align="center"></el-table-column>
                <el-table-column label="物料编码" prop="plateGoodsCode" align="center"></el-table-column>
                <el-table-column label="计划下达时间" prop="createTime" align="center"></el-table-column>
                <el-table-column label="生产标识" prop="pjYieldOrder.prodIdent" align="center"></el-table-column>
                <el-table-column label="生产数量" prop="pjYieldOrder.poQty" align="center"></el-table-column>
                <el-table-column label="物料需求量(克)" prop="plateSingleQuotaTotal" align="center"></el-table-column>
            </el-table>
            <div v-show="totalNum" style="display: flex;justify-content: flex-end;align-items: center; margin: 20px 20px 0 0;">合计：{{ totalNum }}</div>
        </div> 
    </div>
  </el-dialog>
</template>

<script>
export default {
    props:{
        showDialog: {
            type: Boolean,
            default: false
        },
    },
    data(){
        return{
            submitForm:{},
            searchForm:{},
            labelValue:'金钾',
            tableData:[],
            totalNum:null,
            selectionList:[]
        }
    },
    mounted(){

    },
    methods:{
        // 切换金钾/银钾类型
        changeType(val){
            console.log('val-------------',)
            if(val.target.value == 3){
                this.labelValue = '金钾'
            }else{
                this.labelValue = '银钾'
            }
        },
        // 点击查询按钮
        onSearch(){
            this.tableData = [
                {
                    pjYieldOrder:{
                        poCode:"WO-220245431",
                        partCode:"21E8-950-1378-H1",
                        partName:'XXX',
                        prodIdent:'JII',
                        poQty:50,
                    },
                    orderWoCode:"WO-220245431",
                    plateGoodsCode:'XXXX（名称）',
                    createTime:"2023-05-17 10:50:08",
                    plateSingleQuotaTotal:'120.00'
                },
                {
                    pjYieldOrder:{
                        poCode:"WO-220245432",
                        partCode:"21E8-950-1378-H1",
                        partName:'XXX',
                        prodIdent:'JII',
                        poQty:50,
                    },
                    orderWoCode:"WO-220245432",
                    plateGoodsCode:'XXXX（名称）',
                    createTime:"2023-05-17 10:50:08",
                    plateSingleQuotaTotal:'25.32'
                },
                {
                    pjYieldOrder:{
                        poCode:"WO-220245433",
                        partCode:"21E8-950-1378-H1",
                        partName:'XXX',
                        prodIdent:'JII',
                        poQty:50,
                    },
                    orderWoCode:"WO-220245433",
                    plateGoodsCode:'XXXX（名称）',
                    createTime:"2023-05-17 10:50:08",
                    plateSingleQuotaTotal:'100.00'
                },
                {
                    pjYieldOrder:{
                        poCode:"WO-220245434",
                        partCode:"21E8-950-1378-H1",
                        partName:'XXX',
                        prodIdent:'JII',
                        poQty:50,
                    },
                    orderWoCode:"WO-220245434",
                    plateGoodsCode:'XXXX（名称）',
                    createTime:"2023-05-17 10:50:08",
                    plateSingleQuotaTotal:'200.00'
                }
            ]
        },
        // 多选
        handleSelectionChange(val) {
            this.selectionList = val;
            console.log('lisy-------------',this.selectionList)
            var strarr = [];
            for (let i in this.selectionList) {
                strarr.push(Number(this.selectionList[i]['plateSingleQuotaTotal']))
            }
            var total = eval(strarr.join('+'));
            this.totalNum = total
            this.submitForm.goodsQuantity = total
        },
        closeDialog(){
            this.$emit('closeDialog');
        }
    }
}
</script>

<style>

</style>