<template>
    <div>
        <div class="sf-right-button-box">
            <el-button type="primary">添加门店</el-button>
            <a><el-button>批量导入/导出</el-button></a>
            <el-button type="danger" plain @click="delStores" :disabled="disabledDel">批量删除</el-button>
            <el-button class="J_show-children" size="small"><el-checkbox class="m-r-10" v-model="showChildMember" @change="setChildMemberShow"></el-checkbox><a class="a-href">显示子成员</a></el-button>
        </div>
        <el-table
            ref="table1"
            height="445"
            :data="tableData"
            @selection-change="selectMember"
            @row-click="linkToDetail">
            <el-table-column
                type="selection"
                width="42"
            ></el-table-column>
            <el-table-column
                label="门店"
                prop="storeName"
                width="140"
            ></el-table-column>
            <el-table-column
                label="代码"
                prop="storeCode"
                width="140"
            ></el-table-column>
            <el-table-column
                label="类型"
                prop="storeType"
                width="100"
            >
                <template slot-scope="scope">
                    {{typeArr[scope.row.storeType * 1 + 1]}}
                </template>
            </el-table-column>
            <el-table-column
                label="地区"
                prop="areaChainName"
                :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
                label="所属分组"
                prop="departmentName"
                :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
                label="操作"
                width="120"
            >
                <template slot-scope="scope">
                    <a class="a-href m-r-20" @click="editStore(scope.row)">编辑</a>
                    <a class="a-href" @click="delStores(scope.row, true)">删除</a>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { getRequest, postRequest, postJsonRequest } from '@/api/api';
export default {
    name: "storeView",
    props: {
        tableData: {
            type: Array,
            default() {
                return [];
            }
        }
    },
    data() {
        return {
            selectedList: [],
            showChildMember: false, // 是否显示子成员
            typeArr: ["全部类型", "自营", "联营", "代理(加盟)", "代销", "托管"],
            statusArr: ["待审核", "正常", "审核失败", "停业整顿", "回收站", "删除"]
        };
    },
    methods: {
        /**
         * 批量删除店铺
         */
        delStores(store, single = false) {
            console.log(store, single);
            let that = this;
            that.$confirm("是否删除所选店铺", "提示", {
                type: "warning"
            }).then(() => {
                let ids = "";
                if (single) {
                    ids = store.storeId;
                } else {
                    let arr = [];
                    that.selectedList.forEach(li => {
                        arr.push(li.storeId);
                    });
                    ids = arr.join(",");
                }
                let params = {
                    ids
                };
                getRequest("/haoban-manage-web/store/delByIds", params)
                .then(res => {
                    console.log(res);
                    if (res.data.errorCode == 1) {
                        let stores = ids.split(",");
                        let spliceData = that.tableData.slice(0);
                        spliceData.forEach(li => {
                            stores.forEach(id => {
                                if (id == li.storeId) {
                                    let index = that.tableData.indexOf(li);
                                    that.tableData.splice(index, 1);
                                }
                            });
                        });
                        that.$message.success({
                            duration: 1000,
                            message: "操作成功"
                        });
                    } else {
                        that.$message.error({
                            duration: 1000,
                            message: res.data.message
                        });
                    }
                }).catch(e => {
                    that.$message.error({
                        duration: 1000,
                        message: e.message
                    });
                })
            });

        },
        selectMember(selection) {
            this.selectedList = selection;
        },
        setChildMemberShow() {
            this.$emit("setChildMemberShow", this.showChildMember);
        },
        linkToDetail() {},
        editStore() {}
    },
    computed: {
        disabledDel() {
            return this.selectedList.length < 1 ;
        }
    }
};
</script>
<style lang="scss">

</style>


