<template>
	<div class="app-list-content">
		<cl-crud class="liu-crud-wrap" @load="onLoad">
			<template #table-column-addTime="{scope}">
				<span>{{ scope.row.addTime | formatTime }}</span>
			</template>

			<template #table-column-status="{scope}">
				<span>{{ scope.row.status | constantfilter('SASS_APPLY_STATUS') }}</span>
			</template>

			<!-- 审核 -->
			<template #slot-apply="{scope}">
				<template v-if="scope.row.status == 2">
					<el-button type="text" @click="showModalFn(scope.row)">审核</el-button>
				</template>
			</template>
		</cl-crud>
		<!-- 审核弹窗 -->
		<el-dialog
			title="审核"
			:visible.sync="applyDialog"
			:close-on-click-modal="false"
			width="500px"
		>
			<div class="ad-modal-content">
				<el-form
					:model="form"
					:rules="rule"
					ref="form"
					label-width="100px"
					class="demo-form"
				>
					<el-form-item label="状态" prop="status">
						<el-radio-group v-model="form.status">
							<el-radio label="1">通过</el-radio>
							<el-radio label="2">拒绝</el-radio>
						</el-radio-group>
					</el-form-item>
					<el-form-item label="备注" prop="remark">
						<el-input type="textarea" v-model="form.remark"></el-input>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click="resetForm">取 消</el-button>
				<el-button type="primary" size="small" @click="applyFn">确认</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
export default {
	data() {
		return {
			// cl-crud
			app: null,
			// 审核
			applyDialog: false,
			form: {
				id: '',
				status: '1',
				remark: ''
			},
			rule: {}
		};
	},
	mounted() {},
	methods: {
		showModalFn(item) {
			this.form.id = item.id;
			this.applyDialog = true;
		},
		applyFn() {
			this.$service.sassShop.applyCheck(this.form).then(res => {
				this.app.refresh();
				this.$message.success('审核成功！');
				this.resetForm();
			});
		},
		resetForm() {
			this.$refs['form'].resetFields();
			this.applyDialog = false;
		},
		// crud
		onLoad({ ctx, app }) {
			this.app = app;
			let applyHost = () => {
				return this.$service.sassShop.applyList();
			};
			ctx.service({
				page: applyHost
			})
				.set('table', {
					columns: [
						{
							prop: 'id',
							label: 'ID',
							align: 'center'
						},
						{
							prop: 'name',
							label: '花店名称',
							align: 'center'
						},
						{
							prop: 'userName',
							label: '店长昵称',
							align: 'center'
						},
						{
							prop: 'mobile',
							label: '手机号',
							align: 'center'
						},
						{
							prop: 'province',
							label: '省份',
							align: 'center',
							emptyText: '无'
						},
						{
							prop: 'city',
							label: '城市',
							align: 'center',
							emptyText: '无'
						},
						{
							prop: 'oldName',
							label: '介绍人',
							align: 'center',
							emptyText: '无'
						},
						{
							prop: 'addTime',
							label: '申请时间',
							align: 'center',
							emptyText: '无'
						},
						{
							prop: 'status',
							label: '状态',
							align: 'center',
							emptyText: '无'
						}
					],
					// 操作列
					op: {
						visible: true, // 是否显示
						// 同 element-ui Table-column Attributes
						props: {
							width: 100,
							align: 'center',
							fixed: 'right',
							label: '操作'
						},
						// 布局，请移步 `layout`
						layout: ['slot-apply']
					}
				})
				.set('layout', [
					['slot-tabs'],
					['flex1', 'refresh-btn'],
					['data-table'],
					['flex1', 'pagination']
				])
				.done();
			app.refresh();
		}
	}
};
</script>
