<template>
    <el-dialog title="优先级调整" append-to-body :modelValue="openShow" width="30%" @close="closeDialog">
        <el-form ref="form" :model="form" :rules="formRules" label-width="120px">
            <el-form-item label="当前优先级:">{{  priorityName}}</el-form-item>
            <el-form-item label="设置优先级:" prop="priority" required>
                <el-select v-model="form.priority" placeholder="请选择" >
                    <el-option v-for="item in priorityList" :key="item.value" :value="item.value" :label="item.label"></el-option>     
                </el-select>
            </el-form-item>
        </el-form>
        
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="closeDialog">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script>
import {updatePreference} from '@/api/orderManagement/planYieIdOrder';  
export default {
    props: {
        showDialog: {
            type: Boolean,
            default: false
      
        },
        // priorityName:{
        //     type:String
        // },
        list:{
            type:Object,
            default:[]
        }
    },
    data() {
        return {
            openShow:false,
            form:{
                value1:''
            },
            formRules:{
                priority:[{required:true,message:'请选择优先级',trigger:'blur'}]
            },
            priorityList:[
                { label:'1级-极高紧急度',value:15001 },
                { label:'2级-高紧急度',value:15002 },
                { label:'3级-中紧急度',value:15003 },
                { label:'4级-低紧急度',value:15004 },
                { label:'5级-正常',value:15005 },
            ],
            priorityName:''
        }
    },
    mounted(){
        this.openShow = this.showDialog
        let list = this.list.map(item => item.priorityApsName)
        let uniqueList = [...new Set(list)];
        this.priorityName = uniqueList.join(',')

    },
    methods:{
        closeDialog(val){
            this.openShow = false
            this.$emit('closeDialog',val);
        },
        submit() {
            this.$refs.form.validate(valid => { 
                if(valid){
                    updatePreference({
                        ids:this.list.map(item => item.id).join(','),
                        priority:this.form.priority
                    }).then(res =>{
                        if(res.data.code == 200){
                            this.$message.success('优先级调整成功')
                            this.closeDialog(true)
                        }
                    })
                    // selectionList（
                }
            })
            // if (!this.form.value1) {
            //     this.$message.warning('请选择优先级');
            //     return;
            // }
            // this.$emit('submitPriority', {
            //     priority: this.form.value1
            // });
            // this.closeDialog();
        }
    },
    
    watch:{
        showDialog(val){
            this.openShow = val
        }    }
}
</script>
<style lang="scss" scoped></style>