<template>
	<div class="app-list-content">
		<cl-crud class="liu-crud-wrap" @load="onLoad">
			<!-- 粉丝 -->
			<template #table-column-totalFans="{scope}">
				<span>{{ scope.row.merchantAsset.totalFans }}</span>
			</template>

			<!-- 客户 -->
			<template #table-column-totalUser="{scope}">
				<span>{{ scope.row.merchantAsset.totalUser }}</span>
			</template>

			<!-- 访问量 -->
			<template #table-column-totalVisit="{scope}">
				<span>{{ scope.row.merchantAsset.totalVisit }}</span>
			</template>

			<!-- 公众号 -->
			<template #table-column-wxAppId="{scope}">
				<span v-if="scope.row.wxAppId">{{ scope.row.wxAppId }}</span>
				<el-button
					type="text"
					v-else
					@click="bindJump(`/wx-open/begin-auth?id=${scope.row.id}`)"
					>待绑定</el-button
				>
			</template>

			<!-- 小程序 -->
			<template #table-column-miniAppId="{scope}">
				<span v-if="scope.row.miniAppId">{{ scope.row.miniAppId }}</span>
				<el-button
					type="text"
					v-else
					@click="bindJump(`/wx-open/begin-auth?id=${scope.row.id}&authType=2`)"
					>待绑定</el-button
				>
			</template>

			<!-- 平台帐号激活 -->
			<template #slot-activation="{scope}">
				<el-button type="primary" size="mini" @click="bindJump(`/wx-open/add-merchant`)"
					>平台帐号激活</el-button
				>
			</template>
		</cl-crud>
	</div>
</template>

<script>
import { getFirstHost } from '@/cool/utils';
export default {
	data() {
		return {
			// cl-crud
			app: null
		};
	},
	mounted() {},
	methods: {
		bindJump(url) {
			let host = `http://api.w.${getFirstHost()}.com`;
			window.open(host + url);
		},
		// crud
		onLoad({ ctx, app }) {
			this.app = app;
			let applyHost = () => {
				return this.$service.sassShop.merchantList();
			};
			ctx.service({
				page: applyHost
			})
				.set('table', {
					columns: [
						{
							prop: 'id',
							label: 'ID',
							align: 'center'
						},
						{
							prop: 'merchantName',
							label: '名称',
							align: 'center'
						},
						{
							prop: 'totalFans',
							label: '粉丝',
							align: 'center'
						},
						{
							prop: 'totalUser',
							label: '客户',
							align: 'center'
						},
						{
							prop: 'totalIncome',
							label: '收入',
							align: 'center',
							emptyText: '无'
						},
						{
							prop: 'totalVisit',
							label: '访问量',
							align: 'center'
						},
						{
							prop: 'adminName',
							label: '店长',
							align: 'center'
						},
						{
							prop: 'openAppId',
							label: '平台',
							align: 'center',
							'min-width': '150px'
						},
						{
							prop: 'wxAppId',
							label: '公众号',
							align: 'center',
							'min-width': '150px'
						},
						{
							prop: 'miniAppId',
							label: '小程序',
							align: 'center',
							'min-width': '150px'
						},
						{
							prop: 'miniVersion',
							label: '小程序版本',
							align: 'center'
						},
						{
							prop: 'setName',
							label: '套餐',
							align: 'center'
						},
						{
							prop: 'status',
							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', 'slot-activation'],
					['data-table'],
					['flex1', 'pagination']
				])
				.done();
			app.refresh();
		}
	}
};
</script>
