<template>
    <div class="app-list-content">
        <x-crud class="liu-crud-wrap" @load="onLoad">
            <!-- 收款二维码 -->
            <template #table-column-gatheringCode="{scope}">
                <el-button type="text" @click="gotoPage(1,scope.row)">查看</el-button>
            </template>
            <!--会员申请码 -->
            <template #table-column-applyCode="{scope}">
                <el-button type="text" @click="gotoPage(2,scope.row)">查看</el-button>
            </template>
        </x-crud>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                // x-crud
                app: null
            };
        },
        mounted() {
        },
        methods: {
            // crud
            onLoad({ctx, app}) {
                this.app = app;
                let applyHost = () => {
                    return this.$service.sassShop.shopList();
                };
                ctx.service({
                    page: applyHost
                })
                    .set('table', {
                        columns: [
                            {
                                prop: 'id',
                                label: 'ID',
                                align: 'center'
                            },
                            {
                                prop: 'shopName',
                                label: '门店名称',
                                align: 'center'
                            },
                            {
                                prop: 'name',
                                label: '商家',
                                align: 'center'
                            },
                            {
                                prop: 'shopProvince',
                                label: '省',
                                align: 'center'
                            },
                            {
                                prop: 'shopCity',
                                label: '市',
                                align: 'center',
                                emptyText: '无'
                            },
                            {
                                prop: 'shopDist',
                                label: '区',
                                align: 'center',
                                emptyText: '无'
                            },
                            {
                                prop: 'gatheringCode',
                                label: '收款二维码',
                                align: 'center',
                            },
                            {
                                prop: 'applyCode',
                                label: '会员申请码',
                                align: 'center',
                            }
                        ],
                        // 操作列
                        op: {
                            visible: false, // 是否显示
                            // 同 element-ui Table-column Attributes
                            props: {
                                width: 150,
                                align: 'center',
                                fixed: 'right',
                                label: '操作'
                            },
                            // 布局，请移步 `layout`
                            layout: []
                        }
                    })
                    .set('layout', [
                        ['slot-tabs'],
                        ['flex1', 'refresh-btn'],
                        ['data-table'],
                        ['flex1', 'pagination']
                    ])
                    .done();
                app.refresh();
            },


            gotoPage(type,data) {
                console.log(data)
                let host = '';
                let url=null
                switch (type) {
                    case 1:
                        url=`/user/gathering-code?id=${data.id}`
                        break
                    case 2:
                        url=`/user/apply-code?id=${data.id}`
                        break;
                }
                window.open(host + url);
            }
        }
    };
</script>
