<template>
    <el-drawer :title="titleMap[mode]" :append-to-body="true" v-model="visible" :size="800" destroy-on-close :close-on-click-modal="false" @closed="$emit('closed')" :with-header="false">
        <el-container class="flex-column" v-loading="loading">
            <div class="drawer-detail-main">
                <div class="drawer-detail-header">
                    <div class="drawer-detail-header-body">
                        <div class="drawer-detail-header-left">{{ titleMap[mode] }} <span class="tips">{{ formData.truename }}</span></div>
                        <div class="drawer-detail-header-left">
                            <el-button type="default" icon="el-icon-close" @click="visible=false"></el-button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="table-search">
                <fieldset>
                    <legend>
                        <el-tag type="info">按需操作</el-tag>
                    </legend>
                    <div class="op-header">
                        <div class="left-panel">
                            <el-button type="success" icon="el-icon-plus" @click="add_address()">关联新地址</el-button>
                            <!-- <el-button icon="el-icon-delete" @click="table_del()" :disabled="dataSelect.length>0?false:true">删除</el-button> -->
                        </div>
                    </div>
                </fieldset>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="list.apiObj" :params="searchKey" @selectionChange="selectionChange" row-key="id" border>
                    <el-table-column type="selection" width="50" fixed="left"></el-table-column>
                </scTable>
            </el-main>
            <el-footer>
                <el-button @click="visible=false">关 闭</el-button>
            </el-footer>
        </el-container>
    </el-drawer>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>
<script>
import formMain from './form';
export default {
    components: {
        formMain
    },
    data(){
        return {
            loading: false,
            mode:"add",
            visible: false,
            titleMap:{
                add:"关联洗衣地址",
                edit:"关联洗衣地址"
            },
            list: {
                apiObj: this.$API.storeAddress.list
            },
            searchKey:{}
        }
    },
    methods:{
        handleSuccess(data){
            console.log(data)
        },
        add_address(){
            this.$nextTick(() => {
                this.$refs.formMain.open()
            })
        },
        open(mode = 'add'){
            this.mode = mode;
            this.visible = true;
            return this
        },
        //表单注入数据
        setData(data){
            this.formData = data;
            this.searchKey.store = data.store_id;
        },
    }
}
</script>