<template>
  <el-dialog
      model-value="BdialogaddVisible"
      :title="dialogTitle"
      width="30%"
      @close="handleClose"
  >
    <el-form
        ref="formRef"
        :model="form"
        label-width="100px"
    >
      <el-form-item label="门店头像" prop="businessAvatar">
        <el-input v-model="form.businessAvatar" />
      </el-form-item>
      <el-form-item label="用户账号" prop="userAccount">
        <el-input v-model="form.userAccount" />
      </el-form-item>
      <el-form-item label="用户密码" prop="userPassword">
        <el-input v-model="form.userPassword" />
      </el-form-item>
      <el-form-item label="门店名" prop="businessName">
        <el-input v-model="form.businessName" />
      </el-form-item>
      <el-form-item label="门店手机号" prop="businessPhone">
        <el-input v-model="form.businessPhone" />
      </el-form-item>
      <el-form-item label="店铺详细地址" prop="address">
        <el-input v-model="form.address" />
      </el-form-item>
      <el-form-item label="门店简介" prop="businessProfile">
        <el-input v-model="form.businessProfile" />
      </el-form-item>
<!--      <el-form-item label="商家相册" prop="businessImages">-->
<!--        <el-input v-model="form.businessImages" />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="分类ID" prop="categoryId">-->
<!--        <el-input v-model="form.categoryId" />-->
<!--      </el-form-item>-->
      <el-form-item label="店主名" prop="shopkeeper">
        <el-input v-model="form.shopkeeper" />
      </el-form-item>
      <el-form-item label="营业执照" prop="license">
        <el-input v-model="form.license" />
      </el-form-item>
<!--      <el-form-item label="身份证正反面" prop="frontIdCard">-->
<!--      <el-input v-model="form.frontIdCard" />-->
<!--        -->
<!--    </el-form-item>-->
<!--      <el-form-item label="身份证反面" prop="backIdCard">-->
<!--      <el-input v-model="form.backIdCard" />  -->
<!--      </el-form-item>-->
      <el-form-item label="银行卡号" prop="bankCard">
        <el-input v-model="form.bankCard" />
      </el-form-item>
      <el-form-item label="开始营业时间" prop="startBusiness">
        <el-time-select
            v-model="value1"
            style="width: 100%"
            start="00:00"
            step="00:15"
            end="23:45"
            placeholder="选择开始营业时间"
        />
      </el-form-item>
      <el-form-item label="结束营业时间" prop="endBusiness">
        <el-time-select
            v-model="value2"
            style="width: 100%"
            start="00:00"
            step="00:15"
            end="23:45"
            placeholder="选择结束营业时间"
        />
      </el-form-item>

    </el-form>
    <template #footer>
<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 value1 = ref('')
const value2 = ref('')
const props=defineProps({
  dialogTitle:{
    type:String,
    default:'',
    required:true
  }
})
const form=ref({
  userAccount:"",
  userPassword:"",
  address: "",
  backIdCard: "",
  bankCard: "",
  businessAvatar: "",
  businessImages: "",
  businessName: "",
  businessPhone: "",
  businessProfile: "",
  categoryId: null,
  endBusiness: "",
  frontIdCard: "",
  license: "",
  shopkeeper: "",
  startBusiness: ""

})
// const rules=ref({
//   name: [
//     {
//       required: true,
//       message: '请输入商品大类名称！'
//     }
//   ],
//   remark: [
//     {
//       required: true,
//       message: '请输入商品大类描述！'
//     }
//   ]
// })
const formRef=ref(null);

// 定义父组件事件
const emits=defineEmits(['update:modelValue','initBusinessList'])
const handleClose=()=>{
  console.log("用户添加关闭xxx")
// 调用执行
  emits('update:modelValue',false)
}
const handleConfirm=()=>{
  formRef.value.validate(async(valid)=>{
    if(valid){
      form.value.startBusiness=value1.value;
      form.value.endBusiness=value2.value;
      let result=await axios.post("business/add",form.value)
      console.log(result.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>