<template>
    <el-dialog id="tableBody" title="分配客户给销售人员" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">

        <div >
                <p>请选择营销组：
                    <el-select v-model="desireNos" placeholder="请选择">
                        <el-option v-for="item in userGroupList" :key="item.value"
                         :label="item.label" :value="item.value"></el-option>
                    </el-select>

                </p>
        </div>

        <div slot="footer" style="margin-right:30%">
            <el-button type="info" plain @click="handleClose">取 消</el-button>
            <el-button type="primary" @click="submitMarket">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script>
    export default {
        name: "ByhContactDialog",
        props: {
            dialogVisible: {
                type: Boolean
            },
            batchNo: {
                type: String
            },
        },
        data () {
            return {
                client: {
                    batchNo:'',
                },
                desireNos: '',
                userGroupList:[],
            }
        },
        created() {
            this.client = {
                batchNo: this.batchNo,
            }

             // 获取当前用户组
            this.$$get('/group/getGroupList/')
            .then(res => {
                if (res.data.code == 1){
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        this.userGroupList = '';
                        return
                    }
                    console.log(res.data.data)
                    this.userGroupList = res.data.data;
                }else{
                this.$message({message: res.data.msg, type: 'error'});
                }
            })
            .catch(err => this.$$msg.err(err))
        },
        methods: {

            /** 关闭处理 */
            handleClose () {
                this.visible = false
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 100)
            },

            submitMarket() {
                this.$$post('/market/distribute', this.buildParam()).then(res => {
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        return
                    }
                    this.$message({message: '操作成功', type: 'success'});
                    this.handleClose();
                    this.$emit('my-event',true)
                    //window.location.reload();
                }).catch(error => {
                    this.$Message.error(error || '系统异常');
                });
            },
            //参数
            buildParam() {
                var return_hash = {
                };

                if (this.client.batchNo != '') {
                    return_hash['batchNo'] = this.client.batchNo
                }

                if (this.desireNos != '') {
                    return_hash['group'] = this.desireNos
                }
                return return_hash;
            },
            

        },
        
    }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">

#tableBody{
    text-align:center;
}
</style>