<template>
<el-drawer :title="titleMap[mode]" v-model="visible" :size="800" destroy-on-close :close-on-click-modal="false" @closed="$emit('closed')">
	<el-main>
		<el-form ref="dialogForm" :model="form" :rules="rules" label-width="120px">
			<el-form-item label="门店名称" prop="title">
				<el-input v-model="form.title" placeholder="请输入门店名称" />
			</el-form-item>
			<el-form-item label="门店地址" prop="address">
				<el-input v-model="form.address" placeholder="请输入门店地址" />
			</el-form-item>
			<el-form-item label="地理坐标维度" prop="latitude">
				<el-input v-model="form.latitude" placeholder="请输入地理坐标维度" />
			</el-form-item>
			<el-form-item label="地理坐标经度" prop="longitude">
				<el-input v-model="form.longitude" placeholder="请输入地理坐标经度" />
			</el-form-item>
			<el-form-item label="人均消费金额" prop="per_capita">
				<el-input v-model="form.per_capita" placeholder="请输入联系电话" />
			</el-form-item>
			<el-form-item label="所属分仓" prop="service_id">
				<sc-select v-model="form.service_id" :apiObj="$API.auth.users.list" :props="{label: 'nickname', value: 'uid'}" style="width: 180px;" />
			</el-form-item>
			<el-form-item label="店主ID" prop="member_id">
				<el-input v-model="form.member_id" placeholder="请输入店主ID" />
			</el-form-item>
			<el-form-item label="店铺栏目" prop="category_id">
				<sc-select-tree v-model="form.category_id" :apiObj="$API.store.category.list" :props="{label: 'title', value: 'id'}" />
			</el-form-item>
			<el-form-item label="商家服务费" prop="balance_rate">
				<el-input v-model="form.balance_rate" placeholder="请输入商家服务费" />
			</el-form-item>
			<el-form-item label="配货服务费" prop="balance_service_rate">
				<el-input v-model="form.balance_service_rate" placeholder="请输入配货服务费" />
			</el-form-item>
			<el-form-item label="商家结算规则" prop="pay_rate">
				<el-input v-model="form.pay_rate" placeholder="请输入收款码现金积分比例" />
			</el-form-item>
			<el-form-item label="营业执照" prop="license">
				<sc-upload v-model="form.license" />
			</el-form-item>
			<el-form-item label="店铺LOGO" prop="logo">
				<sc-upload v-model="form.logo" />
			</el-form-item>
			<el-form-item label="店铺招牌" prop="seal" v-if="false">
				<sc-upload v-model="form.seal" />
			</el-form-item>
			<el-form-item label="介绍图片" prop="photos" v-if="false">
				<sc-upload-multiple v-model="form.photos" />
			</el-form-item>
			<el-form-item label="门店实拍" prop="store_images" v-if="false">
				<sc-upload-multiple v-model="form.store_images" />
			</el-form-item>
			<el-form-item label="店铺介绍" prop="content">
				<sc-editor v-model="form.content" placeholder="请输入店铺介绍" />
			</el-form-item>
			<el-form-item label="是否启用" prop="status">
				<el-select v-model="form.status" placeholder="请选择是否启用" clearable>
					<el-option v-for="(item, index) in [{label: '审核中', value: 0}, {label: '通过审核', value: 1}, {label: '拒绝通过', value: 2}]" :key="index" :label="item.label" :value="item.value" />
				</el-select>
			</el-form-item>
		</el-form>
	</el-main>
	<template #footer>
		<el-button type="primary" @click="onSubmit">确认提交</el-button>
	</template>
</el-drawer>
</template>

<script>
import scEditor from '@/components/scEditor'

export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑',
				audit: '审核'
			},
			form: {},
			rules: {},
			storeModule: [
				{label: '店招', value: 'storeHeader'},
				{label: '菜单', value: 'storeMenu'},
				{label: '广告图', value: 'storeBanner'},
				{label: '轮播图', value: 'storeSwiper'},
				{label: '活动详情', value: 'actionDetail'},
				{label: '商品列表', value: 'goodsList'},
				{label: '订单列表', value: 'orderList'},
				{label: '抢购列表', value: 'rushList'}
			],
			visible: false,
			isSaveing: false,
			cache: {}
		}
	},
	components: {
		scEditor
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode='add'){
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		onSubmit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res
					if(this.form.id){
						res = await this.$API.store.lists.edit.post(this.form);
					}else{
						res = await this.$API.store.lists.add.post(this.form);
					}

					this.isSaveing = false;
					if(res.code == 1){
						this.$emit('success', res.data)
						this.visible = false;
						this.$message.success("操作成功")
					}else{
						this.$message.error(res.message)
					}
				}
			})
		},
		//表单注入数据
		setData(data){
			this.loading = true
			Object.assign(this.form, data)
		}
	}
}
</script>

<style>
</style>
