<template>
  <el-button type="primary" icon="Plus" @click="addEvent">新增</el-button>
  <el-button type="primary" icon="Plus" @click="toUrl()">下载会员充值二维码</el-button>
  <br />
  <div style="margin-top: 10px;">
    允许充值自定义金额： <el-switch v-model="isCustomAmount" class="ml-2" :active-value="1" :inactive-value="0"
      @click="changeStatus" />
  </div>
  <QR ref="downloadQR"></QR>

</template>
<script setup>
import QR from './downloadQR.vue'
import API from '../api.js'
const emit = defineEmits(['add']);
const downloadQR = ref(null)
let isCustomAmount = ref(false)
async function toUrl() {
  const shopId = localStorage.getItem("shopId");
  let res = await API.getVipCode({ shopId: shopId });
  downloadQR.value.show(res)
}
onMounted(() => {
  getInfo()
})
async function getInfo() {
  const shopId = localStorage.getItem("shopId");
  let res = await API.shopInfodetail({ id: shopId });
  isCustomAmount.value = res.isCustomAmount
}
async function changeStatus() {
  let shopId = localStorage.getItem("shopId");
  let res = await API.shopInfoEidt({ id: shopId, isCustomAmount: isCustomAmount.value });
  console.log(res, 'tpasj2')
  ElMessage.success("修改成功");

}
function addEvent() {
  emit('add');
}
</script>
