<template>
    <div :id="this.inputId+'_container'" class="go-common-drop-ctl" style="position: relative;" ref="common_drop_div">
        <go-input :label-width="inputItem.labelWidth"
            :labelAlign="labelAlign" :id="this.inputId+'_inputDiv'" :readOnly="true" :suffix="suffixIcon" v-model="selValue"
                         @inputClick="inputClick" :width="width" :item="inputItem"></go-input>
    </div>
</template>

<script>
    import formMixin from "../../../mixins/formMixins";
    import goDialog from "../../../jsCom/go-dialog";
    import {GoingUtils} from "goingutils";
    //平台api查询的前缀
    let PlatformPrefix = window.SysConfigUtils.go_eplat_adress;


    export default {
        name: "go-control-sel",
        mixins: [formMixin],
        data: function () {
            return {
                recordDb:'',
                method:'',
                selValue: '',
                suffixIcon: "ivu-icon ivu-icon-ios-arrow-down",
                inputId: GoingUtils.getUUid(12),
            };
        },
        props: {
            icon: {
                type: Boolean,
                default: true
            },
            options: {
                type: Object,
                default: () => {
                }
            }
        },
        computed: {},
        mounted() {
            this.selValue = this.value;
        },
        methods: {
            //弹出窗口
            inputClick() {
                if (this.inputItem.disabled) {
                    return void 0;
                }
                let vueObj = this;
                let defOpt = {
                    openNode:true,
                    treeUrl:PlatformPrefix + `/api/pe-portal/sectionType/querySectionAllTypeTree`,
                    title: "选择相应的服务",
                    //树点击事件
                    clickTreeNode({nodeId, gridObj}) {
                        vueObj.$emit("clickTreeNode", {nodeId, gridObj});
                        if (gridObj != null) {
                            gridObj.flushGridByUrl({
                                url: PlatformPrefix + `/api/pe-portal/dataSource/getSectionDsByType/` + nodeId
                            });
                        }
                    },
                    backFun(orgTreeObj,backData){
                        orgTreeObj.openAllItems&&orgTreeObj.openAllItems(0);
                        vueObj.$emit("initAfter", {orgTreeObj,backData});
                    },
                    //确定按钮
                    confirmBtn(goAclWin, vueObj) {
                        let {url,method} = goAclWin.getRowRecord();
                        if(url){
                            vueObj.selValue=url;
                            vueObj.method=method;
                            vueObj.$emit("input", url);
                            vueObj.$WinUtils.closeParentCurWin();
                            vueObj.$emit("selRecord", {record:goAclWin.getRowRecord()});
                        }else{
                            GoingUtils.showWinErrorMessage("请选择相应的记录后再操作！");
                        }

                    }
                };
                $.extend(defOpt, this.options);
                //激活服务选择组件
                goDialog.attachControlWin(defOpt, this);
            },
            //获取方法参数
            getMethod(){
                return this.method;
            }
        },
        components: {

        },
        watch:{
            value(newVal) {
                this.selValue = newVal;
            }
        }
    };
</script>
