<template>
    <div class="view" id="labelPage" v-loading="load">
        <!-- <by-tool :propConfig="tool" v-if="userInfo && userInfo.userName == 'admin'" class="tool"
            @clickHandle="clickHandle" id="configTool" /> -->
        <!-- <module-view :propConfig="config" ref="view" @pagination="getList" @onRefresh="getList" /> -->
        <el-button type="default" @click="uploadWaterShop" size="small" style="margin-bottom: 10px;">同步店铺</el-button>
        <by-table :propConfig="tableConfig" ref="table" />
    </div>

</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { query, IShopResponse, uploadWaterShop } from '@/api/shop'
import { IResponeData, waterShop } from "@/api/omsOrder";
@Component({ components: {} })
export default class OrderConfig extends Vue {
    isHasOne = false;//是否有一条数据
    shopIds: string[] = [];
    userInfo: any = {};
    tool = {
        tools: {
            add: true,
            refresh: true
        },
        audit: {}
    }
    tableConfig: any = {
        attr: {
            size: 'mini',
            align: 'left',
            seq: true
        },
        columns: [{
            width: 150,
            title: '店铺编号',
            field: 'shopId'
        }, {
            title: '店铺名称',
            field: 'shopName'
        }, {
            title: '平台',
            field: 'shopSite',
            width: 150,
        }, {
            title: '创建于',
            field: 'createTime',
            width: 150,
        }]
    }
    time: any;
    timeNum = 0;
    data: Array<any> = []
    load = false;


    //同步聚水潭店铺
    async uploadWaterShop() {
        this.$confirm('确认同步聚水潭店铺吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(async () => {
            const res = await uploadWaterShop({ pageIndex: 1, pageSize: 20 }) as unknown as IShopResponse<any>;
            if (res.code != 200) {
                return;
            }
            this.$message.success('同步成功');
            this.getList();
        }).catch((err: any) => {
            console.info("取消")
        })
    }

    async getList() {
        this.load = true;
        const res = await waterShop() as unknown as IResponeData<any>;
        this.load = false;
        if (res.code != 200) {
            return;
        }
        (this.$refs.table as any).setValue(res.rows);
    }
    clickHandle(e: string) {
        if (e == 'onAdd') {
            if (this.isHasOne) {
                this.$message.warning('最多只能添加一条数据');
                return;
            }
            (this.$refs.addConfig as any).setShow(true)
        }
        if (e == 'onRefresh') {
            this.getList();
        }
    }


    created() {
        this.userInfo = this.$store.getters.userInfo;
    }
    mounted() {
        this.$nextTick(() => {
            this.getList()
        })
    }
}
</script>

<style lang="scss" scoped>
.view {
    width: 100%;
    height: 100%;
    padding: 16px;
    box-sizing: border-box;

    .tool {
        padding-bottom: 16px;
    }
}
</style>