<template>
<el-dialog title="查看店铺" v-model="visible" :width="600" destroy-on-close :close-on-click-modal="false" @closed="$emit('closed')">
	<el-main>
		<div style="text-align: center;">
			<img :src="qrcode" style="width: 400px; height: 400px;" />
		</div>
		<div style="text-align: center; margin-top: 20px;">
			<el-button type="primary" @click="refresh">更新</el-button>
		</div>
	</el-main>
</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			store_url: '',
			visible: false,
			isSaveing: false,
			store_id: 0,
			qrcode: '',
			refresh: 0,
			cache: {}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(id){
			this.store_id = id
			this.getQrcode()
			this.visible = true;
			return this;
		},
		refresh(){
			this.refresh = 1
			this.getQrcode()
		},
		async getQrcode(){
			if(this.store_id == 0){
				this.$message.error("请先选择店铺")
				return false
			}
			var res = await this.$API.store.payment.qrcode.get({store_id: this.store_id, refresh: this.refresh})
			if(res.code == 1){
				this.qrcode = res.data + '?timestamp=' + Date.now()
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表单注入数据
		setData(data){
			this.loading = true
			Object.assign(this.form, data)
		}
	}
}
</script>
