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

        <div >
                <p>请选择客户意愿(多选)：
                    <el-select v-model="marketService" multiple placeholder="请选择">
                        <el-option
                        v-for="item in options"
                        :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: "byhRegainMarket",
        props: {
            dialogVisible: {
                type: Boolean
            },
            batchNo: {
                type: String
            },
        },
        data () {
            return {
                client: {
                    batchNo:'',
                    
                },
                marketService:'',
                options: [],
            }
        },
        created() {
            this.client = {
                batchNo: this.batchNo,
            }
        },
        methods: {

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

            submitMarket() {
                this.$$post('/market/recovery', 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)

                }).catch(error => {
                    this.$Message.error(error || '系统异常');
                });
            },
             //参数
            buildParam() {
                var return_hash = {
                };

                if (this.client.batchNo != '') {
                    return_hash['batchNo'] = this.client.batchNo
                }
                 if (this.marketService != '') {
                    return_hash['desireNos'] = this.marketService
                }
                return return_hash;
            },
            loadOperate() {
                this.$$post('/market/getDesire', {
                    parentId  : 0,
                })
                    .then(res => {
                    if (res.data.code < 1) {
                        this.$message.error(res.data.msg);
                        return
                    }

                    var arr_data = res.data.data;
                    var arr = new Array()
                    arr_data.forEach(e=>{
                        if(e.parentId==0){
                        var a = new Object();
                        a.value = e.desireNo;
                        a.label = e.name;
                        var arr2 = new Array();
                        arr_data.forEach(item=>{
                            if (item.parentId==e.id) {
                            var b = new Object;
                            b.value = item.desireNo;
                            b.label = item.name;
                            arr2.push(b);
                            }
                        });
                        a.children = arr2;
                        arr.push(a)
                        }
                    })
                    this.options  = arr;
                    })
                    .catch(err => {
                    alert("error!")
                    })
            },
        },
        mounted: function () {
            this.loadOperate();
        },
    }
</script>

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

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