<template>
  <el-dialog
      model-value="BdialogVisible"
      :title="dialogTitle"
      width="30%"
      @close="handleClose"
  >
    <el-form
        ref="formRef"
        :model="form"
        label-width="100px"
    >
      <el-form-item label="门店头像" prop="businessAvatar">
        <img :src="form.businessAvatar" width="50" height="50"/>
      </el-form-item>
      <el-form-item label="门店名" prop="businessName">
        {{form.businessName}}
      </el-form-item>
      <el-form-item label="门店手机号" prop="businessPhone">
        {{form.businessPhone}}
      </el-form-item>
      <el-form-item label="店铺详细地址" prop="address">
        {{form.address}}
      </el-form-item>
      <el-form-item label="门店简介" prop="businessProfile">
        {{form.businessProfile}}
      </el-form-item>
      <el-form-item label="商家相册" prop="businessImages">
        {{form.businessImages}}
      </el-form-item>
      <el-form-item label="分类ID" prop="categoryId">
       {{form.categoryId}}
      </el-form-item>
      <el-form-item label="店主名" prop="shopkeeper">
        {{form.shopkeeper}}
      </el-form-item>
      <el-form-item label="营业执照" prop="license">
        {{form.license}}
      </el-form-item>
      <el-form-item label="身份证正面" prop="frontIdCard">
        {{form.frontIdCard}}
      </el-form-item>
      <el-form-item label="身份证反面" prop="backIdCard">
        {{form.backIdCard}}
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCard">
        {{form.bankCard}}
      </el-form-item>
      <el-form-item label="开始营业时间" prop="startBusiness">
        {{form.startBusiness}}
      </el-form-item>
      <el-form-item label="结束营业时间" prop="endBusiness">
        {{form.endBusiness}}
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        {{form.createTime}}
      </el-form-item>
    </el-form>
    <template #footer v-if="title">
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">审核成功</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import {defineEmits, defineProps, ref, watch} from "vue";
import axios from "@/util/axios";
import { ElMessage } from "element-plus";
const props=defineProps({
  bussinessId:{
    type: String,
    default:-1,
    required:true
  },
  dialogTitle:{
    type:String,
    default:'',
    required:true
  }
})
const form=ref({
  id:null,
  address: "",
  backIdCard: "",
  bankCard: "",
  businessAvatar: "",
  businessImages: "",
  businessName: "",
  businessPhone: "",
  businessProfile: "",
  categoryId: null,
  endBusiness: "",
  frontIdCard: "",
  license: "",
  state:null,
  shopkeeper: "",
  startBusiness: "",
  createTime:""
})

const formRef=ref(null);
const title=ref(false);
const initFormData=async(id)=>{
  // console.log(id)
 //  const res=await axios.get("business/getById",{id: id})

 // // form.value=res.data.data;
 //  form.value=res.data.data;
  const res=await axios.post("business/list/page",{id: id})
   console.log(res.data.data)
  form.value=res.data.data.records[0];
}
watch(
    ()=>props.bussinessId,
    ()=>{
      console.log("id="+props.dialogTitle);
      console.log(props.bussinessId)
      if (props.dialogTitle=='审核商家'){
        title.value=true;
      }
      let id=props.bussinessId;
        initFormData(id)
    }
)
// 定义父组件事件
const emits=defineEmits(['update:modelValue','initBusinessList'])
const handleClose=()=>{
  console.log("xxx")
// 调用执行
  emits('update:modelValue',false)
}

const handleConfirm = () => {
  form.value.state=1
  formRef.value.validate(async (valid) => {
    if (valid) {
      let result = await axios.post("business/update", form.value)
      console.log(result.data.data)
      let data = result.data;
      if (data.code == 0) {
        ElMessage.success("执行成功！");
        formRef.value.resetFields();
        emits("initBusinessList");
        handleClose();
      } else {
        ElMessage.error(data.description);
      }
    } else {
      console.log("fail")
      return false
    }
  })
}

</script>
<style scoped>
</style>